/** * Gets the named property as a boolean value. If the property matches the string {@code "true"} (case-insensitive), * then it is returned as the boolean value {@code true}. Any other non-{@code null} text in the property is * considered {@code false}. * * @param name the name of the property to look up * @return the boolean value of the property or {@code false} if undefined. */ public boolean getBooleanProperty(final String name) { return getBooleanProperty(name, false); }
static void init() { inheritableMap = PropertiesUtil.getProperties().getBooleanProperty(INHERITABLE_MAP); }
private boolean isDebugPropertyEnabled() { return PropertiesUtil.getProperties().getBooleanProperty(Constants.LOG4J2_DEBUG, false, true); }
/** * Initializes static variables based on system properties. Normally called when this class is initialized by the VM * and when Log4j is reconfigured. */ static void init() { final PropertiesUtil properties = PropertiesUtil.getProperties(); initialCapacity = properties.getIntegerProperty(PROPERTY_NAME_INITIAL_CAPACITY, DEFAULT_INITIAL_CAPACITY); inheritableMap = properties.getBooleanProperty(INHERITABLE_MAP); }
public SimpleLoggerContext() { props = new PropertiesUtil("log4j2.simplelog.properties"); showContextMap = props.getBooleanProperty(SYSTEM_PREFIX + "showContextMap", false); showLogName = props.getBooleanProperty(SYSTEM_PREFIX + "showlogname", false); showShortName = props.getBooleanProperty(SYSTEM_PREFIX + "showShortLogname", true); showDateTime = props.getBooleanProperty(SYSTEM_PREFIX + "showdatetime", false); final String lvl = props.getStringProperty(SYSTEM_PREFIX + "level"); defaultLevel = Level.toLevel(lvl, Level.ERROR); dateTimeFormat = showDateTime ? props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + "dateTimeFormat", DEFAULT_DATE_TIME_FORMAT) : null; final String fileName = props.getStringProperty(SYSTEM_PREFIX + "logFile", SYSTEM_ERR); PrintStream ps; if (SYSTEM_ERR.equalsIgnoreCase(fileName)) { ps = System.err; } else if (SYSTEM_OUT.equalsIgnoreCase(fileName)) { ps = System.out; } else { try { final FileOutputStream os = new FileOutputStream(fileName); ps = new PrintStream(os); } catch (final FileNotFoundException fnfe) { ps = System.err; } } this.stream = ps; }
/** * Initializes static variables based on system properties. Normally called when this class is initialized by the VM * and when Log4j is reconfigured. */ static void init() { final PropertiesUtil properties = PropertiesUtil.getProperties(); initialCapacity = properties.getIntegerProperty(PROPERTY_NAME_INITIAL_CAPACITY, DEFAULT_INITIAL_CAPACITY); inheritableMap = properties.getBooleanProperty(INHERITABLE_MAP); }
/** * Initializes static variables based on system properties. Normally called when this class is initialized by the VM * and when Log4j is reconfigured. */ private static void initPrivate() { final PropertiesUtil properties = PropertiesUtil.getProperties(); ThreadContextMapName = properties.getStringProperty(THREAD_CONTEXT_KEY); GcFreeThreadContextKey = properties.getBooleanProperty(GC_FREE_THREAD_CONTEXT_KEY); }
/** * <em>Consider private, used for testing.</em> */ static void init() { ThreadContextMapFactory.init(); contextMap = null; final PropertiesUtil managerProps = PropertiesUtil.getProperties(); disableAll = managerProps.getBooleanProperty(DISABLE_ALL); useStack = !(managerProps.getBooleanProperty(DISABLE_STACK) || disableAll); useMap = !(managerProps.getBooleanProperty(DISABLE_MAP) || disableAll); contextStack = new DefaultThreadContextStack(useStack); if (!useMap) { contextMap = new NoOpThreadContextMap(); } else { contextMap = ThreadContextMapFactory.createThreadContextMap(); } if (contextMap instanceof ReadOnlyThreadContextMap) { readOnlyContextMap = (ReadOnlyThreadContextMap) contextMap; } else { readOnlyContextMap = null; } }
/** * Gets the named property as a boolean value. If the property matches the string {@code "true"} (case-insensitive), * then it is returned as the boolean value {@code true}. Any other non-{@code null} text in the property is * considered {@code false}. * * @param name the name of the property to look up * @return the boolean value of the property or {@code false} if undefined. */ public boolean getBooleanProperty(final String name) { return getBooleanProperty(name, false); }
/** * <em>Consider private, used for testing.</em> */ static void init() { contextMap = null; final PropertiesUtil managerProps = PropertiesUtil.getProperties(); disableAll = managerProps.getBooleanProperty(DISABLE_ALL); useStack = !(managerProps.getBooleanProperty(DISABLE_STACK) || disableAll); useMap = !(managerProps.getBooleanProperty(DISABLE_MAP) || disableAll); contextStack = new Log4jv2ThreadContextStack(useStack); contextMap = new Log4jv2ThreadContextMap(); }
private boolean isDebugPropertyEnabled() { return PropertiesUtil.getProperties().getBooleanProperty(Constants.LOG4J2_DEBUG, false, true); }
private ThreadLocal<StringMap> createThreadLocalMap() { final PropertiesUtil managerProps = PropertiesUtil.getProperties(); final boolean inheritable = managerProps.getBooleanProperty(INHERITABLE_MAP); if (inheritable) { return new InheritableThreadLocal<StringMap>() { @Override protected StringMap childValue(final StringMap parentValue) { return parentValue != null ? createStringMap(parentValue) : null; } }; } // if not inheritable, return plain ThreadLocal with null as initial value return new ThreadLocal<>(); }
private ThreadLocal<StringMap> createThreadLocalMap() { final PropertiesUtil managerProps = PropertiesUtil.getProperties(); final boolean inheritable = managerProps.getBooleanProperty(INHERITABLE_MAP); if (inheritable) { return new InheritableThreadLocal<StringMap>() { @Override protected StringMap childValue(final StringMap parentValue) { return parentValue != null ? createStringMap(parentValue) : null; } }; } // if not inheritable, return plain ThreadLocal with null as initial value return new ThreadLocal<>(); }
private static boolean isJmxDisabled() { return PropertiesUtil.getProperties().getBooleanProperty(PROPERTY_DISABLE_JMX); }
static ThreadLocal<Map<String, String>> createThreadLocalMap(final boolean isMapEnabled) { final PropertiesUtil managerProps = PropertiesUtil.getProperties(); final boolean inheritable = managerProps.getBooleanProperty(INHERITABLE_MAP); if (inheritable) { return new InheritableThreadLocal<Map<String, String>>() { @Override protected Map<String, String> childValue(final Map<String, String> parentValue) { return parentValue != null && isMapEnabled // ? Collections.unmodifiableMap(new HashMap<>(parentValue)) // : null; } }; } // if not inheritable, return plain ThreadLocal with null as initial value return new ThreadLocal<>(); }
/** * Returns either a {@code null} Executor (causing JMX notifications to be sent from the caller thread) or a daemon * background thread Executor, depending on the value of system property "log4j2.jmx.notify.async". If this * property is not set, use a {@code null} Executor for web apps to avoid memory leaks and other issues when the * web app is restarted. * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-938">LOG4J2-938</a> */ private static ExecutorService createExecutor() { final boolean defaultAsync = !Constants.IS_WEB_APP; final boolean async = PropertiesUtil.getProperties().getBooleanProperty(PROPERTY_ASYNC_NOTIF, defaultAsync); return async ? Executors.newFixedThreadPool(1, Log4jThreadFactory.createDaemonThreadFactory(THREAD_NAME_PREFIX)) : null; }
public SimpleLoggerContext() { props = new PropertiesUtil("log4j2.simplelog.properties"); showContextMap = props.getBooleanProperty(SYSTEM_PREFIX + "showContextMap", false); showLogName = props.getBooleanProperty(SYSTEM_PREFIX + "showlogname", false); showShortName = props.getBooleanProperty(SYSTEM_PREFIX + "showShortLogname", true); showDateTime = props.getBooleanProperty(SYSTEM_PREFIX + "showdatetime", false); final String lvl = props.getStringProperty(SYSTEM_PREFIX + "level"); defaultLevel = Level.toLevel(lvl, Level.ERROR); dateTimeFormat = showDateTime ? props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + "dateTimeFormat", DEFAULT_DATE_TIME_FORMAT) : null; final String fileName = props.getStringProperty(SYSTEM_PREFIX + "logFile", SYSTEM_ERR); PrintStream ps; if (SYSTEM_ERR.equalsIgnoreCase(fileName)) { ps = System.err; } else if (SYSTEM_OUT.equalsIgnoreCase(fileName)) { ps = System.out; } else { try { final FileOutputStream os = new FileOutputStream(fileName); ps = new PrintStream(os); } catch (final FileNotFoundException fnfe) { ps = System.err; } } this.stream = ps; }
if (!propsUtil.isOsWindows() || propsUtil.getBooleanProperty("log4j.skipJansi") || direct) { return outputStream;
private static ThreadContextMap createDefaultThreadContextMap() { if (Constants.ENABLE_THREADLOCALS) { if (PropertiesUtil.getProperties().getBooleanProperty(GC_FREE_THREAD_CONTEXT_KEY)) { return new GarbageFreeSortedArrayThreadContextMap(); } return new CopyOnWriteSortedArrayThreadContextMap(); } return new DefaultThreadContextMap(true); } }
@Override public void start() { LOGGER.debug("Starting LoggerContext[name={}, {}]...", getName(), this); if (PropertiesUtil.getProperties().getBooleanProperty("log4j.LoggerContext.stacktrace.on.start", false)) { LOGGER.debug("Stack trace to locate invoker", new Exception("Not a real error, showing stack trace to locate invoker")); } if (configLock.tryLock()) { try { if (this.isInitialized() || this.isStopped()) { this.setStarting(); reconfigure(); if (this.configuration.isShutdownHookEnabled()) { setUpShutdownHook(); } this.setStarted(); } } finally { configLock.unlock(); } } LOGGER.debug("LoggerContext[name={}, {}] started OK.", getName(), this); }