コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: FormattedLogger(FormattedLog formattedLog, @Nonnull Supplier<java.io.PrintWriter> writerSupplier, @Nonnull String prefix, java.time.format.DateTimeFormatter dateTimeFormatter, java.util.function.Supplier<java.time.ZonedDateTime> zonedDateTimeSupplier)
        internal FormattedLogger(FormattedLog formattedLog, Supplier <PrintWriter> writerSupplier, string prefix, DateTimeFormatter dateTimeFormatter, System.Func <ZonedDateTime> zonedDateTimeSupplier) : base(writerSupplier, formattedLog.Lock, formattedLog.AutoFlush)
        {
            this._formattedLog      = formattedLog;
            this._prefix            = prefix;
            this._dateTimeFormatter = dateTimeFormatter;
            this._supplier          = zonedDateTimeSupplier;
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnSameLoggerForSameContext()
        internal virtual void ShouldReturnSameLoggerForSameContext()
        {
            // Given
            FormattedLogProvider logProvider = FormattedLogProvider.ToOutputStream(new MemoryStream());

            // Then
            FormattedLog log = logProvider.GetLog("test context");

            assertThat(logProvider.GetLog("test context"), sameInstance(log));
        }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnSameLoggerForSameClass()
        internal virtual void ShouldReturnSameLoggerForSameClass()
        {
            // Given
            FormattedLogProvider logProvider = FormattedLogProvider.ToOutputStream(new MemoryStream());

            // Then
            FormattedLog log = logProvider.getLog(this.GetType());

            assertThat(logProvider.GetLog(typeof(FormattedLogProviderTest)), sameInstance(log));
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldLogWithAbbreviatedClassNameAsContext()
        internal virtual void ShouldLogWithAbbreviatedClassNameAsContext()
        {
            // Given
            StringWriter         writer      = new StringWriter();
            FormattedLogProvider logProvider = NewFormattedLogProvider(writer);
            FormattedLog         log         = logProvider.GetLog(typeof(StringWriter));

            // When
            log.Info("Terminator 2");

            // Then
            assertThat(writer.ToString(), endsWith(format("INFO [j.i.StringWriter] Terminator 2%n")));
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldAllowLevelToBeChanged()
        internal virtual void ShouldAllowLevelToBeChanged()
        {
            // Given
            StringWriter writer = new StringWriter();
            FormattedLog log    = NewFormattedLog(writer, Level.Info);

            // When
            log.Info("No, it's when there's nothing wrong with you, but you hurt anyway. You get it?");
            log.Level = Level.Warn;
            log.Info("I know now why you cry. But it's something I can never do.");
            log.Level = Level.Debug;
            log.Info("There's 215 bones in the human body. That's one.");

            // Then
            assertThat(writer.ToString(), equalTo(format("%s%n%s%n", "1984-10-26 04:23:24.343+0000 INFO [test] No, it's when there's nothing wrong with you, but " + "you hurt anyway. You get it?", "1984-10-26 04:23:24.343+0000 INFO [test] There's 215 bones in the human body. That's one.")));
        }
コード例 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSetLevelForLogWithMatchingContext()
        internal virtual void ShouldSetLevelForLogWithMatchingContext()
        {
            // Given
            StringWriter         writer      = new StringWriter();
            FormattedLogProvider logProvider = NewFormattedLogProvider(writer, "java.io.StringWriter", Level.Debug);

            // When
            FormattedLog stringWriterLog     = logProvider.GetLog(typeof(StringWriter));
            FormattedLog otherClassLog       = logProvider.GetLog(typeof(PrintWriter));
            FormattedLog matchingNamedLog    = logProvider.GetLog("java.io.StringWriter");
            FormattedLog nonMatchingNamedLog = logProvider.GetLog("java.io.Foo");

            // Then
            assertThat(stringWriterLog.DebugEnabled, @is(true));
            assertThat(otherClassLog.DebugEnabled, @is(false));
            assertThat(matchingNamedLog.DebugEnabled, @is(true));
            assertThat(nonMatchingNamedLog.DebugEnabled, @is(false));
        }
コード例 #7
0
 private static FormattedLog NewFormattedLog(StringWriter writer, Level level)
 {
     return(FormattedLog.WithUTCTimeZone().withCategory("test").withLogLevel(level).withTimeSupplier(_dateTimeSupplier).toPrintWriter(Suppliers.singleton(new PrintWriter(writer))));
 }