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 C8806200D5D for ; Wed, 20 Dec 2017 17:41:35 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C6945160C15; Wed, 20 Dec 2017 16:41:35 +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 94927160BF9 for ; Wed, 20 Dec 2017 17:41:34 +0100 (CET) Received: (qmail 27481 invoked by uid 500); 20 Dec 2017 16:41:28 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 27470 invoked by uid 99); 20 Dec 2017 16:41:28 -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; Wed, 20 Dec 2017 16:41:28 +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 1C888C3B6A for ; Wed, 20 Dec 2017 16:41:28 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.68 X-Spam-Level: * X-Spam-Status: No, score=1.68 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, KAM_NUMSUBJECT=0.5, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id hQREReEQZYSy for ; Wed, 20 Dec 2017 16:41:24 +0000 (UTC) Received: from mail-it0-f54.google.com (mail-it0-f54.google.com [209.85.214.54]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 3885E5F254 for ; Wed, 20 Dec 2017 16:41:23 +0000 (UTC) Received: by mail-it0-f54.google.com with SMTP id u62so7430686ita.2 for ; Wed, 20 Dec 2017 08:41:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=kb89I3MfMj3eF7mV1JbBejMhmCiQLS8ORW/U33qIOj0=; b=tHKnLfui53CVVXKCo6UweswcyhqoKy7Qux+JtIso4m4XO8AB4sPASIIhgjjR4qyMvy /yuzvhJMIqp0k8NMuvxepLt/tE94+D2N/tMWYBRffp4Ikel0yj3rhOx3QxRcZVZbV4/W PaSuKP8/Ut082fX2Ltn2QHbomtYDHno4WXB0948t52EJV2VSHZEEx6Gbf/+0xRz/4C5K FZeyCFgRByYZpWzbmDhGCLT6p+6Uam8rPT8Q3nzFO0b6jtulsQpQtWUEjqEqMqFyFFNG DjcxxRYiVd1Nummj7E1EjyrPPezcp1XW1l+TyfVTQQhbbGNI8Bkle0vHDB1yVTxU+a2j GJBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=kb89I3MfMj3eF7mV1JbBejMhmCiQLS8ORW/U33qIOj0=; b=OpYFiiXU3hqvEIjh0IeIYzVtvJZylvfcUMT+yZ85N3SIwzeJPNlamoOKhVBJcIE0rC 75+3MrEYtXUgsSle9X9cgGUGQUsMjgWvsWOI8rPashufYdxENIhcX8ssb08a/LTNAhit CW3hKFcwZjsJQZO5WWAiFmK5PxVn8grKcHhjL85w2jRVJf3HqxpnhsokSztPzrVnTTkL ZmVc1vZRbiwB387LlQp+74L2Ogj86LcWKaBzN1kDqz7w/Ygp4VkEcevmJFSjOP3/mxEQ WSXfx4IcSo+D9asTgCupGpwCsZA2XLJCRgBKnx3H987NSdFysRI7e/xFGg5w5MJ6Ilv2 DSEw== X-Gm-Message-State: AKGB3mIGWSWj7wVOddepI9IXPBjOdZOBO9Z4XZkJF5n0CeEMQI+ZJx8F Upe+kTKkr4EkkGd+PEmLPH3/fbSug2VL73xHo4M= X-Google-Smtp-Source: ACJfBotnzP45JphsnyLXYKcsTW41GvunNbDg+fUBt8sroxYBO9NqFX94UO34lfTsk8+7ejl+7zlEQMardn/6KVPBUJI= X-Received: by 10.36.31.204 with SMTP id d195mr8012408itd.133.1513788081649; Wed, 20 Dec 2017 08:41:21 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.35.87 with HTTP; Wed, 20 Dec 2017 08:41:20 -0800 (PST) In-Reply-To: <994711695.3542764.1513770763682@mail.yahoo.com> References: <149297028.8989360.1513356584631.ref@mail.yahoo.com> <149297028.8989360.1513356584631@mail.yahoo.com> <1135967208.651998.1513455504142@mail.yahoo.com> <4CC2ECCB-4F67-4DD3-9CFA-77EDB112E3D1@dslextreme.com> <1005045786.429296.1513534958805@mail.yahoo.com> <1175355988.553244.1513544300393@mail.yahoo.com> <81895AB0-D834-47A9-8068-7E3066F56B6C@dslextreme.com> <637410391.626754.1513550454216@mail.yahoo.com> <89A80E08-BB95-4B6E-977F-BF2CB222D131@dslextreme.com> <1288696164.2905519.1513711418274@mail.yahoo.com> <1123222379.3025852.1513718918285@mail.yahoo.com> <994711695.3542764.1513770763682@mail.yahoo.com> From: Matt Sicker Date: Wed, 20 Dec 2017 10:41:20 -0600 Message-ID: Subject: Re: Migrating from log4j1 to log4j2 To: Log4J Users List , Paladox Content-Type: multipart/alternative; boundary="001a11444d0edf3da60560c84015" archived-at: Wed, 20 Dec 2017 16:41:36 -0000 --001a11444d0edf3da60560c84015 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Manually managing configurations along with a config file sounds overly complicated. A composite configuration might work here, though I've never used that feature yet. You could use the config file as the first config, then the programmatic config as the second config so it overrides the first (or swap it). You can specify an implementation of MergeStrategy via the log4j2.mergeStrategy global property for more complex merging. On 20 December 2017 at 05:52, Paladox wrote: > =E2=80=9Cremember the configuration when reconfiguring=E2=80=9D > because we add appenders with java, they will get lost after > the reconfiguration as they are not in the configuation file. We want to > reload the configuation without losing anything. > > "Again, what is the behavior you are looking for? What are you changing > programmatically? Just the log levels of Loggers? Are you wanting those > changes re-applied after a reconfiguration?" > We had log level set to null so that when we reloaded the file it would > add back the loggers. But it wouldn't get rid of any appenders which we s= et > through java. > > We are trying to reset log levels back to what they were set in the file > without losing any appenders. > On Tuesday, 19 December 2017, 23:35:05 GMT, Ralph Goers < > ralph.goers@dslextreme.com> wrote: > > OK. But I am still unclear on what you want the behavior to be. Sometime= s > you speak of reconfiguring and sometimes not. For example, why do you wan= t > to =E2=80=9Cremember the configuration when reconfiguring=E2=80=9D? > > The =E2=80=9Cnormal=E2=80=9D behavior of Log4j 2 when reconfiguring based= on a change to > the configuration is: > Re-read the configuration and create a brand new Configuration. > Start the new Configuration (starts the new Appenders). > Set the LoggerContext to point to the new Configuration. > Update all Loggers to use the new Configuration. > Stop the old Configuration. > > This happens automatically if you have set monitorInterval to a non-zero > value on a Configuration element in a config file. You can force it to > happen by calling LoggerContext.reconfigure(). > > If you have made any programmatic changes to the configuration they will > be lost during this process. If you are =E2=80=9Cremembering the changes= =E2=80=9D you made > programmatically and have captured them you can just reapply them after > Log4j 2 reconfigures. > > Again, what is the behavior you are looking for? What are you changing > programmatically? Just the log levels of Loggers? Are you wanting those > changes re-applied after a reconfiguration? > > Ralph > > > > > > On Dec 19, 2017, at 2:28 PM, Paladox > wrote: > > > > We set it to null so that we can load the configuation file without > resetting anything. > > So if we set the logger to null and load the configuation file it would > not erase anything like the appenders we added with java instead it would > just add back the loggers we set to null and use the level we set in the > configuation file. > > In log4j2 it seems to not support a way like https://github.com/apache/ > log4j/blob/c5f4279081091e562c44bb753f6e52dc6be5fa52/src/main/java/org/ > apache/log4j/PropertyConfigurator.java#L120 > > > > " Read configuration from a file. The existing configuration is > not cleared nor reset. If you require a different behavior, then > call {@link LogManager#resetConfiguration resetConfiguration} method > before calling doConfigure." > > Thats one of the reasons why we had to use null as it did not reset it > (which we doint want anyways) we needed to remove the log level to preven= t > it for example writing tons of info if you have it set to DEBUG. But by r= e > adding the file we got the loggers back to the default value we had them > set at. > > Now in log4j2 there dosen't seem to be anything similar except from the > one you pointed too but that reset everything. > > > > On Tuesday, 19 December 2017, 21:11:26 GMT, Ralph Goers < > ralph.goers@dslextreme.com> wrote: > > > > I still have no idea why you think you need to reset the log level to > null. When you reconfigure you are going to get a brand new configuration > with everything reset anyway. > > > > If I was doing what you say you want to do I would create a > configuration file that has the stuff that you always want to add. I woul= d > then use Configurator.initialize(=E2=80=9Cfile1, file2=E2=80=9D) to combi= ne the user=E2=80=99s > configuration with yours. > > > > Ralph > > > >> On Dec 19, 2017, at 12:23 PM, Paladox > wrote: > >> > >> Thanks, hmm. Im a little unsure how to do this part now. Im only stuck > on this last part. Then we can migrate to log42. > >> > >> Im wondering how do i get log4j2 to remember the configuation when > reconfiguring. As all i need is to reset the log level to null then load > the file which reads the logging without causing a null pointer. > >> > >> I see there's ConfigurationBuilder as you pointed too but we use a > mixture of java / using the properties files. > >> > >> So we add a appender with java but add ConsoleAppender through the > properties file. > >> > >> Reading this https://github.com/apache/log4j/blob/ > c5f4279081091e562c44bb753f6e52dc6be5fa52/src/main/java/org/apache/log4j/ > PropertyConfigurator.java#L120 seems to say that it just reads the > configuation but dosen't clear anything. I wonder would something like be > able to be added to log4j2 please? > >> > >> > >> > >> On Sunday, 17 December 2017, 23:30:02 GMT, Ralph Goers < > ralph.goers@dslextreme.com> wrote: > >> > >> > >> The way log4j 1 worked and how log4j 2 works are a bit different. Log4= j > 1 only had Loggers. When you wanted to configure a Logger you obtained a > Logger and added an appender to it or set its logging level. If you creat= ed > a Logger that didn=E2=80=99t have a logging level it would go to its pare= nt Logger > and get it from there. So setting a Logger=E2=80=99s logging level to nul= l > basically said =E2=80=9Clook at your parent=E2=80=9D. When an applicatio= n wants to log > something it also obtains a Logger. So the Loggers used for logging and > configuration were the same. In order to reconfigure, Log4j 1 would clear > everything from the Loggers and then start adding configuration back to > them as it processed the configuration. During the time that the Loggers > are cleared and before configuration is added back events are ignored. > >> > >> Log4j 2 doesn=E2=80=99t work this way at all. When the configuration i= s read a > set of LoggerConfig objects is created. These all contain the same > information that is in the configuration file. When an application wants = to > log it gets a Logger. The Logger looks for a LoggerConfig with its name o= r, > if one isn=E2=80=99t found, one of its ancestors. The Logger then is set = with a > reference to the LoggerConfig that provides its configuration and it copi= es > that LoggerConfig=E2=80=99s logging level into it to improve performance.= Thus, > when you want to change a logging level you need to locate the > LoggerConfig for the Logger, update its logging level, and then call > updateLoggers to cause all Loggers to reevaluate which LoggerConfig they > should be using and what their current logging level is. > >> > >> There are several ways to deal with changes. > >> You add a listener to handle configuration changes. This would allow > you to reinsert changes to the configuration. > >> You can create your own Configuration and combine it with the user=E2= =80=99s > configuration using a CompositeConfiguration. Your configuration can be > created with a config file or via the ConfigurationBuilder. > >> You can extend XMLConfiguration and/or PropertiesConfiguration and add > your own definitions to it. > >> > >> I am sure there are other ways this can all be done depending on what > you are trying to achieve. If you modify the logging level of a > LoggerConfig and then a reconfigure occurs Log4j will automatically handl= e > resetting the configuration. You don=E2=80=99t have to do anything. If yo= u want to > reinsert changes to the user=E2=80=99s configuration then you have to use= one of > the techniques I noted above. > >> > >> Ralph > >> > >> > >> > >> > >>> On Dec 17, 2017, at 3:40 PM, Paladox > wrote: > >>> > >>> "You didn=E2=80=99t answer what logging level you are setting to null= and why." > >>> Im not really sure why it was set to null as this was done long befor= e > i started contributing to gerrit. > >>> I can presume it was done because PropertyConfiguator would reload th= e > file but wouldn't discard anything else so if we set loggers through java > then reloading the file would not affect them. So i guess they wanted to > make sure everything goes back to the way it was. > >>> More explementation, because we have a ssh command that can set log > levels for either all or specific loggers we want to be able to remove th= e > levels to put it back to how it was done when the application was started= . > So ie if we set debug on com.google. then that will be added to the logge= rs > as > >>> com.google =3D DEBUG > >>> but when the application was started that was not in the loggers so w= e > did not get any debug in the output. > >>> But we want to set it to the default by removing com.google as logger= s > in com.google have different levels. IE in the log4j2.properties file we > have > >>> com.google.gerrit.sshd.GerritServerSession which is set to WARN > >>> > >>> but now because we did com.google @ debug com.google.gerrit.sshd.Gerr= itServerSession > will be debug and everything else under com.google class path that uses > loggers. > >>> But users would not know every logger under com.google so they > wouldn't be able to put them all back to the default so we set the log > level to null and reloaded the file without loosing any java appenders. B= ut > with log4j2 it seems to restart as new. > >>> On Sunday, 17 December 2017, 22:25:28 GMT, Ralph Goers < > ralph.goers@dslextreme.com > wrote: > >>> > >>> You didn=E2=80=99t answer what logging level you are setting to null = and why. > >>> > >>> I=E2=80=99m still not getting a clear picture of what the real requir= ements > are. "we use java to add appenders and other things because we want users > to customise the behavour through a config=E2=80=9D tells me you want use= rs to be > able to use their own configuration but not why you want to add appenders > and =E2=80=9Cother things=E2=80=9D or what requirement you are trying to = solve with them. > What I need here is some sort of =E2=80=9Cuser story definition=E2=80=9D = like - =E2=80=9CAs a user > of Gerrit I need to be able to provide my own logging configuration while > Gerrit makes sure that error conditions are always logged even if my > configuration doesn=E2=80=99t specify it=E2=80=9D or something like that.= We can tell you > how to implement something once we understand what you are really trying = to > achieve. You probably have done this before, but in case you haven=E2=80= =99t done > that before you can look at https://www.mountaingoatsoftware.com/ > agile/user-stories agile/user-stories> agile/user-stories agile/user-stories>>. Also, you might have a definition of what you want > the experience for a user of Gerrit to be vs that of a developer. If so, > tell me what they both are. > >>> > >>> Ralph > >>> > >>>> On Dec 17, 2017, at 1:58 PM, Paladox > wrote: > >>>> > >>>> > >>>> for "=E2=80=9CThen loads the property file=E2=80=9D - what property = file? The log4j 2 > configuration file? Why would you set the log sell to null before reload= ed > the configuration? " > >>>> > >>>> We doin't, we would load it after we set the log level to null. > >>>> > >>>> Also for the "what". Well we use java to add appenders and other > things because we want users to customise the behavour through a config. > For example some users want log4j to log with json instead of the pattern > layout. Though if users want to modify it more then a config they use the > system property to override the default log4j configuation file and use > there own. > >>>> > >>>> On Sunday, 17 December 2017, 20:44:09 GMT, Ralph Goers < > ralph.goers@dslextreme.com > wrote: > >>>> > >>>> > >>>> "Sets the log level to null=E2=80=9D - which log level? The root, a > particular logger, or a Threshold Filter on a particular appender? FWIW, = in > Log4j 1 setting the log level to null on a Logger just means it will > inherit from its parent. That is not necessarily the case in Log4j 2. > >>>> > >>>> =E2=80=9CThen loads the property file=E2=80=9D - what property file?= The log4j 2 > configuration file? Why would you set the log sell to null before reload= ed > the configuration? > >>>> > >>>> =E2=80=9CWithout losing any appenders created with Java=E2=80=9D - H= ow are the > appenders created with Java and why are they created with Java? You could > use a composite configuration that adds your the =E2=80=9Cstandard=E2=80= =9D configuration > to what a user provides or you could extend XMLConfiguratoin with your ow= n > extra configuration. > >>>> > >>>> In short, you still haven=E2=80=99t described what you want the resu= ltant > behavior to be. You are still describing =E2=80=9CHow?=E2=80=9D instead o= f =E2=80=9CWhat?=E2=80=9D. In > other words - something like - =E2=80=9CWe want to require that a specifi= c logger > is always logged at error and those logs are always routed to a file name= d > xxxx, regardless of what other things the user might configure=E2=80=9D. > >>>> > >>>> Ralph > >>>> > >>>>> On Dec 17, 2017, at 11:22 AM, Paladox yahoo.com.INVALID >> wrote: > >>>>> > >>>>> Im trying to migrate gerrit from log4j1 to log4j2. > >>>>> With this we have a ssh command that resets log levels (ie sets the > log level to null then loads the Property file without restarting from > fresh and loosing any appenders that were created with java). > >>>>> On Sunday, 17 December 2017, 17:56:42 GMT, Ralph Goers < > ralph.goers@dslextreme.com ralph.goers@dslextreme.com >> wrote: > >>>>> > >>>>> Why are you trying to do this? What problem are you trying to solve= ? > Simply trying to port code from Log4j 1 to Log4j 2 without evaluating wha= t > the best way is to achieve the desired results is not an approach I > recommend. > >>>>> > >>>>> Ralph > >>>>> > >>>>>> On Dec 16, 2017, at 1:18 PM, Paladox yahoo.com.INVALID >> wrote: > >>>>>> > >>>>>> Would like to add more to this question. > >>>>>> Im wondering is it possible to also reset log levels? > >>>>>> In log4j1.x we did > >>>>>> private static void reset() throws MalformedURLException { for > (Enumeration logger =3D LogManager.getCurrentLoggers(); > logger.hasMoreElements(); ) { logger.nextElement().setLevel(null); > } > >>>>>> String path =3D System.getProperty(JAVA_OPTIONS_LOG_CONFIG); > if (Strings.isNullOrEmpty(path)) { PropertyConfigurator. > configure(Loader.getResource(LOG_CONFIGURATION)); } else { > PropertyConfigurator.configure(new URL(path)); } } > >>>>>> in log4j2 i carn't find any good replacements. Setting setLevel > results in null pointer same would be for setAllLevels. (Works in log4j1)= . > >>>>>> Then when i try to reload the properties file it just resets > everything then loads the file. Thus if you used some java code it would = be > lost and you would have to restart your java application to get the > appenders or anything added with java code. > >>>>>> In log4j1 you need PropertyConfigurator.configure which re added > the log levels that were from the file without resetting anything. > >>>>>> On Friday, 15 December 2017, 16:50:28 GMT, Paladox < > thomasmulhall410@yahoo.com.INVALID yahoo.com.INVALID> thomasmulhall410@yahoo.com.INVALID>>> wrote: > >>>>>> > >>>>>> Hi, im wondering if i could have some help with migrating from > log4j1 to log4j2 please? > >>>>>> Im trying to update gerrit to log4j2 but am stuck on some things. > [1] > >>>>>> 1. How do i migrate from PropertyConfigurator. > configure(Loader.getResource(LOG_CONFIGURATION)); to something log4j2 > compatible please? > >>>>>> Im trying to migrate all the way without trying to use log4j1 > compatible api log4j2. (Though im still pulling it in i am trying not to > use it). > >>>>>> I found doing something like > >>>>>> String path =3D System.getProperty(JAVA_OPTIONS_LOG_CONFIG); > if (Strings.isNullOrEmpty(path)) { ConfigurationSource source =3D > ConfigurationSource.fromResource(LOG_CONFIGURATION, null); > Configurator.initialize(null, source); } else { URL in =3D new > URL(path); Configurator.initialize((String) null, null, > in.toURI()); } > >>>>>> could work but then it wont reload the configuation without > restarting the configuation as new (ie gets rid of everything). which > .reconfigure() does. > >>>>>> Im trying to reset log levels to null so that we can reload the > configuation but reconfigure gets rid of everything thus causing problems > if you used java to add appenders or anything else. see [2] > >>>>>> Also how would i migrate from using removeAllAppenders to log4j2 > compatible code please? > >>>>>> [1] https://gerrit-review.googlesource.com/#/c/gerrit/+/142811/ < > https://gerrit-review.googlesource.com/#/c/gerrit/+/142811/>< > https://gerrit-review.googlesource.com/#/c/gerrit/+/142811/ < > https://gerrit-review.googlesource.com/#/c/gerrit/+/142811/>> > >>>>>> [2] https://gerrit-review.googlesource.com/#/c/gerrit/+/ > 142811/46/java/com/google/gerrit/sshd/commands/SetLoggingLevelCommand.jav= a > 142811/46/java/com/google/gerrit/sshd/commands/SetLoggingLevelCommand.jav= a > > 142811/46/java/com/google/gerrit/sshd/commands/SetLoggingLevelCommand.jav= a > 142811/46/java/com/google/gerrit/sshd/commands/SetLoggingLevelCommand.jav= a > >> > >>>>> > >>>>> > >>>>> > >>>>> ------------------------------------------------------------ > --------- > >>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org > unsubscribe@logging.apache.org unsubscribe@logging.apache.org>> > >>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org > logging.apache.org > > >>>> > >>>> > >>>> > >>>> > >>>> --------------------------------------------------------------------= - > >>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org > unsubscribe@logging.apache.org unsubscribe@logging.apache.org>> > >>>> For additional commands, e-mail: log4j-user-help@logging.apache.org > logging.apache.org > > > --=20 Matt Sicker --001a11444d0edf3da60560c84015--