Ejemplo n.º 1
0
        public override string Format(RxLoggerConfiguration configuration, RxLogEntryMeta meta, TLog instance, FormatFlags format)
        {
            Guard.NotNull(configuration);
            Guard.NotNull(instance);

            // right then, this is what we do
            // we format out the meta data that we want, and then just use a simple method to get the
            // rest of the formatted text

            var sb = new StringBuilder();

            if (format == FormatFlags.IncludeMeta)
            {
                var formattedMeta = configuration.Formatting.FormatMeta(meta);

                if (_multiLine)
                {
                    sb.AppendLine(formattedMeta);
                }
                else
                {
                    sb.Append(formattedMeta + " ");
                }
            }

            BuildText(sb, configuration, instance);

            return(sb.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create an instance using the specified configuration
        /// </summary>
        /// <param name="configuration"></param>
        public RxObservableLogHost(RxLoggerConfiguration configuration)
        {
            Configuration = configuration;

            _disposables = new CompositeDisposable();

            var pump = new Subject <RxLogEntry>();

            _pumpSubject = Subject.Synchronize(pump, Configuration.Host.PublishScheduler);

            // starts the process...

            var log = new ReplaySubject <RxLogEntry>(Configuration.Host.ReplaySize);

            _syncsubject = log;

            // setup the subscription

            var prePumpSubscription = Configuration.Host.PrePumpObservable(_pumpSubject).
                                      Do(Enqueue).
                                      Select(_ => Unit.Default).
                                      Catch((Exception e) => this.OnError(e)).
                                      Retry().
                                      Subscribe();

            _disposables.Add(prePumpSubscription);

            // Create a single one
            var messageObservable = log.Publish().RefCount();

            // and now build all of the subscribers
            BuildSubscribers(messageObservable);
        }
        public void CrashingSubscriberHandledCorrectlyTest()
        {
            var hostConfiguration = new HostConfiguration(publishScheduler: Scheduler.Immediate);
            var configuration     = RxLoggerConfiguration.Create(hostConfiguration);

            RxLogEntry lastValueSub1 = null;
            RxLogEntry lastValueSub2 = null;

            configuration.AddSubscriber((c, en) => TestSubscriber(c, en, (r) => lastValueSub1 = r, raiseException: true));
            configuration.AddSubscriber((c, en) => TestSubscriber(c, en, (r) => lastValueSub2 = r));

            // one subscription we will let it raise exceptions, other won't.
            var entry1 = RxLogEntry.WithNoMeta(new object());
            var entry2 = RxLogEntry.WithNoMeta(new object());

            var host = new RxObservableLogHost(configuration);

            host.Publish(entry1);

            Assert.Null(lastValueSub1);
            Assert.Same(entry1, lastValueSub2);

            host.Publish(entry2);

            Assert.Null(lastValueSub1);
            Assert.Same(entry2, lastValueSub2);
        }
        public ObservableMixinsTests()
        {
            _testSubject = new Subject <string>();

            _mockLogHost = new Mock <IRxLogHost>();
            _mockLogHost.Setup(p => p.Configuration).Returns(RxLoggerConfiguration.Create());
            RxLog.SetDefault(new RxLog(_mockLogHost.Object));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Set the default <see cref="RxLog"/> based upon a specified configuration.
        /// </summary>
        /// <param name="configuration"></param>
        public static void SetDefault(RxLoggerConfiguration configuration)
        {
            Guard.NotNull(configuration);

            var host = configuration.CreateHost();

            RxLog.SetDefault(new RxLog(host));
        }
        /// <summary>
        /// Create the default log host using the specified <see cref="RxLoggerConfiguration"/>
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static void SetDefault(this RxLoggerConfiguration configuration)
        {
            var host = configuration.CreateHost();

            var log = new RxLog(host);

            RxLog.SetDefault(log);
        }
        public void CreateSuccessfullyTest()
        {
            var configuration = RxLoggerConfiguration.Create();

            var host = new RxObservableLogHost(configuration);

            Assert.Equal(host.Configuration, configuration);
        }
        public void CreateValidConfigurationTest()
        {
            var config = RxLoggerConfiguration.Create();

            var meta = config.CreateMeta(this.GetType(), _testMemberName, _testLineNo);

            Assert.NotNull(config.Host);
            Assert.NotNull(config.Formatting);
        }
        public void MetaCreationValidTest()
        {
            var config = RxLoggerConfiguration.Create();

            var meta = config.CreateMeta(this.GetType(), _testMemberName, _testLineNo);

            Assert.Same(meta.CallingClass, this.GetType());
            Assert.Equal(_testMemberName, meta.MemberName);
            Assert.Equal(_testLineNo, meta.LineNo);
        }
        public void CustomCreateWIthNoSubscriberTest()
        {
            var hc = HostConfiguration.Default;
            var lc = LogFormattingConfiguration.Default;

            var subs   = new List <Func <RxLoggerConfiguration, IObservable <RxLogEntry>, IObservable <Unit> > >();
            var config = new RxLoggerConfiguration(hc, lc, subs);

            Assert.Same(config.Host, hc);
            Assert.Same(config.Formatting, lc);
            Assert.Equal(0, config.Subscribers.Count);
        }
Ejemplo n.º 11
0
        public override void BuildText(StringBuilder sb, RxLoggerConfiguration configuration, Timer timer)
        {
            sb.AppendLine($"{timer.Name} Timer");

            var totalAmount = timer.Entries.Count;

            sb.AppendLine($"Total {totalAmount}");

            foreach (var instance in timer.Entries)
            {
                _blockFormatter.BuildText(sb, configuration, instance.Value);
            }
        }
        public void PublishedItemsChanneledThroughConfigTest()
        {
            var hostConfiguration = new HostConfiguration(prePumpObservable: (e) => PumpTest(e), publishScheduler: Scheduler.Immediate);

            var configuration = RxLoggerConfiguration.Create(hostConfiguration: hostConfiguration);

            var host = new RxObservableLogHost(configuration);

            var entry = RxLogEntry.WithNoMeta(new object());

            host.Publish(entry);

            Assert.Same(entry, _lastValue);
        }
        public string Formatted(RxLoggerConfiguration configuration, RxLogEntry entry, FormatFlags flags)
        {
            Guard.NotNull(configuration);
            Guard.NotNull(entry);

            var sb = new StringBuilder();

            // right then, we need to format the core and then the rest of the properties for the actual log item...
            // this is a straight wander of the properties of the item...

            if (flags == FormatFlags.IncludeMeta && entry.Meta != null)
            {
                sb.Append(_metaFormatter.Formatted(entry.Meta));
            }

            if (_onePropertyPerLine)
            {
                sb.AppendLine();
                sb.AppendLine(entry.Specifics.GetType().Name);
            }
            else
            {
                sb.Append(" ");
                sb.Append(entry.Specifics.GetType().Name);
                sb.Append(" ");
            }


            var attributes = entry.Specifics.Properties();

            foreach (var attribute in attributes)
            {
                if (_onePropertyPerLine)
                {
                    sb.Append(attribute.Key);
                    sb.Append("=");
                    sb.Append(attribute.Value);
                    sb.AppendLine();
                }
                else
                {
                    sb.Append(" ");
                    sb.Append(attribute.Key);
                    sb.Append("=");
                    sb.Append(attribute.Value);
                }
            }

            return(sb.ToString());
        }
Ejemplo n.º 14
0
        public override void BuildText(StringBuilder sb, RxLoggerConfiguration configuration, Discrete discrete)
        {
            sb.AppendLine($"{discrete.Name} {discrete.GetType()} Discrete {discrete.Unit.Name}");

            if (discrete.Count > 0)
            {
                sb.AppendLine($"Assigned = {discrete.Count} time(s)");

                sb.AppendLine($"Last Value = {discrete.LastValue} {discrete.Unit.Name}");
                sb.AppendLine($"At = {discrete.LastDateTimeOffset}");
            }
            else
            {
                sb.AppendLine("Never assigned");
            }
        }
        public void CustomCreateWithSubscriberTest()
        {
            var hc = HostConfiguration.Default;
            var lc = LogFormattingConfiguration.Default;

            Func <RxLoggerConfiguration, IObservable <RxLogEntry>, IObservable <Unit> > sub = (r, o) => Observable.Return(Unit.Default);

            var subs = new List <Func <RxLoggerConfiguration, IObservable <RxLogEntry>, IObservable <Unit> > > {
                sub
            };

            var config = new RxLoggerConfiguration(hc, lc, subs);

            Assert.Equal(1, config.Subscribers.Count);
            Assert.Same(sub, config.Subscribers[0]);
        }
        public void SubscribersCorrectlySubscribedTest()
        {
            var hostConfiguration = new HostConfiguration(prePumpObservable: (e) => PumpTest(e, false), publishScheduler: Scheduler.Immediate);

            var configuration = RxLoggerConfiguration.Create(hostConfiguration: hostConfiguration);

            RxLogEntry lastValue = default(RxLogEntry);

            configuration.AddSubscriber((c, en) => TestSubscriber(c, en, (v) => lastValue = v));

            var host = new RxObservableLogHost(configuration);

            var entry = RxLogEntry.WithNoMeta(new object());

            host.Publish(entry);

            Assert.Same(entry, lastValue);
        }
Ejemplo n.º 17
0
        public override void BuildText(StringBuilder sb, RxLoggerConfiguration configuration, TimingBlock instance)
        {
            if (string.IsNullOrEmpty(instance.Name))
            {
                sb.AppendLine($"unnamed Timer");
            }
            else
            {
                sb.AppendLine($"{instance.Name} Timer");
            }

            sb.AppendLine($"Total = {instance.Count}");

            if (instance.Count > 1)
            {
                sb.AppendLine($"Minimum = {instance.Min} ms");
                sb.AppendLine($"Maximum = {instance.Max} ms");
                sb.AppendLine($"Mean = {instance.Mean} ms");
            }

            sb.AppendLine($"Last = {instance.LastMilliseconds} ms");

            var entryCounter = 1;

            long last = -1;

            foreach (var entry in instance.Entries)
            {
                if (last < 0)
                {
                    last = entry.Milliseconds;
                }
                else
                {
                    last = entry.Milliseconds - last;
                }

                sb.AppendLine($"#{entryCounter,3} {entry.Label} =  {entry.Milliseconds} ms (+{last}) ms");

                last = entry.Milliseconds;

                ++entryCounter;
            }
        }
        private IObservable <Unit> TestSubscriber(RxLoggerConfiguration rxLoggerConfiguration, IObservable <RxLogEntry> source, Action <RxLogEntry> reportLastValue, bool raiseException = false)
        {
            return(Observable.Create <Unit>((o) =>
            {
                var sub = source.Subscribe(v =>
                {
                    if (raiseException)
                    {
                        o.OnError(new Exception());
                    }
                    else
                    {
                        reportLastValue(v);
                        o.OnNext(Unit.Default);
                    }
                });

                return sub;
            }));
        }
        public void ErrorsDuringProcessingPassedToErrorHandlerTest()
        {
            Exception lastException = null;

            var hostConfiguration = new HostConfiguration(prePumpObservable: (e) => PumpTest(e, true), publishScheduler: Scheduler.Immediate, errored:
                                                          (e) =>
            {
                lastException = e;
                return(Observable.Return(Unit.Default));
            });

            var configuration = RxLoggerConfiguration.Create(hostConfiguration: hostConfiguration);

            var host = new RxObservableLogHost(configuration);

            var entry = RxLogEntry.WithNoMeta(new object());

            host.Publish(entry);

            Assert.NotNull(lastException);
        }
        public void PublishedItemsCanBeFilteredTest()
        {
            // indicate that pump shouldn't pass through messages
            var hostConfiguration = new HostConfiguration(prePumpObservable: (e) => PumpTest(e, ignoreAll: true), publishScheduler: Scheduler.Immediate);

            var configuration = RxLoggerConfiguration.Create(hostConfiguration: hostConfiguration);


            RxLogEntry lastSubValue = default(RxLogEntry);

            configuration.AddSubscriber((c, en) => TestSubscriber(c, en, (r) => lastSubValue = r, raiseException: true));

            var host = new RxObservableLogHost(configuration);

            var entry = RxLogEntry.WithNoMeta(new object());

            host.Publish(entry);

            // verify not received anything.
            Assert.Null(lastSubValue);
        }
Ejemplo n.º 21
0
        public override void BuildText(StringBuilder sb, RxLoggerConfiguration configuration, Counter counter)
        {
            sb.AppendLine($"{counter.Name} Counter");

            var totalAmount = counter.Instances.Values.Sum();

            sb.AppendLine($"Total {totalAmount}");

            if (counter.Instances.ContainsKey(string.Empty))
            {
                var noNameMatch = counter.Instances[string.Empty];

                sb.AppendLine($"Item (unnamed) = {noNameMatch} {counter.Unit.Name}");
            }

            foreach (var instance in counter.Instances)
            {
                if (!string.IsNullOrEmpty(instance.Key))
                {
                    sb.AppendLine($"Item {instance.Key} = {instance.Value} {counter.Unit.Name}");
                }
            }
        }
Ejemplo n.º 22
0
 public override void BuildText(StringBuilder sb, RxLoggerConfiguration configuration, Classified instance)
 {
     sb.Append(instance.Message);
 }
Ejemplo n.º 23
0
 public abstract void BuildText(StringBuilder sb, RxLoggerConfiguration configuration, TLog instance);
Ejemplo n.º 24
0
 public abstract string Format(RxLoggerConfiguration configuration, RxLogEntryMeta meta, TLog instance, FormatFlags format);
Ejemplo n.º 25
0
 protected override string Format(RxLoggerConfiguration configuration, RxLogEntry entry, FormatFlags format)
 {
     return(this.Format(configuration, entry.Meta, (TLog)entry.Specifics, format));
 }