You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by ~Abhi$hek~ <bo...@gmail.com> on 2014/01/30 06:33:42 UTC
Migrating from log4j 1.2 to log4j 2
Hello Log4j 2 experts,
I am in the process of migrating my application from log4j 1.2 to log4j 2.0
I have existing code:
Enumeration appenders = logger.getAllAppenders();
.
.
.
fileBackupIndex = rollingFileAppender.getMaxBackupIndex();
maxFileSize = rollingFileAppender.getMaximumFileSize();
In log4j 2.0 I could not find way to replace above java code. How to get
list of all appenders and how to get the max value defined for RollingFile
appender programmatically?
Regards,
Abhishek
Re: Migrating from log4j 1.2 to log4j 2
Posted by Ralph Goers <ra...@dslextreme.com>.
As it should be. They are very much subject to the internal workings of Log4j core and have nothing to do with the end user API.
FWIW - here is the code you need.
org.apache.log4j.coreLoggerContext ctx = (org.apache.log4j.core.LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
ListAppender listApp;
for (final Map.Entry<String, Appender> entry : config.getAppenders().entrySet()) {
if (entry.getKey().equals("List")) {
listApp = (ListAppender) entry.getValue();
}
}
On Jan 31, 2014, at 9:01 AM, Gary Gregory <ga...@gmail.com> wrote:
> Another item of note is that Appender is in the Core, not the public API.
>
> Gary
>
>
> On Thu, Jan 30, 2014 at 9:54 PM, Remko Popma <re...@gmail.com> wrote:
>
>> Away from PC now, but if I remember correctly, that method is now commented
>> as "only used by Junit tests". That may be the most convenient method to
>> use. We may want to change that comment though...
>>
>>
>> On Friday, January 31, 2014, Gary Gregory
>> <garydgregory@gmail.com<javascript:_e(%7B%7D,'cvml','
>> garydgregory@gmail.com');>>
>> wrote:
>>
>>> I have finally created a separate sandbox for our app server to test
>>> porting from log4j1 to 2.
>>>
>>> The first thing I run into? Just this issue! ;)
>>>
>>> We have code like this:
>>>
>>> Logger.getRootLogger().getAllAppenders()
>>>
>>> Why? Because the server looks for the log file (if any) so that it can
>>> return its tail to our client side admin console.
>>>
>>> I do not care if the functionality is part of the API, as long as it is
>> in
>>> the Core. We have custom appenders so we are tied to Log4j (version 1
>> ATM).
>>>
>>> So what's a clean way to get this? I see:
>>>
>>> - API: org.apache.logging.log4j.LogManager.getContext() but
>>> org.apache.logging.log4j.spi.LoggerContext does not surface appenders.
>>> - Core: org.apache.logging.log4j.core.Logger.getAppenders()
>>>
>>> So I think I have a solution:
>>>
>>> Map<String, Appender> appenders = ((org.apache.logging.log4j.core.Logger)
>>> LogManager.getRootLogger()).getAppenders();
>>>
>>> Where LogManager is in org.apache.logging.log4j.
>>>
>>> Gary
>>>
>>>
>>> On Thu, Jan 30, 2014 at 4:23 PM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> Hi Abhishek,
>>>>
>>>> These are currently private fields and not easily accessible.
>>>> Can you explain your use case? Why do you need this?
>>>>
>>>> Best regards,
>>>> Remko
>>>>
>>>>
>>>> On Thu, Jan 30, 2014 at 2:33 PM, ~Abhi$hek~ <bo...@gmail.com>
>> wrote:
>>>>
>>>>> Hello Log4j 2 experts,
>>>>>
>>>>>
>>>>>
>>>>> I am in the process of migrating my application from log4j 1.2 to
>> log4j
>>>> 2.0
>>>>>
>>>>> I have existing code:
>>>>>
>>>>> Enumeration appenders = logger.getAllAppenders();
>>>>>
>>>>> .
>>>>>
>>>>> .
>>>>>
>>>>> .
>>>>>
>>>>> fileBackupIndex = rollingFileAppender.getMaxBackupIndex();
>>>>>
>>>>> maxFileSize = rollingFileAppender.getMaximumFileSize();
>>>>>
>>>>>
>>>>>
>>>>> In log4j 2.0 I could not find way to replace above java code. How to
>>> get
>>>>> list of all appenders and how to get the max value defined for
>>>> RollingFile
>>>>> appender programmatically?
>>>>>
>>>>> Regards,
>>>>> Abhishek
>>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition<
>>> http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Migrating from log4j 1.2 to log4j 2
Posted by Gary Gregory <ga...@gmail.com>.
Another item of note is that Appender is in the Core, not the public API.
Gary
On Thu, Jan 30, 2014 at 9:54 PM, Remko Popma <re...@gmail.com> wrote:
> Away from PC now, but if I remember correctly, that method is now commented
> as "only used by Junit tests". That may be the most convenient method to
> use. We may want to change that comment though...
>
>
> On Friday, January 31, 2014, Gary Gregory
> <garydgregory@gmail.com<javascript:_e(%7B%7D,'cvml','
> garydgregory@gmail.com');>>
> wrote:
>
> > I have finally created a separate sandbox for our app server to test
> > porting from log4j1 to 2.
> >
> > The first thing I run into? Just this issue! ;)
> >
> > We have code like this:
> >
> > Logger.getRootLogger().getAllAppenders()
> >
> > Why? Because the server looks for the log file (if any) so that it can
> > return its tail to our client side admin console.
> >
> > I do not care if the functionality is part of the API, as long as it is
> in
> > the Core. We have custom appenders so we are tied to Log4j (version 1
> ATM).
> >
> > So what's a clean way to get this? I see:
> >
> > - API: org.apache.logging.log4j.LogManager.getContext() but
> > org.apache.logging.log4j.spi.LoggerContext does not surface appenders.
> > - Core: org.apache.logging.log4j.core.Logger.getAppenders()
> >
> > So I think I have a solution:
> >
> > Map<String, Appender> appenders = ((org.apache.logging.log4j.core.Logger)
> > LogManager.getRootLogger()).getAppenders();
> >
> > Where LogManager is in org.apache.logging.log4j.
> >
> > Gary
> >
> >
> > On Thu, Jan 30, 2014 at 4:23 PM, Remko Popma <re...@gmail.com>
> > wrote:
> >
> > > Hi Abhishek,
> > >
> > > These are currently private fields and not easily accessible.
> > > Can you explain your use case? Why do you need this?
> > >
> > > Best regards,
> > > Remko
> > >
> > >
> > > On Thu, Jan 30, 2014 at 2:33 PM, ~Abhi$hek~ <bo...@gmail.com>
> wrote:
> > >
> > > > Hello Log4j 2 experts,
> > > >
> > > >
> > > >
> > > > I am in the process of migrating my application from log4j 1.2 to
> log4j
> > > 2.0
> > > >
> > > > I have existing code:
> > > >
> > > > Enumeration appenders = logger.getAllAppenders();
> > > >
> > > > .
> > > >
> > > > .
> > > >
> > > > .
> > > >
> > > > fileBackupIndex = rollingFileAppender.getMaxBackupIndex();
> > > >
> > > > maxFileSize = rollingFileAppender.getMaximumFileSize();
> > > >
> > > >
> > > >
> > > > In log4j 2.0 I could not find way to replace above java code. How to
> > get
> > > > list of all appenders and how to get the max value defined for
> > > RollingFile
> > > > appender programmatically?
> > > >
> > > > Regards,
> > > > Abhishek
> > > >
> > >
> >
> >
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition<
> > http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
> >
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Migrating from log4j 1.2 to log4j 2
Posted by Remko Popma <re...@gmail.com>.
Away from PC now, but if I remember correctly, that method is now commented
as "only used by Junit tests". That may be the most convenient method to
use. We may want to change that comment though...
On Friday, January 31, 2014, Gary Gregory
<garydgregory@gmail.com<javascript:_e(%7B%7D,'cvml','garydgregory@gmail.com');>>
wrote:
> I have finally created a separate sandbox for our app server to test
> porting from log4j1 to 2.
>
> The first thing I run into? Just this issue! ;)
>
> We have code like this:
>
> Logger.getRootLogger().getAllAppenders()
>
> Why? Because the server looks for the log file (if any) so that it can
> return its tail to our client side admin console.
>
> I do not care if the functionality is part of the API, as long as it is in
> the Core. We have custom appenders so we are tied to Log4j (version 1 ATM).
>
> So what's a clean way to get this? I see:
>
> - API: org.apache.logging.log4j.LogManager.getContext() but
> org.apache.logging.log4j.spi.LoggerContext does not surface appenders.
> - Core: org.apache.logging.log4j.core.Logger.getAppenders()
>
> So I think I have a solution:
>
> Map<String, Appender> appenders = ((org.apache.logging.log4j.core.Logger)
> LogManager.getRootLogger()).getAppenders();
>
> Where LogManager is in org.apache.logging.log4j.
>
> Gary
>
>
> On Thu, Jan 30, 2014 at 4:23 PM, Remko Popma <re...@gmail.com>
> wrote:
>
> > Hi Abhishek,
> >
> > These are currently private fields and not easily accessible.
> > Can you explain your use case? Why do you need this?
> >
> > Best regards,
> > Remko
> >
> >
> > On Thu, Jan 30, 2014 at 2:33 PM, ~Abhi$hek~ <bo...@gmail.com> wrote:
> >
> > > Hello Log4j 2 experts,
> > >
> > >
> > >
> > > I am in the process of migrating my application from log4j 1.2 to log4j
> > 2.0
> > >
> > > I have existing code:
> > >
> > > Enumeration appenders = logger.getAllAppenders();
> > >
> > > .
> > >
> > > .
> > >
> > > .
> > >
> > > fileBackupIndex = rollingFileAppender.getMaxBackupIndex();
> > >
> > > maxFileSize = rollingFileAppender.getMaximumFileSize();
> > >
> > >
> > >
> > > In log4j 2.0 I could not find way to replace above java code. How to
> get
> > > list of all appenders and how to get the max value defined for
> > RollingFile
> > > appender programmatically?
> > >
> > > Regards,
> > > Abhishek
> > >
> >
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<
> http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
Re: Migrating from log4j 1.2 to log4j 2
Posted by Ralph Goers <ra...@dslextreme.com>.
Gary, there are tons of unit tests that get the appenders. You have to get the Configuration from the loggerContext. That is where the Appenders are, not on the Loggers.
Ralph
On Jan 30, 2014, at 6:23 PM, Gary Gregory <ga...@gmail.com> wrote:
> I have finally created a separate sandbox for our app server to test
> porting from log4j1 to 2.
>
> The first thing I run into? Just this issue! ;)
>
> We have code like this:
>
> Logger.getRootLogger().getAllAppenders()
>
> Why? Because the server looks for the log file (if any) so that it can
> return its tail to our client side admin console.
>
> I do not care if the functionality is part of the API, as long as it is in
> the Core. We have custom appenders so we are tied to Log4j (version 1 ATM).
>
> So what's a clean way to get this? I see:
>
> - API: org.apache.logging.log4j.LogManager.getContext() but
> org.apache.logging.log4j.spi.LoggerContext does not surface appenders.
> - Core: org.apache.logging.log4j.core.Logger.getAppenders()
>
> So I think I have a solution:
>
> Map<String, Appender> appenders = ((org.apache.logging.log4j.core.Logger)
> LogManager.getRootLogger()).getAppenders();
>
> Where LogManager is in org.apache.logging.log4j.
>
> Gary
>
>
> On Thu, Jan 30, 2014 at 4:23 PM, Remko Popma <re...@gmail.com> wrote:
>
>> Hi Abhishek,
>>
>> These are currently private fields and not easily accessible.
>> Can you explain your use case? Why do you need this?
>>
>> Best regards,
>> Remko
>>
>>
>> On Thu, Jan 30, 2014 at 2:33 PM, ~Abhi$hek~ <bo...@gmail.com> wrote:
>>
>>> Hello Log4j 2 experts,
>>>
>>>
>>>
>>> I am in the process of migrating my application from log4j 1.2 to log4j
>> 2.0
>>>
>>> I have existing code:
>>>
>>> Enumeration appenders = logger.getAllAppenders();
>>>
>>> .
>>>
>>> .
>>>
>>> .
>>>
>>> fileBackupIndex = rollingFileAppender.getMaxBackupIndex();
>>>
>>> maxFileSize = rollingFileAppender.getMaximumFileSize();
>>>
>>>
>>>
>>> In log4j 2.0 I could not find way to replace above java code. How to get
>>> list of all appenders and how to get the max value defined for
>> RollingFile
>>> appender programmatically?
>>>
>>> Regards,
>>> Abhishek
>>>
>>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Migrating from log4j 1.2 to log4j 2
Posted by Gary Gregory <ga...@gmail.com>.
I have finally created a separate sandbox for our app server to test
porting from log4j1 to 2.
The first thing I run into? Just this issue! ;)
We have code like this:
Logger.getRootLogger().getAllAppenders()
Why? Because the server looks for the log file (if any) so that it can
return its tail to our client side admin console.
I do not care if the functionality is part of the API, as long as it is in
the Core. We have custom appenders so we are tied to Log4j (version 1 ATM).
So what's a clean way to get this? I see:
- API: org.apache.logging.log4j.LogManager.getContext() but
org.apache.logging.log4j.spi.LoggerContext does not surface appenders.
- Core: org.apache.logging.log4j.core.Logger.getAppenders()
So I think I have a solution:
Map<String, Appender> appenders = ((org.apache.logging.log4j.core.Logger)
LogManager.getRootLogger()).getAppenders();
Where LogManager is in org.apache.logging.log4j.
Gary
On Thu, Jan 30, 2014 at 4:23 PM, Remko Popma <re...@gmail.com> wrote:
> Hi Abhishek,
>
> These are currently private fields and not easily accessible.
> Can you explain your use case? Why do you need this?
>
> Best regards,
> Remko
>
>
> On Thu, Jan 30, 2014 at 2:33 PM, ~Abhi$hek~ <bo...@gmail.com> wrote:
>
> > Hello Log4j 2 experts,
> >
> >
> >
> > I am in the process of migrating my application from log4j 1.2 to log4j
> 2.0
> >
> > I have existing code:
> >
> > Enumeration appenders = logger.getAllAppenders();
> >
> > .
> >
> > .
> >
> > .
> >
> > fileBackupIndex = rollingFileAppender.getMaxBackupIndex();
> >
> > maxFileSize = rollingFileAppender.getMaximumFileSize();
> >
> >
> >
> > In log4j 2.0 I could not find way to replace above java code. How to get
> > list of all appenders and how to get the max value defined for
> RollingFile
> > appender programmatically?
> >
> > Regards,
> > Abhishek
> >
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: Migrating from log4j 1.2 to log4j 2
Posted by Remko Popma <re...@gmail.com>.
Hi Abhishek,
These are currently private fields and not easily accessible.
Can you explain your use case? Why do you need this?
Best regards,
Remko
On Thu, Jan 30, 2014 at 2:33 PM, ~Abhi$hek~ <bo...@gmail.com> wrote:
> Hello Log4j 2 experts,
>
>
>
> I am in the process of migrating my application from log4j 1.2 to log4j 2.0
>
> I have existing code:
>
> Enumeration appenders = logger.getAllAppenders();
>
> .
>
> .
>
> .
>
> fileBackupIndex = rollingFileAppender.getMaxBackupIndex();
>
> maxFileSize = rollingFileAppender.getMaximumFileSize();
>
>
>
> In log4j 2.0 I could not find way to replace above java code. How to get
> list of all appenders and how to get the max value defined for RollingFile
> appender programmatically?
>
> Regards,
> Abhishek
>