Esempio n. 1
0
        public static LogSource Create(object o)
        {
            switch (o)
            {
            case IActorContext ab:
                return(new LogSource(ab.Self.Path.ToString(), SourceType(o)));

            case IActorRef actorRef:
                return(new LogSource(actorRef.Path.ToString(), SourceType(actorRef)));

            case string str:
                return(new LogSource(str, SourceType(str)));

            case System.Type t:
                return(new LogSource(Logging.SimpleName(t), t));

            default:
                return(new LogSource(Logging.SimpleName(o), SourceType(o)));
            }
        }
Esempio n. 2
0
        /// <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 MinimalLogger))
            {
                SetUpStdoutLogger(system.Settings);
                Publish(new Debug(SimpleName(this), GetType(), $"Shutting down: {Logging.SimpleName(system.Settings.StdoutLogger)} started"));
            }

            foreach (var logger in _loggers)
            {
                if (!(logger is MinimalLogger))
                {
                    Unsubscribe(logger);
                    if (logger is IInternalActorRef internalActorRef)
                    {
                        internalActorRef.Stop();
                    }
                }
            }

            Publish(new Debug(SimpleName(this), GetType(), "All default loggers stopped"));
        }
Esempio n. 3
0
 public static string FromType(Type t, ActorSystem system)
 {
     return($"{Logging.SimpleName(t)} ({system})");
 }
Esempio n. 4
0
        /// <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($@"Logger specified in config cannot be found: ""{strLoggerType}""");
                }

                if (typeof(MinimalLogger).IsAssignableFrom(loggerType))
                {
                    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)
            {
                var stdOutLogger = system.Settings.StdoutLogger;
                Publish(new Debug(logName, GetType(), $"{Logging.SimpleName(stdOutLogger)} being removed"));
                Unsubscribe(stdOutLogger);
            }

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