@Override public ExtendedLogger getLogger(final String name) { return getLogger(name, null); }
@Override public Level getLevel() { return logger.getLevel(); }
public void setLevel(final Level level) { logger.setLevel(level); }
/** * Returns a LoggerContext. * * @param loader The ClassLoader for the context. If null the context will attempt to determine the appropriate * ClassLoader. * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be * returned and if the caller is a class in the container's classpath then a different LoggerContext may * be returned. If true then only a single LoggerContext will be returned. * @return a LoggerContext. */ public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext) { try { return factory.getContext(FQCN, loader, null, currentContext); } catch (final IllegalStateException ex) { LOGGER.warn(ex.getMessage() + " Using SimpleLogger"); return new SimpleLoggerContextFactory().getContext(FQCN, loader, null, currentContext); } }
private StatusLogger(final String name, final MessageFactory messageFactory) { super(name, messageFactory); final String dateFormat = PROPS.getStringProperty(STATUS_DATE_FORMAT, Strings.EMPTY); final boolean showDateTime = !Strings.isEmpty(dateFormat); this.logger = new SimpleLogger("StatusLogger", Level.ERROR, false, true, showDateTime, false, dateFormat, messageFactory, PROPS, System.err); this.listenersLevel = Level.toLevel(DEFAULT_STATUS_LEVEL, Level.WARN).intLevel(); // LOG4J2-1813 if system property "log4j2.debug" is defined, print all status logging if (isDebugPropertyEnabled()) { logger.setLevel(Level.TRACE); } }
@Override public ExtendedLogger getLogger(final String name, final MessageFactory messageFactory) { // Note: This is the only method where we add entries to the 'loggerRegistry' ivar. final ExtendedLogger extendedLogger = loggerRegistry.getLogger(name, messageFactory); if (extendedLogger != null) { AbstractLogger.checkMessageFactory(extendedLogger, messageFactory); return extendedLogger; } final SimpleLogger simpleLogger = new SimpleLogger(name, defaultLevel, showLogName, showShortName, showDateTime, showContextMap, dateTimeFormat, messageFactory, props, stream); loggerRegistry.putIfAbsent(name, messageFactory, simpleLogger); return loggerRegistry.getLogger(name, messageFactory); }
@Override public boolean isEnabled(final Level level, final Marker marker) { // LOG4J2-1813 if system property "log4j2.debug" is defined, all status logging is enabled if (isDebugPropertyEnabled()) { return true; } if (listeners.size() > 0) { return listenersLevel >= level.intLevel(); } return logger.isEnabled(level, marker); }
logger.logMessage(fqcn, level, marker, msg, t); } else { if (listeners.size() > 0) { logger.logMessage(fqcn, level, marker, msg, t);
if (i % 2 == 0) { lastUsedContext = new SimpleLoggerContext();
/** * Returns the current LoggerContext. * <p> * WARNING - The LoggerContext returned by this method may not be the LoggerContext used to create a Logger for the * calling class. * </p> * * @return The current LoggerContext. */ public static LoggerContext getContext() { try { return factory.getContext(FQCN, null, null, true); } catch (final IllegalStateException ex) { LOGGER.warn(ex.getMessage() + " Using SimpleLogger"); return new SimpleLoggerContextFactory().getContext(FQCN, null, null, true); } }
@Override public void setLevel(String level) { Level new_level=strToLevel(level); if(new_level == null) return; if(logger instanceof org.apache.logging.log4j.core.Logger) ((org.apache.logging.log4j.core.Logger)logger).setLevel(new_level); else if(logger instanceof SimpleLogger) ((SimpleLogger)logger).setLevel(new_level); }
@Test public void testIsGemfireObject() { assertTrue("Instances of Function are GemFire objects", InternalDataSerializer.isGemfireObject(new TestFunction())); assertFalse("Instances of PdxSerializaerObject are NOT GemFire objects", InternalDataSerializer.isGemfireObject(new TestPdxSerializerObject())); assertFalse("Instances of anything under org.apache. are GemFire objects", InternalDataSerializer.isGemfireObject(new SimpleLogger("", Level.OFF, false, false, false, false, "", null, new PropertiesUtil(new Properties()), null))); assertTrue("Instances of anything in org.apache.geode. are GemFire objects", InternalDataSerializer.isGemfireObject(new InternalGemFireException())); assertTrue("Instances of anything under org.apache.geode. are GemFire objects", InternalDataSerializer.isGemfireObject(new ExampleSecurityManager())); }
/** * Returns a LoggerContext. * * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be * returned and if the caller is a class in the container's classpath then a different LoggerContext may * be returned. If true then only a single LoggerContext will be returned. * @return a LoggerContext. */ public static LoggerContext getContext(final boolean currentContext) { // TODO: would it be a terrible idea to try and find the caller ClassLoader here? try { return factory.getContext(FQCN, null, null, currentContext, null, null); } catch (final IllegalStateException ex) { LOGGER.warn(ex.getMessage() + " Using SimpleLogger"); return new SimpleLoggerContextFactory().getContext(FQCN, null, null, currentContext, null, null); } }
/** * Returns a LoggerContext * * @param fqcn The fully qualified class name of the Class that this method is a member of. * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be * returned and if the caller is a class in the container's classpath then a different LoggerContext may * be returned. If true then only a single LoggerContext will be returned. * @return a LoggerContext. */ protected static LoggerContext getContext(final String fqcn, final boolean currentContext) { try { return factory.getContext(fqcn, null, null, currentContext); } catch (final IllegalStateException ex) { LOGGER.warn(ex.getMessage() + " Using SimpleLogger"); return new SimpleLoggerContextFactory().getContext(fqcn, null, null, currentContext); } }
/** * Returns a LoggerContext * * @param fqcn The fully qualified class name of the Class that this method is a member of. * @param loader The ClassLoader for the context. If null the context will attempt to determine the appropriate * ClassLoader. * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be * returned and if the caller is a class in the container's classpath then a different LoggerContext may * be returned. If true then only a single LoggerContext will be returned. * @return a LoggerContext. */ protected static LoggerContext getContext(final String fqcn, final ClassLoader loader, final boolean currentContext) { try { return factory.getContext(fqcn, loader, null, currentContext); } catch (final IllegalStateException ex) { LOGGER.warn(ex.getMessage() + " Using SimpleLogger"); return new SimpleLoggerContextFactory().getContext(fqcn, loader, null, currentContext); } }
/** * Returns a LoggerContext. * * @param loader The ClassLoader for the context. If null the context will attempt to determine the appropriate * ClassLoader. * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be * returned and if the caller is a class in the container's classpath then a different LoggerContext may * be returned. If true then only a single LoggerContext will be returned. * @param configLocation The URI for the configuration to use. * @return a LoggerContext. */ public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext, final URI configLocation) { try { return factory.getContext(FQCN, loader, null, currentContext, configLocation, null); } catch (final IllegalStateException ex) { LOGGER.warn(ex.getMessage() + " Using SimpleLogger"); return new SimpleLoggerContextFactory().getContext(FQCN, loader, null, currentContext, configLocation, null); } }
/** * Returns a LoggerContext. * * @param loader The ClassLoader for the context. If null the context will attempt to determine the appropriate * ClassLoader. * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be * returned and if the caller is a class in the container's classpath then a different LoggerContext may * be returned. If true then only a single LoggerContext will be returned. * @param externalContext An external context (such as a ServletContext) to be associated with the LoggerContext. * @return a LoggerContext. */ public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext, final Object externalContext) { try { return factory.getContext(FQCN, loader, externalContext, currentContext); } catch (final IllegalStateException ex) { LOGGER.warn(ex.getMessage() + " Using SimpleLogger"); return new SimpleLoggerContextFactory().getContext(FQCN, loader, externalContext, currentContext); } }
/** * Returns a LoggerContext * * @param fqcn The fully qualified class name of the Class that this method is a member of. * @param loader The ClassLoader for the context. If null the context will attempt to determine the appropriate * ClassLoader. * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be * returned and if the caller is a class in the container's classpath then a different LoggerContext may * be returned. If true then only a single LoggerContext will be returned. * @param configLocation The URI for the configuration to use. * @param name The LoggerContext name. * @return a LoggerContext. */ protected static LoggerContext getContext(final String fqcn, final ClassLoader loader, final boolean currentContext, URI configLocation, String name) { try { return factory.getContext(fqcn, loader, null, currentContext, configLocation, name); } catch (final IllegalStateException ex) { LOGGER.warn(ex.getMessage() + " Using SimpleLogger"); return new SimpleLoggerContextFactory().getContext(fqcn, loader, null, currentContext); } }
/** * Returns a LoggerContext. * * @param loader The ClassLoader for the context. If null the context will attempt to determine the appropriate * ClassLoader. * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be * returned and if the caller is a class in the container's classpath then a different LoggerContext may * be returned. If true then only a single LoggerContext will be returned. * @param externalContext An external context (such as a ServletContext) to be associated with the LoggerContext. * @param configLocation The URI for the configuration to use. * @param name The LoggerContext name. * @return a LoggerContext. */ public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext, final Object externalContext, final URI configLocation, final String name) { try { return factory.getContext(FQCN, loader, externalContext, currentContext, configLocation, name); } catch (final IllegalStateException ex) { LOGGER.warn(ex.getMessage() + " Using SimpleLogger"); return new SimpleLoggerContextFactory().getContext(FQCN, loader, externalContext, currentContext, configLocation, name); } }
/** * Returns a LoggerContext. * * @param loader The ClassLoader for the context. If null the context will attempt to determine the appropriate * ClassLoader. * @param currentContext if false the LoggerContext appropriate for the caller of this method is returned. For * example, in a web application if the caller is a class in WEB-INF/lib then one LoggerContext may be * returned and if the caller is a class in the container's classpath then a different LoggerContext may * be returned. If true then only a single LoggerContext will be returned. * @param externalContext An external context (such as a ServletContext) to be associated with the LoggerContext. * @param configLocation The URI for the configuration to use. * @return a LoggerContext. */ public static LoggerContext getContext(final ClassLoader loader, final boolean currentContext, final Object externalContext, final URI configLocation) { try { return factory.getContext(FQCN, loader, externalContext, currentContext, configLocation, null); } catch (final IllegalStateException ex) { LOGGER.warn(ex.getMessage() + " Using SimpleLogger"); return new SimpleLoggerContextFactory().getContext(FQCN, loader, externalContext, currentContext, configLocation, null); } }