Example #1
0
        private static string InputLogToString(IStringLog log)
        {
            var sb = new StringBuilder();

            foreach (var record in log)
            {
                sb.AppendLine(record);
            }

            return(sb.ToString());
        }
Example #2
0
        public static string ToInputLog(this IStringLog log)
        {
            var sb = new StringBuilder();

            foreach (var record in log)
            {
                sb.AppendLine(record);
            }

            return(sb.ToString());
        }
 private AnankeSettings(TimeSpan maximumRuntime, ILoggerFactory loggerFactory, TimeSpan exitTimeout,
                        double randomMaximumRuntimeRelativeDelta,
                        StdoutParser stdoutParser, IStringLog consoleLog, IExitProcessService exitProcessService,
                        ISignalService signalService)
 {
     MaximumRuntime = maximumRuntime;
     LoggerFactory  = loggerFactory;
     ExitTimeout    = exitTimeout;
     RandomMaximumRuntimeRelativeDelta = randomMaximumRuntimeRelativeDelta;
     StdoutParser       = stdoutParser;
     ConsoleLog         = consoleLog;
     ExitProcessService = exitProcessService;
     SignalService      = signalService;
 }
Example #4
0
        // TODO: use LogGenerators rather than string comparisons
        private int?DivergentPoint(IStringLog currentLog, IStringLog newLog)
        {
            int max = newLog.Count;

            if (currentLog.Count < newLog.Count)
            {
                max = currentLog.Count;
            }

            for (int i = 0; i < max; i++)
            {
                if (newLog[i] != currentLog[i])
                {
                    return(i);
                }
            }

            return(null);
        }
Example #5
0
        /// <summary>
        /// Creates a new logger provider.
        /// </summary>
        /// <param name="stringLog">The underlying string log to which all logs are written. May not be <c>null</c>.</param>
        /// <param name="formatter">The formatter used to translate log events into single-line strings. May not be <c>null</c>.</param>
        /// <param name="filter">The filter for determining which log events to log. May not be <c>null</c>.</param>
        public AnankeLoggerProvider(IStringLog stringLog, LoggerFormatter formatter, LoggerIsEnabledFilter filter)
        {
            if (stringLog == null)
            {
                throw new ArgumentNullException(nameof(stringLog));
            }
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            m_stringLog = stringLog;
            m_formatter = formatter;
            m_filter    = filter;
            m_loggers   = new ConcurrentDictionary <string, ILogger>();
        }
        /// <summary>
        /// Creates a new logger provider.
        /// </summary>
        /// <param name="stringLog">The underlying string log to which all logs are written. May not be <c>null</c>.</param>
        /// <param name="formatter">The formatter used to translate log events into single-line strings. May not be <c>null</c>.</param>
        /// <param name="filter">The filter for determining which log events to log. May not be <c>null</c>.</param>
        public DockerShimLoggerProvider(IStringLog stringLog, Func <LogEvent, string> formatter, Func <string, LogLevel, bool> filter)
        {
            if (stringLog == null)
            {
                throw new ArgumentNullException(nameof(stringLog));
            }
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            m_stringLog = stringLog;
            m_formatter = formatter;
            m_filter    = filter;
            m_loggers   = new ConcurrentDictionary <string, ILogger>();
        }
        internal AnankeSettings(IStringLog consoleLog, Func <string, LogLevel, bool> loggerIsEnabledFilter, Func <LogEvent, string> loggerFormatter)
        {
            var loggerFactory = new LoggerFactory();

            consoleLog            = consoleLog ?? new TextWriterStringLog(Console.Out);
            loggerFormatter       = loggerFormatter ?? AnankeFormatters.FormattedText;
            loggerIsEnabledFilter = loggerIsEnabledFilter ?? ((_, __) => true);
            var loggerProvider = new AnankeLoggerProvider(consoleLog, loggerFormatter, loggerIsEnabledFilter);

            loggerFactory.AddProvider(loggerProvider);
            LoggerFactory = loggerFactory;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                SignalService = new WindowsSignalService();
            }
            else
            {
                SignalService = new UnixSignalService();
            }
        }
        /// <summary>
        /// Creates a new logger provider.
        /// </summary>
        /// <param name="stringLog">The underlying string log to which all logs are written. May not be <c>null</c>.</param>
        /// <param name="formatter">The formatter used to translate log events into single-line strings. May not be <c>null</c>.</param>
        /// <param name="filter">The filter for determining which log events to log. May not be <c>null</c>.</param>
        public AnankeLoggerProvider(IStringLog stringLog, Func <LogEvent, string> formatter, Func <string, LogLevel, bool> filter)
        {
            if (stringLog == null)
            {
                throw new ArgumentNullException(nameof(stringLog));
            }
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            m_stringLog = stringLog;
            m_formatter = formatter;
            m_filter    = filter;
            m_loggers   = new ConcurrentDictionary <string, ILogger>();
            m_scopes    = new AsyncLocal <ImmutableStack <object> >();
        }
        internal static AnankeSettings InternalCreate(TimeSpan?maximumRuntime = null, ILoggerFactory loggerFactory = null,
                                                      LoggerIsEnabledFilter loggerIsEnabledFilter = null, LoggerFormatter loggerFormatter = null,
                                                      TimeSpan?exitTimeout  = null, double?randomMaximumRuntimeRelativeDelta = null, StdoutParser stdoutParser = null,
                                                      IStringLog consoleLog = null,
                                                      IExitProcessService exitProcessService = null, ISignalService signalService = null)
        {
            if (signalService == null)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    signalService = new WindowsSignalService();
                }
                else
                {
                    signalService = new UnixSignalService();
                }
            }

            consoleLog            = consoleLog ?? new TextWriterStringLog(Console.Out);
            loggerFormatter       = loggerFormatter ?? AnankeFormatters.FormattedText;
            loggerIsEnabledFilter = loggerIsEnabledFilter ?? ((_, __) => true);
            var loggerProvider = new AnankeLoggerProvider(consoleLog, loggerFormatter, loggerIsEnabledFilter);

            if (loggerFactory == null)
            {
                loggerFactory = new LoggerFactory();
                loggerFactory.AddProvider(loggerProvider);
            }

            return(new AnankeSettings(maximumRuntime ?? Timeout.InfiniteTimeSpan,
                                      loggerFactory,
                                      exitTimeout ?? TimeSpan.FromSeconds(10),
                                      randomMaximumRuntimeRelativeDelta ?? 0.10,
                                      stdoutParser ?? ((message, provider) => provider.CreateLogger("App").LogInformation(message)),
                                      consoleLog,
                                      exitProcessService ?? new ExitProcessService(),
                                      signalService));
        }
Example #10
0
		// TODO: use LogGenerators rather than string comparisons
		private int? DivergentPoint(IStringLog currentLog, IStringLog newLog)
		{
			int max = newLog.Count;
			if (currentLog.Count < newLog.Count)
			{
				max = currentLog.Count;
			}

			for (int i = 0; i < max; i++)
			{
				if (newLog[i] != currentLog[i])
				{
					return i;
				}
			}

			return null;
		}
Example #11
0
		private static string InputLogToString(IStringLog log)
		{
			var sb = new StringBuilder();
			foreach (var record in log)
			{
				sb.AppendLine(record);
			}

			return sb.ToString();
		}
 /// <summary>
 /// Creates a new escaping log wrapper around an existing log.
 /// </summary>
 /// <param name="log">The inner logger.</param>
 public EscapingStringLog(IStringLog log)
 {
     m_log = log;
 }
 /// <summary>
 /// Creates a new text writer that writes to the specified string log only when an explicit <c>WriteLine</c> is requested.
 /// </summary>
 /// <param name="stringLog">The wrapped string log.</param>
 public StringLogTextWriter(IStringLog stringLog)
 {
     m_stringLog = stringLog;
     m_writer    = new StringWriter();
 }