Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 92E15200C32 for ; Thu, 9 Mar 2017 19:21:45 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 91830160B75; Thu, 9 Mar 2017 18:21:45 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B383A160B5F for ; Thu, 9 Mar 2017 19:21:44 +0100 (CET) Received: (qmail 10856 invoked by uid 500); 9 Mar 2017 18:21:43 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 10847 invoked by uid 99); 9 Mar 2017 18:21:43 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Mar 2017 18:21:43 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 68F9CC0FCB for ; Thu, 9 Mar 2017 18:21:43 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.652 X-Spam-Level: X-Spam-Status: No, score=0.652 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_NEUTRAL=0.652, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id UccfGHZBC5Yo for ; Thu, 9 Mar 2017 18:21:42 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 32A1E5F1EE for ; Thu, 9 Mar 2017 18:21:42 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id C56DDE09F0 for ; Thu, 9 Mar 2017 18:21:38 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 29E89243B2 for ; Thu, 9 Mar 2017 18:21:38 +0000 (UTC) Date: Thu, 9 Mar 2017 18:21:38 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: log4j-dev@logging.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (LOG4J2-1842) Expand SystemPropertiesLookup syntax MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 09 Mar 2017 18:21:45 -0000 [ https://issues.apache.org/jira/browse/LOG4J2-1842?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15903549#comment-15903549 ] ASF GitHub Bot commented on LOG4J2-1842: ---------------------------------------- GitHub user mihhail-lapushkin opened a pull request: https://github.com/apache/logging-log4j2/pull/64 [LOG4J2-1842] Expand SystemPropertiesLookup syntax The table in **Property Substitution** needs to be updated: https://logging.apache.org/log4j/2.x/manual/configuration.html Next to **sys** change the contents of **Context** column to: > System properties. Can be either a simple property key for System.getProperty(key) or a series of pipe-separated property keys followed by a default value key1|key2|...|keyn|defaultValue. Either the first existing property or the default value is used. You can merge this pull request into a Git repository by running: $ git pull https://github.com/mihhail-lapushkin/logging-log4j2 master Alternatively you can review and apply these changes as the patch at: https://github.com/apache/logging-log4j2/pull/64.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #64 ---- commit 6998bb8882c749d9ace1a86429836431910e9e21 Author: Mihhail Lapushkin Date: 2017-03-09T18:08:13Z [LOG4J2-1842] Expand SystemPropertiesLookup syntax: - Implemented the proposal - Refactored test and added new test cases ---- > Expand SystemPropertiesLookup syntax > ------------------------------------ > > Key: LOG4J2-1842 > URL: https://issues.apache.org/jira/browse/LOG4J2-1842 > Project: Log4j 2 > Issue Type: Improvement > Components: Lookups > Reporter: Mihhail Lapushkin > Priority: Minor > > I've been using a modified version of {{SystemPropertiesLookup}} in my project. Maybe it could be part of the library. > The idea is to allow a series of property keys to be specified. If one of the properties is present, then it is used. If none are present, then the default value is used. For example: > {code} > > > > {code} > This allows me to quickly rerun the app with different log levels without fiddling with the configuration file or JConsole. Defaults represent production settings, so that nothing extra needs to be specified to run the app. > This work nice in other places as well: > {code} > > {code} > Disables colors by default (for production build), but leaves an easy way to turn them on for development. > When no pipes are present in the expression, then the standard property lookup is used, so the change is backwards-compatible. > Can be a separate lookup if needed. > Here is the possible implementation: > {code} > @Plugin(name = "sys", category = StrLookup.CATEGORY) > public class SystemPropertiesLookup extends AbstractLookup { > private static final Logger LOGGER = StatusLogger.getLogger(); > private static final Marker LOOKUP = MarkerManager.getMarker("LOOKUP"); > /** > * @param event The current LogEvent. > * @param expression the expression to be looked up. > * @return The value resolved by expression. > */ > @Override > public String lookup(final LogEvent event, final String expression) { > try { > if (expression.indexOf('|') < 0) { > return System.getProperty(expression); > } > String[] expressionElements = expression.split("\\|"); > for (int i = 0; i < expressionElements.length - 1; i++) { > String propertyValue = System.getProperty(expressionElements[i]); > if (propertyValue != null) { > return propertyValue; > } > } > return expressionElements[expressionElements.length - 1]; > } catch (final Exception ex) { > LOGGER.warn(LOOKUP, "Error while resolving system property by expression [{}].", expression, ex); > return null; > } > } > } > {code} -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-dev-help@logging.apache.org