/** * Checks that the message factory a logger was created with is the same as the given messageFactory. If they are * different log a warning to the {@linkplain StatusLogger}. A null MessageFactory translates to the default * MessageFactory {@link #DEFAULT_MESSAGE_FACTORY_CLASS}. * * @param logger The logger to check * @param messageFactory The message factory to check. */ public static void checkMessageFactory(final ExtendedLogger logger, final MessageFactory messageFactory) { final String name = logger.getName(); final MessageFactory loggerMessageFactory = logger.getMessageFactory(); if (messageFactory != null && !loggerMessageFactory.equals(messageFactory)) { StatusLogger.getLogger().warn( "The Logger {} was created with the message factory {} and is now requested with the " + "message factory {}, which may create log events with unexpected formatting.", name, loggerMessageFactory, messageFactory); } else if (messageFactory == null && !loggerMessageFactory.getClass().equals(DEFAULT_MESSAGE_FACTORY_CLASS)) { StatusLogger .getLogger() .warn("The Logger {} was created with the message factory {} and is now requested with a null " + "message factory (defaults to {}), which may create log events with unexpected " + "formatting.", name, loggerMessageFactory, DEFAULT_MESSAGE_FACTORY_CLASS.getName()); } }
/** * FastLogger should delegate getName */ @Test public void delegateGetName() { assertThat(fastLogger.getName()).isEqualTo(LOGGER_NAME); verify(mockedLogger, never()).getName(); } }
@Before public void setUp() { MessageFactory messageFactory = new ParameterizedMessageFactory(); mockedLogger = mock(ExtendedLogger.class); mockedMarker = mock(Marker.class); when(mockedLogger.getMessageFactory()).thenReturn(messageFactory); when(mockedLogger.getName()).thenReturn(LOGGER_NAME); when(mockedLogger.getLevel()).thenReturn(Level.INFO); when(mockedMarker.getName()).thenReturn(MARKER_NAME); fastLogger = new FastLogger(mockedLogger); FastLogger.setDelegating(true); clearInvocations(mockedLogger); assertThat(mockedLogger.getLevel()).isEqualTo(Level.INFO); }
public String getName() { return m_delegate.getName(); }
/** * Checks that the message factory a logger was created with is the same as the given messageFactory. If they are * different log a warning to the {@linkplain StatusLogger}. A null MessageFactory translates to the default * MessageFactory {@link #DEFAULT_MESSAGE_FACTORY_CLASS}. * * @param logger The logger to check * @param messageFactory The message factory to check. */ public static void checkMessageFactory(final ExtendedLogger logger, final MessageFactory messageFactory) { final String name = logger.getName(); final MessageFactory loggerMessageFactory = logger.getMessageFactory(); if (messageFactory != null && !loggerMessageFactory.equals(messageFactory)) { StatusLogger.getLogger().warn( "The Logger {} was created with the message factory {} and is now requested with the " + "message factory {}, which may create log events with unexpected formatting.", name, loggerMessageFactory, messageFactory); } else if (messageFactory == null && !loggerMessageFactory.getClass().equals(DEFAULT_MESSAGE_FACTORY_CLASS)) { StatusLogger .getLogger() .warn("The Logger {} was created with the message factory {} and is now requested with a null " + "message factory (defaults to {}), which may create log events with unexpected " + "formatting.", name, loggerMessageFactory, DEFAULT_MESSAGE_FACTORY_CLASS.getName()); } }