StandardOutLogger

Namespace: Akka
We found 10 examples in language CSharp for this search. You will see 33 fragments of code.




		public void StartStandardOutLogger(StandardOutLogger standardOutLogger, IStandardOutLoggerSettings settings)
		{
			_stdOutLogger = standardOutLogger;
			SetupStandardOutLogger(standardOutLogger, settings);
			Publish(new DebugLogEvent(GetType().Name, GetType(), "StandardOutLogger started"));

		}


        private void SetUpStdoutLogger(Settings config)
        {
            var logLevel = Logging.LogLevelFor(config.StdoutLogLevel);
            SubscribeLogLevelAndAbove(logLevel, Logging.StandardOutLogger);
        }


		public void AddStandardOutLogger()
		{
			InternalAddLogger(typeof(StandardOutLogger),false);
		}


        /// <summary>
        /// Sets up StandardOutLogger logger.
        /// </summary>
        /// <param name="config">The configuration.</param>
        private void SetUpStdoutLogger(Settings config)
        {
            var logLevel = Logging.LogLevelFor(config.StdoutLogLevel);
            SubscribeLogLevelAndAbove(logLevel, Logging.StandardOutLogger);
        }


        /// <summary>
        /// Determines whether a specified classifier, <paramref name="child" />, is a subclass of another classifier, <paramref name="parent" />.
        /// </summary>
        /// <param name="parent">The potential parent of the classifier that is being checked.</param>
        /// <param name="child">The classifier that is being checked.</param>
        /// <returns><c>true</c> if the <paramref name="child" /> classifier is a subclass of <paramref name="parent" />; otherwise <c>false</c>.</returns>
        protected override bool IsSubClassification(Type parent, Type child)
        {
            return parent.IsAssignableFrom(child);
        }

        /// <summary>
        /// Publishes the specified event directly to the specified subscriber.
        /// </summary>
        /// <param name="event">The event that is being published.</param>
        /// <param name="subscriber">The subscriber that receives the event.</param>
        protected override void Publish(object @event, IActorRef subscriber)
        {
            subscriber.Tell(@event);
        }

        /// <summary>
        /// Classifies the specified event using the specified classifier.
        /// </summary>
        /// <param name="event">The event that is being classified.</param>
        /// <param name="classifier">The classifier used to classify the event.</param>
        /// <returns><c>true</c> if the classification succeeds; otherwise <c>false</c>.</returns>
        protected override bool Classify(object @event, Type classifier)
        {
            return classifier.IsAssignableFrom(GetClassifier(@event));
        }

        /// <summary>
        /// Retrieves the classifier used to classify the specified event.
        /// </summary>
        /// <param name="event">The event for which to retrieve the classifier.</param>
        /// <returns>The classifier used to classify the event.</returns>
        protected override Type GetClassifier(object @event)
        {
            return @event.GetType();
        }

        /// <summary>
        /// Starts the loggers defined in the system configuration.
        /// </summary>
        /// <param name="system">The system that the loggers need to start monitoring.</param>
        /// <exception cref="ConfigurationException">
        /// This exception is thrown if the logger specified in the <paramref name="system"/> configuration could not be found or loaded.
        /// </exception>
        /// <exception cref="LoggerInitializationException">
        /// This exception is thrown if the logger doesn't respond with a <see cref="LoggerInitialized"/> message when initialized.
        /// </exception>
        internal void StartDefaultLoggers(ActorSystemImpl system)
        {
            var logName = SimpleName(this) + "(" + system.Name + ")";
            var logLevel = Logging.LogLevelFor(system.Settings.LogLevel);
            var loggerTypes = system.Settings.Loggers;
            var timeout = system.Settings.LoggerStartTimeout;
            var asyncStart = system.Settings.LoggerAsyncStart;
            var shouldRemoveStandardOutLogger = true;

            foreach (var strLoggerType in loggerTypes)
            {
                var loggerType = Type.GetType(strLoggerType);
                if (loggerType == null)
                {
                    throw new ConfigurationException([email protected]"Logger specified in config cannot be found: ""{strLoggerType}""");
                }

                if (loggerType == typeof(StandardOutLogger))
                {
                    shouldRemoveStandardOutLogger = false;
                    continue;
                }

                if (asyncStart)
                {
                    // Not awaiting for result, and not depending on current thread context
                    Task.Run(() => AddLogger(system, loggerType, logLevel, logName, timeout))
                        .ContinueWith(t =>
                        {
                            if (t.Exception != null)
                            {
                                Console.WriteLine($"Logger [{strLoggerType}] specified in config cannot be loaded: {t.Exception}");
                            }
                        });
                }
                else
                {
                    try
                    {
                        AddLogger(system, loggerType, logLevel, logName, timeout);
                    }
                    catch (Exception ex)
                    {
                        throw new ConfigurationException($"Logger [{strLoggerType}] specified in config cannot be loaded: {ex}", ex);
                    }
                }
            }

            LogLevel = logLevel;

            if (system.Settings.DebugUnhandledMessage)
            {
                var forwarder = system.SystemActorOf(Props.Create(typeof(UnhandledMessageForwarder)), "UnhandledMessageForwarder");
                Subscribe(forwarder, typeof(UnhandledMessage));
            }

            if (shouldRemoveStandardOutLogger)
            {
                Publish(new Debug(logName, GetType(), "StandardOutLogger being removed"));
                Unsubscribe(Logging.StandardOutLogger);
            }

            Publish(new Debug(logName, GetType(), "Default Loggers started"));
        }

        /// <summary>
        /// Stops the loggers defined in the system configuration.
        /// </summary>
        /// <param name="system">The system that the loggers need to stop monitoring.</param>
        internal void StopDefaultLoggers(ActorSystem system)
        {
            var level = LogLevel; // volatile access before reading loggers
            if (!_loggers.Any(c => c is StandardOutLogger))
            {
                SetUpStdoutLogger(system.Settings);
                Publish(new Debug(SimpleName(this), GetType(), "Shutting down: StandardOutLogger started"));
            }

            foreach (var logger in _loggers)
            {
                if (!(logger is StandardOutLogger))
                {
                    Unsubscribe(logger);
                    var internalActorRef = logger as IInternalActorRef;
                    if (internalActorRef != null)
                    {
                        internalActorRef.Stop();
                    }
                }
            }

            Publish(new Debug(SimpleName(this), GetType(), "All default loggers stopped"));
        }


        /// <summary>
        /// Handles incoming log events by printing them to the console.
        /// </summary>
        /// <param name="message">The message to print</param>
        /// <param name="sender">The actor that sent the message.</param>
        /// <exception cref="ArgumentNullException">
        /// This exception is thrown if the given <paramref name="message"/> is undefined.
        /// </exception>
        protected override void TellInternal(object message, IActorRef sender)
        {
            if(message == null)
                throw new ArgumentNullException(nameof(message), "The message to log must not be null.");

            var logEvent = message as LogEvent;
            if (logEvent != null)
            {
                PrintLogEvent(logEvent);
            }
            else
            {
                Console.WriteLine(message);
            }
        }

        /// <summary>
        /// Prints a specified event to the console.
        /// </summary>
        /// <param name="logEvent">The event to print</param>
        public static void PrintLogEvent(LogEvent logEvent)
        {
            ConsoleColor? color = null;
            
            if(UseColors)
            {
                var logLevel = logEvent.LogLevel();
                switch(logLevel)
                {
                    case LogLevel.DebugLevel:
                        color = DebugColor;
                        break;
                    case LogLevel.InfoLevel:
                        color = InfoColor;
                        break;
                    case LogLevel.WarningLevel:
                        color = WarningColor;
                        break;
                    case LogLevel.ErrorLevel:
                        color = ErrorColor;
                        break;
                }
            }

            StandardOutWriter.WriteLine(logEvent.ToString(), color);
        }


        /// <summary>
        /// Determines whether a specified classifier, <paramref name="child" />, is a subclass of another classifier, <paramref name="parent" />.
        /// </summary>
        /// <param name="parent">The potential parent of the classifier that is being checked.</param>
        /// <param name="child">The classifier that is being checked.</param>
        /// <returns><c>true</c> if the <paramref name="child" /> classifier is a subclass of <paramref name="parent" />; otherwise <c>false</c>.</returns>
        protected override bool IsSubClassification(Type parent, Type child)
        {
            return parent.IsAssignableFrom(child);
        }

        /// <summary>
        /// Publishes the specified event directly to the specified subscriber.
        /// </summary>
        /// <param name="event">The event that is being published.</param>
        /// <param name="subscriber">The subscriber that receives the event.</param>
        protected override void Publish(object @event, IActorRef subscriber)
        {
            subscriber.Tell(@event);
        }

        /// <summary>
        /// Classifies the specified event using the specified classifier.
        /// </summary>
        /// <param name="event">The event that is being classified.</param>
        /// <param name="classifier">The classifier used to classify the event.</param>
        /// <returns><c>true</c> if the classification succeeds; otherwise <c>false</c>.</returns>
        protected override bool Classify(object @event, Type classifier)
        {
            return classifier.IsAssignableFrom(GetClassifier(@event));
        }

        /// <summary>
        /// Retrieves the classifier used to classify the specified event.
        /// </summary>
        /// <param name="event">The event for which to retrieve the classifier.</param>
        /// <returns>The classifier used to classify the event.</returns>
        protected override Type GetClassifier(object @event)
        {
            return @event.GetType();
        }

        /// <summary>
        /// Starts the loggers defined in the system configuration.
        /// </summary>
        /// <param name="system">The system that the loggers need to start monitoring.</param>
        /// <exception cref="ConfigurationException">
        /// This exception is thrown if the logger specified in the <paramref name="system"/> configuration could not be found or loaded.
        /// </exception>
        /// <exception cref="LoggerInitializationException">
        /// This exception is thrown if the logger doesn't respond with a <see cref="LoggerInitialized"/> message when initialized.
        /// </exception>
        internal void StartDefaultLoggers(ActorSystemImpl system)
        {
            var logName = SimpleName(this) + "(" + system.Name + ")";
            var logLevel = Logging.LogLevelFor(system.Settings.LogLevel);
            var loggerTypes = system.Settings.Loggers;
            var timeout = system.Settings.LoggerStartTimeout;
            var shouldRemoveStandardOutLogger = true;

            foreach (var strLoggerType in loggerTypes)
            {
                var loggerType = Type.GetType(strLoggerType);
                if (loggerType == null)
                {
                    throw new ConfigurationException([email protected]"Logger specified in config cannot be found: ""{strLoggerType}""");
                }

                if (loggerType == typeof(StandardOutLogger))
                {
                    shouldRemoveStandardOutLogger = false;
                    continue;
                }
                
                try
                {
                    AddLogger(system, loggerType, logLevel, logName, timeout);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException($"Logger [{strLoggerType}] specified in config cannot be loaded: {e}", e);
                }
            }

            LogLevel = logLevel;

            if (system.Settings.DebugUnhandledMessage)
            {
                var forwarder = system.SystemActorOf(Props.Create(typeof(UnhandledMessageForwarder)), "UnhandledMessageForwarder");
                Subscribe(forwarder, typeof(UnhandledMessage));
            }

            if (shouldRemoveStandardOutLogger)
            {
                Publish(new Debug(logName, GetType(), "StandardOutLogger being removed"));
                Unsubscribe(Logging.StandardOutLogger);
            }

            Publish(new Debug(logName, GetType(), "Default Loggers started"));
        }

        /// <summary>
        /// Stops the loggers defined in the system configuration.
        /// </summary>
        /// <param name="system">The system that the loggers need to stop monitoring.</param>
        internal void StopDefaultLoggers(ActorSystem system)
        {
            var level = LogLevel; // volatile access before reading loggers
            if (!_loggers.Any(c => c is StandardOutLogger))
            {
                SetUpStdoutLogger(system.Settings);
                Publish(new Debug(SimpleName(this), GetType(), "Shutting down: StandardOutLogger started"));
            }

            foreach (var logger in _loggers)
            {
                if (!(logger is StandardOutLogger))
                {
                    Unsubscribe(logger);
                    var internalActorRef = logger as IInternalActorRef;
                    if (internalActorRef != null)
                    {
                        internalActorRef.Stop();
                    }
                }
            }

            Publish(new Debug(SimpleName(this), GetType(), "All default loggers stopped"));
        }


        public override IMessageQueue Create(IActorRef owner, ActorSystem system)
        {
            if(owner != null && system != null) return new LoggerMailbox(owner, system);
            throw new ArgumentNullException(nameof(owner), "no mailbox owner or system given");
        }

        void IMessageQueue.Enqueue(IActorRef receiver, Envelope envelope)
        {
            MessageQueue.Enqueue(receiver, envelope);
        }

        bool IMessageQueue.TryDequeue(out Envelope envelope)
        {
            return MessageQueue.TryDequeue(out envelope);
        }

        void IMessageQueue.CleanUp(IActorRef owner, IMessageQueue deadletters)
        {
            if (HasMessages)
            {
                Envelope envelope;

                // Drain all remaining messages to the StandardOutLogger.
                // CleanUp is called after switching out the mailbox, which is why
                // this kind of look works without a limit.
                while (TryDequeue(out envelope))
                {
                    // Logging.StandardOutLogger is a MinimalActorRef, i.e. not a "real" actor
                    Logging.StandardOutLogger.Tell(envelope.Message, envelope.Sender);
                }
            }
            MessageQueue.CleanUp(owner, deadletters);
        }


        /// <summary>
        /// Determines whether [is sub classification] [the specified parent].
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="child">The child.</param>
        /// <returns><c>true</c> if [is sub classification] [the specified parent]; otherwise, <c>false</c>.</returns>
        protected override bool IsSubClassification(Type parent, Type child)
        {
            return parent.IsAssignableFrom(child);
        }

        /// <summary>
        /// Publishes the specified event.
        /// </summary>
        /// <param name="event">The event.</param>
        /// <param name="subscriber">The subscriber.</param>
        protected override void Publish(object @event, IActorRef subscriber)
        {
            subscriber.Tell(@event);
        }

        /// <summary>
        /// Classifies the specified event.
        /// </summary>
        /// <param name="event">The event.</param>
        /// <param name="classifier">The classifier.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        protected override bool Classify(object @event, Type classifier)
        {
            return classifier.IsAssignableFrom(GetClassifier(@event));
        }

        /// <summary>
        /// Gets the classifier for the LogEvent.
        /// </summary>
        /// <param name="event">The event.</param>
        /// <returns>Type.</returns>
        protected override Type GetClassifier(object @event)
        {
            return @event.GetType();
        }

        /// <summary>
        /// Starts the default loggers.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <exception cref="System.Exception">Can not use logger of type: + loggerType</exception>
        internal void StartDefaultLoggers(ActorSystemImpl system)
        {
            var logName = SimpleName(this) + "(" + system.Name + ")";
            var logLevel = Logging.LogLevelFor(system.Settings.LogLevel);
            var loggerTypes = system.Settings.Loggers;
            var timeout = system.Settings.LoggerStartTimeout;
            var shouldRemoveStandardOutLogger = true;

            foreach (var strLoggerType in loggerTypes)
            {
                var loggerType = Type.GetType(strLoggerType);
                if (loggerType == null)
                {
                    throw new ConfigurationException("Logger specified in config cannot be found: \"" + strLoggerType + "\"");
                }

                if (loggerType == typeof(StandardOutLogger))
                {
                    shouldRemoveStandardOutLogger = false;
                    continue;
                }
                
                try
                {
                    AddLogger(system, loggerType, logLevel, logName, timeout);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException(string.Format("Logger [{0}] specified in config cannot be loaded: {1}", strLoggerType, e),e);
                }
            }

            LogLevel = logLevel;

            if (system.Settings.DebugUnhandledMessage)
            {
                var forwarder = system.SystemActorOf(Props.Create(typeof(UnhandledMessageForwarder)), "UnhandledMessageForwarder");
                Subscribe(forwarder, typeof(UnhandledMessage));
            }

            if (shouldRemoveStandardOutLogger)
            {
                Publish(new Debug(logName, GetType(), "StandardOutLogger being removed"));
                Unsubscribe(Logging.StandardOutLogger);
            }

            Publish(new Debug(logName, GetType(), "Default Loggers started"));
        }

        internal void StopDefaultLoggers(ActorSystem system)
        {
            //TODO: Implement stopping loggers
        }


        public IReactiveServicesBuilder AddReactiveService<T, TI>()
            where TI : T
            where T : Service
        {
            ServiceDelegates.Add(x => x.AddTransient<T, TI>());
            TypeMapping.Add((typeof(T), typeof(TI)));
            return this;
        }

        public IReactiveServicesBuilder AddActorSystemDelegate(Action<ActorSystem> actorSystemDelegate)
        {
            ActorSystemDelegates.Add(actorSystemDelegate);
            return this;
        }

        public IReactiveServicesBuilder WithTopicSerializer<T>(Func<ISerializer> serializerFactory = null)
        where T : ISerializer, new()
        {
            if (serializerFactory != null)
                SerializerFactory = serializerFactory;
            return this;
        }

        public IReactiveServicesBuilder WithMessagePropertyExtractor<T>(Func<IMessagePropertyExtractor> extractorFactory = null)
        where T : IMessagePropertyExtractor, new()
        {
            if (extractorFactory != null)
                ExtractorFactory = extractorFactory;
            return this;
        }

        internal IReactiveServices Build(IServiceCollection services)
        {
            ServiceDelegates.Add(x => x.AddTransient<ISerializer>(y => SerializerFactory.Invoke()));
            ServiceDelegates.Add(x => x.AddTransient<IMessagePropertyExtractor>(y => ExtractorFactory.Invoke()));
            foreach (var serviceDelegate in ServiceDelegates)
                serviceDelegate.Invoke(services);
            return new ReactiveServices(TypeMapping);
        }

Akka.Event.StandardOutLogger : IActorRef, ICanTell, IEquatable

Constructors :

public StandardOutLogger()

Methods :

public static ConsoleColor get_DebugColor()
public static Void set_DebugColor(ConsoleColor value = )
public static ConsoleColor get_InfoColor()
public static Void set_InfoColor(ConsoleColor value = )
public static ConsoleColor get_WarningColor()
public static Void set_WarningColor(ConsoleColor value = )
public static ConsoleColor get_ErrorColor()
public static Void set_ErrorColor(ConsoleColor value = )
public static Boolean get_UseColors()
public static Void set_UseColors(Boolean value = )
public IActorRefProvider get_Provider()
public ActorPath get_Path()
public IInternalActorRef get_Parent()
public IActorRef GetChild(IReadOnlyList<String> name = )
public Void Resume(Exception causedByFailure = null)
public Void Start()
public Void Stop()
public Void Restart(Exception cause = )
public Void Suspend()
public Void SendSystemMessage(ISystemMessage message = )
public Boolean get_IsLocal()
public Boolean get_IsTerminated()
public Void SendSystemMessage(ISystemMessage message = , IActorRef sender = )
public Void Tell(Object message = , IActorRef sender = )
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()
public Int32 CompareTo(Object obj = )
public Boolean Equals(IActorRef other = )
public Int32 CompareTo(IActorRef other = )
public ISurrogate ToSurrogate(ActorSystem system = )
public Type GetType()

Other methods