예제 #1
0
        /// <summary>
        ///     Starts the default loggers.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <exception cref="System.Exception">Can not use logger of type: + loggerType</exception>
        public async void StartDefaultLoggers(ActorSystem system)
        {
            //TODO: find out why we have logName and in AddLogger, "name"
            string         logName     = SimpleName(this) + "(" + system.Name + ")";
            LogLevel       logLevel    = Logging.LogLevelFor(system.Settings.LogLevel);
            IList <string> loggerTypes = system.Settings.Loggers;

            foreach (string loggerType in loggerTypes)
            {
                Type actorClass = Type.GetType(loggerType);
                if (actorClass == null)
                {
                    //TODO: create real exceptions and refine error messages
                    throw new Exception("Can not use logger of type:" + loggerType);
                }
                TimeSpan timeout = system.Settings.LoggerStartTimeout;
                Task     task    = AddLogger(system, actorClass, logLevel, logName);
                if (await Task.WhenAny(task, Task.Delay(timeout)) == task)
                {
                }
                else
                {
                    Publish(new Warning(logName, GetType(),
                                        "Logger " + logName + " did not respond within " + timeout + " to InitializeLogger(bus)"));
                }
            }
            Publish(new Debug(logName, GetType(), "Default Loggers started"));
            SetLogLevel(logLevel);
        }
예제 #2
0
        /// <summary>
        ///     Sets up stdout logger.
        /// </summary>
        /// <param name="config">The configuration.</param>
        private void SetUpStdoutLogger(Settings config)
        {
            LogLevel logLevel = Logging.LogLevelFor(config.StdoutLogLevel);

            foreach (LogLevel level in allLogLevels.Where(l => l >= logLevel))
            {
                Subscribe(Logging.StandardOutLogger, Logging.ClassFor(level));
            }
        }
예제 #3
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 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($"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"));
        }
예제 #4
0
        /// <summary>
        ///     Starts the default loggers.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <exception cref="System.Exception">Can not use logger of type: + loggerType</exception>
        public async void StartDefaultLoggers(ActorSystemImpl system)
        {
            //TODO: find out why we have logName and in AddLogger, "name"
            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)
                {
                    //TODO: create real exceptions and refine error messages
                    throw new Exception("Logger specified in config cannot be found: \"" + strLoggerType + "\"");
                }
                if (loggerType == typeof(StandardOutLogger))
                {
                    shouldRemoveStandardOutLogger = false;
                    continue;
                }
                var addLoggerTask = AddLogger(system, loggerType, logLevel, logName);

                if (!addLoggerTask.Wait(timeout))
                {
                    Publish(new Warning(logName, GetType(),
                                        "Logger " + logName + " did not respond within " + timeout + " to InitializeLogger(bus)"));
                }
                else
                {
                    var actorRef = addLoggerTask.Result;
                    _loggers.Add(actorRef);
                    SubscribeLogLevelAndAbove(logLevel, actorRef);
                    Publish(new Debug(logName, GetType(), "Logger " + actorRef.Path.Name + " started"));
                }
            }
            _logLevel = logLevel;
            if (shouldRemoveStandardOutLogger)
            {
                Publish(new Debug(logName, GetType(), "StandardOutLogger being removed"));
                Unsubscribe(Logging.StandardOutLogger);
            }
            Publish(new Debug(logName, GetType(), "Default Loggers started"));
        }
예제 #5
0
        private void SetUpStdoutLogger(Settings config)
        {
            var logLevel = Logging.LogLevelFor(config.StdoutLogLevel);

            SubscribeLogLevelAndAbove(logLevel, Logging.StandardOutLogger);
        }
예제 #6
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 (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"));
        }