Tabnine Logo
TestLoggerFactory
Code IndexAdd Tabnine to your IDE (free)

How to use
TestLoggerFactory
in
slf4jtest

Best Java code snippets using slf4jtest.TestLoggerFactory (Showing top 20 results out of 315)

origin: com.portingle/slf4jtesting

public TestLoggerFactory buildLogging() {
  return new TestLoggerFactory(this);
}
origin: portingle/slf4jtesting

/**
 * get or create the logger
 */
public TestLogger getLogger(Class<?> name) {
  return getLogger(name.getName());
}
origin: portingle/slf4jtesting

@Override
public boolean assertMatches(Predicate<LogMessage> predicate) throws Error {
  boolean matched = matches(predicate);
  if (!matched) {
    throw new AssertionError("did not match " + predicate.toString());
  }
  return true;
}
origin: portingle/slf4jtesting

public void testErrorIsEnabledByDefault() {
  Settings settings = Settings.instance();
  TestLoggerFactory f = new TestLoggerFactory(settings);
  TestLogger log = f.getLogger("john");
  assert (log.isErrorEnabled());
}
origin: portingle/slf4jtesting

@Test
public void testMultiLineMatching() {
  // enable info logging because only error is enabled by default
  TestLoggerFactory loggerFactory = Settings.instance().enable(LogLevel.InfoLevel).buildLogging();
  TestLogger logger = loggerFactory.getLogger(this.getClass());
  // do some multiline logging
  logger.info("Line1" + System.lineSeparator() + "Line2");
  // this one does match multiline logging
  assert (loggerFactory.matches("Line1.*"));
  // using DOTALL we can match multiline
  Pattern regex = Pattern.compile("Line1.*", Pattern.DOTALL);
  Pattern regexNoMatch = Pattern.compile("NOMATCH");
  assert (loggerFactory.matches(regex));
  assert (!loggerFactory.matches(regexNoMatch));
  assert (loggerFactory.matches(LogLevel.InfoLevel, regex));
  assert (!loggerFactory.matches(LogLevel.ErrorLevel, regex));
  assert (logger.matches(regex));
  assert (!logger.matches(regexNoMatch));
  assert (logger.matches(LogLevel.InfoLevel, regex));
  assert (!logger.matches(LogLevel.ErrorLevel, regex));
}
origin: com.portingle/slf4jtesting

/**
 * get or create the logger
 */
@Override
public TestLogger getLogger(String name) {
  TestLogger cached = loggers.get(name);
  if (cached != null)
    return cached;
  TestLogger newLogger = createMock(settings, name);
  TestLogger oldLogger = loggers.putIfAbsent(name, newLogger);
  if (oldLogger != null) return oldLogger;
  return newLogger;
}
origin: portingle/slf4jtesting

  @Test
  public void testBasicDemo() throws Exception {
    TestLoggerFactory loggerFactory = new TestLoggerFactory();

    Example sut = new Example(loggerFactory);
    sut.doLogging();

    TestLogger logger = loggerFactory.getLogger(Example.class);
    assertTrue(logger.matches(".*Hello.*"));
  }
}
origin: portingle/slf4jtesting

/**
 * get or create the logger
 */
@Override
public TestLogger getLogger(String name) {
  TestLogger cached = loggers.get(name);
  if (cached != null)
    return cached;
  TestLogger newLogger = createMock(settings, name);
  TestLogger oldLogger = loggers.putIfAbsent(name, newLogger);
  if (oldLogger != null) return oldLogger;
  return newLogger;
}
origin: com.portingle/slf4jtesting

/**
 * get or create the logger
 */
public TestLogger getLogger(Class<?> name) {
  return getLogger(name.getName());
}
origin: portingle/slf4jtesting

public void testLoggingDefaults() {
  StringPrintStream console = StringPrintStream.newStream();
  PrintStream old = System.err;
  System.setErr(console);
  try {
    TestLoggerFactory f = new TestLoggerFactory();
    TestLogger log = f.getLogger("john");
    log.error("anError");
    log.info("someInfo");
    assert (console.contains("anError"));
    assert (!console.contains("someInfo"));
    assert (log.contains("anError"));
    assert (!log.contains("someInfo"));
    assert (console.matches(".*anError.*"));
    assert (!console.matches(".*someInfo.*"));
    assert (log.matches(".*anError.*"));
    assert (!log.matches(".*someInfo.*"));
  } finally {
    System.setErr(old);
  }
}
origin: com.portingle/slf4jtesting

@Override
public boolean assertMatches(Predicate<LogMessage> predicate) throws Error {
  boolean matched = matches(predicate);
  if (!matched) {
    throw new AssertionError("did not match " + predicate.toString());
  }
  return true;
}
origin: portingle/slf4jtesting

public TestLoggerFactory buildLogging() {
  return new TestLoggerFactory(this);
}
origin: portingle/slf4jtesting

  public void testDelegateToAMockingLibrary() {
    Logger mockLogger = Mockito.mock(Logger.class);
    TestLoggerFactory f = Settings.instance()
        .printingEnabled(false)
        .delegate("john", mockLogger)
        .buildLogging();

    TestLogger log = f.getLogger("john");

    log.error("anError");

    Mockito.verify(mockLogger).error("anError");
  }
}
origin: portingle/slf4jtesting

  @Test
  public void testDemoAssemblyInjection() {

    // enable info logging because only error is enabled by default
    TestLoggerFactory loggingImpl = Settings.instance().
        enable(LogLevel.InfoLevel).buildLogging();

    // create the Assembly component along with its internal internalDetail instance
    Example assembly = new Example(loggingImpl);
    assembly.doSomeInfoLogging();

    // check the Info logging
    assert (loggingImpl.matches("Hello from Assembly"));
    assert (loggingImpl.matches("Hello from InternalSubcomponent"));
  }
}
origin: portingle/slf4jtesting

@Test
public void testLogMessageMatching() {
  // enable info logging because only error is enabled by default
  TestLoggerFactory loggerFactory = Settings.instance().enable(LogLevel.InfoLevel)
      .buildLogging();
  TestLogger logger = loggerFactory.getLogger(this.getClass());
  logger.info("Line1" + System.lineSeparator() + "Line2");
  Pattern pattern = Pattern.compile("Line1.*", Pattern.DOTALL);
  boolean found = false;
  for (LogMessage l : logger.lines()) {
    if (pattern.matcher(l.text).matches())
      found = true;
  }
  assert (found);
}
origin: portingle/slf4jtesting

public void testWarnIsDisabledByDefault() {
  TestLoggerFactory f = Settings.instance().buildLogging();
  TestLogger log = f.getLogger("john");
  assert (!log.isWarnEnabled());
}
origin: portingle/slf4jtesting

/**
 * In the previous examples we've seen logging captured using either the TestLogger or by replacing the system wide
 * logging using System.errOut/setErr. Sometimes however neither of these approaches is what we want and injecting
 * a mock logger is more useful.
 * <p>
 * This example uses mock to perform an "ordered" verification.
 */
@Test
public void demoDelegatingToMockito() throws Exception {
  // we'll hook the mock up to the logging framework
  Logger mockLogger = Mockito.mock(Logger.class);
  // setup the logging impl so that logging to the logger "MyLogger" is directed at the mock
  TestLoggerFactory loggerFactory = Settings.instance()
      .delegate("MyLogger", mockLogger).buildLogging();
  // do some work
  TestLogger logger = loggerFactory.getLogger("MyLogger");
  logger.info("Hello Johnny");
  logger.info("Hello Gracie");
  // check that the mock was called in the right order
  InOrder inOrder = Mockito.inOrder(mockLogger);
  inOrder.verify(mockLogger).info("Hello Johnny");
  inOrder.verify(mockLogger).info("Hello Gracie");
}
origin: portingle/slf4jtesting

TestLogger logger = loggerFactory.getLogger(this.getClass());
origin: portingle/slf4jtesting

/**
 * trivial demo of calling the logging functions on a logger and verifying what was logged.
 */
@Test
public void demoConsoleLoggingUsingConstructor() throws Exception {
  TestLoggerFactory loggerFactory = Settings.instance()
      .enableAll() // necessary as by default only ErrorLevel is enabled
      .buildLogging();
  TestLogger logger = loggerFactory.getLogger("MyLogger");
  // expect to see some console logging
  logger.info("Hello World!");
  // verification - the TestLogger instance will have collected all the enabled logging was sent to the loggers
  TestLogger testLogger = loggerFactory.getLogger("MyLogger");
  Assert.assertTrue(testLogger.matches("Hello World!"));
}
origin: portingle/slf4jtesting

public void testErrorCanBeDisabled() {
  TestLoggerFactory f = Settings.instance().disable(LogLevel.ErrorLevel).buildLogging();
  TestLogger log = f.getLogger("john");
  assert (!log.isErrorEnabled());
}
slf4jtestTestLoggerFactory

Most used methods

  • <init>
  • getLogger
    get or create the logger
  • matches
  • createMock

Popular in Java

  • Reactive rest calls using spring rest template
  • findViewById (Activity)
  • addToBackStack (FragmentTransaction)
  • notifyDataSetChanged (ArrayAdapter)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now