getAppender

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

getAppender

EDMONDO SENA
how to getAppender from logger? we have a lot of code to get the appender
in the project: logger.getAppender(appenderName). I read the api for the
log4j2, I couldn't find any.

How can I fix it?

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getAppender

Matt Sicker
Appenders and such are part of the core library now. There are likely
features in log4j2 that could replace what you’re doing, though. In any
case, there’s plenty of examples of how that is done in the tests.

On Wed, Feb 19, 2020 at 04:23 EDMONDO SENA <[hidden email]> wrote:

> how to getAppender from logger? we have a lot of code to get the appender
> in the project: logger.getAppender(appenderName). I read the api for the
> log4j2, I couldn't find any.
>
> How can I fix it?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
> --
Matt Sicker <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: getAppender

EDMONDO SENA

Can you tell me where can I find out these examples?

Kind regards.
//Edmondo.


On 2020/02/19 14:09:52, Matt Sicker <[hidden email]> wrote:

> Appenders and such are part of the core library now. There are likely
> features in log4j2 that could replace what you’re doing, though. In any
> case, there’s plenty of examples of how that is done in the tests.
>
> On Wed, Feb 19, 2020 at 04:23 EDMONDO SENA <[hidden email]> wrote:
>
> > how to getAppender from logger? we have a lot of code to get the appender
> > in the project: logger.getAppender(appenderName). I read the api for the
> > log4j2, I couldn't find any.
> >
> > How can I fix it?
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> > --
> Matt Sicker <[hidden email]>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getAppender

Gary Gregory-4
Please see
https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/config/Configuration.html#getAppender-java.lang.String-

On Wed, Feb 19, 2020, 09:27 EDMONDO SENA <[hidden email]> wrote:

>
> Can you tell me where can I find out these examples?
>
> Kind regards.
> //Edmondo.
>
>
> On 2020/02/19 14:09:52, Matt Sicker <[hidden email]> wrote:
> > Appenders and such are part of the core library now. There are likely
> > features in log4j2 that could replace what you’re doing, though. In any
> > case, there’s plenty of examples of how that is done in the tests.
> >
> > On Wed, Feb 19, 2020 at 04:23 EDMONDO SENA <[hidden email]> wrote:
> >
> > > how to getAppender from logger? we have a lot of code to get the
> appender
> > > in the project: logger.getAppender(appenderName). I read the api for
> the
> > > log4j2, I couldn't find any.
> > >
> > > How can I fix it?
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > > --
> > Matt Sicker <[hidden email]>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: getAppender

EDMONDO SENA
Ok, but they are the API not examples....




On 2020/02/19 14:29:41, Gary Gregory <[hidden email]> wrote:

> Please see
> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/config/Configuration.html#getAppender-java.lang.String-
>
> On Wed, Feb 19, 2020, 09:27 EDMONDO SENA <[hidden email]> wrote:
>
> >
> > Can you tell me where can I find out these examples?
> >
> > Kind regards.
> > //Edmondo.
> >
> >
> > On 2020/02/19 14:09:52, Matt Sicker <[hidden email]> wrote:
> > > Appenders and such are part of the core library now. There are likely
> > > features in log4j2 that could replace what you’re doing, though. In any
> > > case, there’s plenty of examples of how that is done in the tests.
> > >
> > > On Wed, Feb 19, 2020 at 04:23 EDMONDO SENA <[hidden email]> wrote:
> > >
> > > > how to getAppender from logger? we have a lot of code to get the
> > appender
> > > > in the project: logger.getAppender(appenderName). I read the api for
> > the
> > > > log4j2, I couldn't find any.
> > > >
> > > > How can I fix it?
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email]
> > > > For additional commands, e-mail: [hidden email]
> > > >
> > > > --
> > > Matt Sicker <[hidden email]>
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getAppender

Ralph Goers
LoggerContext context = LogManager.getContext(“false”);
FileAppender appender = context.getConfiguration().getAppender("info");

Ralph


> On Feb 19, 2020, at 7:47 AM, EDMONDO SENA <[hidden email]> wrote:
>
> Ok, but they are the API not examples....
>
>
>
>
> On 2020/02/19 14:29:41, Gary Gregory <[hidden email]> wrote:
>> Please see
>> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/config/Configuration.html#getAppender-java.lang.String-
>>
>> On Wed, Feb 19, 2020, 09:27 EDMONDO SENA <[hidden email]> wrote:
>>
>>>
>>> Can you tell me where can I find out these examples?
>>>
>>> Kind regards.
>>> //Edmondo.
>>>
>>>
>>> On 2020/02/19 14:09:52, Matt Sicker <[hidden email]> wrote:
>>>> Appenders and such are part of the core library now. There are likely
>>>> features in log4j2 that could replace what you’re doing, though. In any
>>>> case, there’s plenty of examples of how that is done in the tests.
>>>>
>>>> On Wed, Feb 19, 2020 at 04:23 EDMONDO SENA <[hidden email]> wrote:
>>>>
>>>>> how to getAppender from logger? we have a lot of code to get the
>>> appender
>>>>> in the project: logger.getAppender(appenderName). I read the api for
>>> the
>>>>> log4j2, I couldn't find any.
>>>>>
>>>>> How can I fix it?
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>>> --
>>>> Matt Sicker <[hidden email]>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

Reply | Threaded
Open this post in threaded view
|

Re: getAppender

EDMONDO SENA
Hi Ralph,

The example below that you mentioned I've got  null.
Is right the casting to LoggerContext?

LoggerContext context = (LoggerContext) LogManager.getContext(false);
FileAppender appender = context.getConfiguration().getAppender("LoggerLog4jDebug");
System.out.println("appender = " + appender);

Can you help me?
//Edmondo.



On 2020/02/19 15:31:53, Ralph Goers <[hidden email]> wrote:

> LoggerContext context = LogManager.getContext(“false”);
> FileAppender appender = context.getConfiguration().getAppender("info");
>
> Ralph
>
>
> > On Feb 19, 2020, at 7:47 AM, EDMONDO SENA <[hidden email]> wrote:
> >
> > Ok, but they are the API not examples....
> >
> >
> >
> >
> > On 2020/02/19 14:29:41, Gary Gregory <[hidden email]> wrote:
> >> Please see
> >> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/config/Configuration.html#getAppender-java.lang.String-
> >>
> >> On Wed, Feb 19, 2020, 09:27 EDMONDO SENA <[hidden email]> wrote:
> >>
> >>>
> >>> Can you tell me where can I find out these examples?
> >>>
> >>> Kind regards.
> >>> //Edmondo.
> >>>
> >>>
> >>> On 2020/02/19 14:09:52, Matt Sicker <[hidden email]> wrote:
> >>>> Appenders and such are part of the core library now. There are likely
> >>>> features in log4j2 that could replace what you’re doing, though. In any
> >>>> case, there’s plenty of examples of how that is done in the tests.
> >>>>
> >>>> On Wed, Feb 19, 2020 at 04:23 EDMONDO SENA <[hidden email]> wrote:
> >>>>
> >>>>> how to getAppender from logger? we have a lot of code to get the
> >>> appender
> >>>>> in the project: logger.getAppender(appenderName). I read the api for
> >>> the
> >>>>> log4j2, I couldn't find any.
> >>>>>
> >>>>> How can I fix it?
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: [hidden email]
> >>>>> For additional commands, e-mail: [hidden email]
> >>>>>
> >>>>> --
> >>>> Matt Sicker <[hidden email]>
> >>>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: [hidden email]
> >>> For additional commands, e-mail: [hidden email]
> >>>
> >>>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getAppender

Ralph Goers
If it compiles than your casting is correct.

Ralph

> On Mar 19, 2020, at 5:41 AM, EDMONDO SENA <[hidden email]> wrote:
>
> Hi Ralph,
>
> The example below that you mentioned I've got  null.
> Is right the casting to LoggerContext?
>
> LoggerContext context = (LoggerContext) LogManager.getContext(false);
> FileAppender appender = context.getConfiguration().getAppender("LoggerLog4jDebug");
> System.out.println("appender = " + appender);
>
> Can you help me?
> //Edmondo.
>
>
>
> On 2020/02/19 15:31:53, Ralph Goers <[hidden email]> wrote:
>> LoggerContext context = LogManager.getContext(“false”);
>> FileAppender appender = context.getConfiguration().getAppender("info");
>>
>> Ralph
>>
>>
>>> On Feb 19, 2020, at 7:47 AM, EDMONDO SENA <[hidden email]> wrote:
>>>
>>> Ok, but they are the API not examples....
>>>
>>>
>>>
>>>
>>> On 2020/02/19 14:29:41, Gary Gregory <[hidden email]> wrote:
>>>> Please see
>>>> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/config/Configuration.html#getAppender-java.lang.String-
>>>>
>>>> On Wed, Feb 19, 2020, 09:27 EDMONDO SENA <[hidden email]> wrote:
>>>>
>>>>>
>>>>> Can you tell me where can I find out these examples?
>>>>>
>>>>> Kind regards.
>>>>> //Edmondo.
>>>>>
>>>>>
>>>>> On 2020/02/19 14:09:52, Matt Sicker <[hidden email]> wrote:
>>>>>> Appenders and such are part of the core library now. There are likely
>>>>>> features in log4j2 that could replace what you’re doing, though. In any
>>>>>> case, there’s plenty of examples of how that is done in the tests.
>>>>>>
>>>>>> On Wed, Feb 19, 2020 at 04:23 EDMONDO SENA <[hidden email]> wrote:
>>>>>>
>>>>>>> how to getAppender from logger? we have a lot of code to get the
>>>>> appender
>>>>>>> in the project: logger.getAppender(appenderName). I read the api for
>>>>> the
>>>>>>> log4j2, I couldn't find any.
>>>>>>>
>>>>>>> How can I fix it?
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>>
>>>>>>> --
>>>>>> Matt Sicker <[hidden email]>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getAppender

EDMONDO SENA
But null is the output .......


On 2020/03/19 15:09:56, Ralph Goers <[hidden email]> wrote:

> If it compiles than your casting is correct.
>
> Ralph
>
> > On Mar 19, 2020, at 5:41 AM, EDMONDO SENA <[hidden email]> wrote:
> >
> > Hi Ralph,
> >
> > The example below that you mentioned I've got  null.
> > Is right the casting to LoggerContext?
> >
> > LoggerContext context = (LoggerContext) LogManager.getContext(false);
> > FileAppender appender = context.getConfiguration().getAppender("LoggerLog4jDebug");
> > System.out.println("appender = " + appender);
> >
> > Can you help me?
> > //Edmondo.
> >
> >
> >
> > On 2020/02/19 15:31:53, Ralph Goers <[hidden email]> wrote:
> >> LoggerContext context = LogManager.getContext(“false”);
> >> FileAppender appender = context.getConfiguration().getAppender("info");
> >>
> >> Ralph
> >>
> >>
> >>> On Feb 19, 2020, at 7:47 AM, EDMONDO SENA <[hidden email]> wrote:
> >>>
> >>> Ok, but they are the API not examples....
> >>>
> >>>
> >>>
> >>>
> >>> On 2020/02/19 14:29:41, Gary Gregory <[hidden email]> wrote:
> >>>> Please see
> >>>> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/config/Configuration.html#getAppender-java.lang.String-
> >>>>
> >>>> On Wed, Feb 19, 2020, 09:27 EDMONDO SENA <[hidden email]> wrote:
> >>>>
> >>>>>
> >>>>> Can you tell me where can I find out these examples?
> >>>>>
> >>>>> Kind regards.
> >>>>> //Edmondo.
> >>>>>
> >>>>>
> >>>>> On 2020/02/19 14:09:52, Matt Sicker <[hidden email]> wrote:
> >>>>>> Appenders and such are part of the core library now. There are likely
> >>>>>> features in log4j2 that could replace what you’re doing, though. In any
> >>>>>> case, there’s plenty of examples of how that is done in the tests.
> >>>>>>
> >>>>>> On Wed, Feb 19, 2020 at 04:23 EDMONDO SENA <[hidden email]> wrote:
> >>>>>>
> >>>>>>> how to getAppender from logger? we have a lot of code to get the
> >>>>> appender
> >>>>>>> in the project: logger.getAppender(appenderName). I read the api for
> >>>>> the
> >>>>>>> log4j2, I couldn't find any.
> >>>>>>>
> >>>>>>> How can I fix it?
> >>>>>>>
> >>>>>>> ---------------------------------------------------------------------
> >>>>>>> To unsubscribe, e-mail: [hidden email]
> >>>>>>> For additional commands, e-mail: [hidden email]
> >>>>>>>
> >>>>>>> --
> >>>>>> Matt Sicker <[hidden email]>
> >>>>>>
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: [hidden email]
> >>>>> For additional commands, e-mail: [hidden email]
> >>>>>
> >>>>>
> >>>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: [hidden email]
> >>> For additional commands, e-mail: [hidden email]
> >>>
> >>>
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getAppender

Ralph Goers
Then it didn’t find an appender with that name in the configuration.

Ralph

> On Mar 19, 2020, at 8:13 AM, EDMONDO SENA <[hidden email]> wrote:
>
> But null is the output .......
>
>
> On 2020/03/19 15:09:56, Ralph Goers <[hidden email]> wrote:
>> If it compiles than your casting is correct.
>>
>> Ralph
>>
>>> On Mar 19, 2020, at 5:41 AM, EDMONDO SENA <[hidden email]> wrote:
>>>
>>> Hi Ralph,
>>>
>>> The example below that you mentioned I've got  null.
>>> Is right the casting to LoggerContext?
>>>
>>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>>> FileAppender appender = context.getConfiguration().getAppender("LoggerLog4jDebug");
>>> System.out.println("appender = " + appender);
>>>
>>> Can you help me?
>>> //Edmondo.
>>>
>>>
>>>
>>> On 2020/02/19 15:31:53, Ralph Goers <[hidden email]> wrote:
>>>> LoggerContext context = LogManager.getContext(“false”);
>>>> FileAppender appender = context.getConfiguration().getAppender("info");
>>>>
>>>> Ralph
>>>>
>>>>
>>>>> On Feb 19, 2020, at 7:47 AM, EDMONDO SENA <[hidden email]> wrote:
>>>>>
>>>>> Ok, but they are the API not examples....
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 2020/02/19 14:29:41, Gary Gregory <[hidden email]> wrote:
>>>>>> Please see
>>>>>> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/config/Configuration.html#getAppender-java.lang.String-
>>>>>>
>>>>>> On Wed, Feb 19, 2020, 09:27 EDMONDO SENA <[hidden email]> wrote:
>>>>>>
>>>>>>>
>>>>>>> Can you tell me where can I find out these examples?
>>>>>>>
>>>>>>> Kind regards.
>>>>>>> //Edmondo.
>>>>>>>
>>>>>>>
>>>>>>> On 2020/02/19 14:09:52, Matt Sicker <[hidden email]> wrote:
>>>>>>>> Appenders and such are part of the core library now. There are likely
>>>>>>>> features in log4j2 that could replace what you’re doing, though. In any
>>>>>>>> case, there’s plenty of examples of how that is done in the tests.
>>>>>>>>
>>>>>>>> On Wed, Feb 19, 2020 at 04:23 EDMONDO SENA <[hidden email]> wrote:
>>>>>>>>
>>>>>>>>> how to getAppender from logger? we have a lot of code to get the
>>>>>>> appender
>>>>>>>>> in the project: logger.getAppender(appenderName). I read the api for
>>>>>>> the
>>>>>>>>> log4j2, I couldn't find any.
>>>>>>>>>
>>>>>>>>> How can I fix it?
>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>>>>
>>>>>>>>> --
>>>>>>>> Matt Sicker <[hidden email]>
>>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getAppender

EDMONDO SENA
The code is:
try {
                        ConfigurationSource source = new ConfigurationSource(new
                     FileInputStream("Log4jApache.xml"));
                        Configurator.initialize(null, source);
                    } catch (IOException e) {
                        System.err.println("Error while initializing log4j from file: log4j.xml");
                        e.printStackTrace();
                    }

LoggerContext context = (LoggerContext) LogManager.getContext(false);
Appender appender = context.getConfiguration().getAppender("LoggerLog4jDebug");
System.out.println("appender = " + appender);

File xml is:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR">
    <Appenders>
        <Console name="LoggerLog4jDebugAppender" target="SYSTEM_OUT">
            <PatternLayout pattern="log4j: %msg%n"/>
        </Console>
        <Console name="LoggerLog4jErrorAppender" target="SYSTEM_ERR">
            <PatternLayout pattern="log4j: %msg%n"/>
        </Console>        
    </Appenders>
    <Loggers>
    <Logger name="LoggerLog4jDebug" level="debug" additivity="false">
    <AppenderRef ref="LoggerLog4jDebugAppender"/>
    </Logger>
    <Logger name="LoggerLog4jError" level="error" additivity="false">
    <AppenderRef ref="LoggerLog4jErrorAppender"/>
    </Logger>    
    </Loggers>
   
  <Appenders>
    <Console name="STDOUT">
      <PatternLayout pattern="%d %-5level [%logger] %msg%n%xThrowable" />
    </Console>
  </Appenders>
  <Loggers>
    <Logger name="org.apache.http.headers" level="DEBUG">
      <AppenderRef ref="STDOUT"/>
    </Logger>
    <!-- Root level="DEBUG">
      <AppenderRef ref="STDOUT" />
    </Root-->
  </Loggers>
</Configuration>

On 2020/03/19 15:15:39, Ralph Goers <[hidden email]> wrote:

> Then it didn’t find an appender with that name in the configuration.
>
> Ralph
>
> > On Mar 19, 2020, at 8:13 AM, EDMONDO SENA <[hidden email]> wrote:
> >
> > But null is the output .......
> >
> >
> > On 2020/03/19 15:09:56, Ralph Goers <[hidden email]> wrote:
> >> If it compiles than your casting is correct.
> >>
> >> Ralph
> >>
> >>> On Mar 19, 2020, at 5:41 AM, EDMONDO SENA <[hidden email]> wrote:
> >>>
> >>> Hi Ralph,
> >>>
> >>> The example below that you mentioned I've got  null.
> >>> Is right the casting to LoggerContext?
> >>>
> >>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
> >>> FileAppender appender = context.getConfiguration().getAppender("LoggerLog4jDebug");
> >>> System.out.println("appender = " + appender);
> >>>
> >>> Can you help me?
> >>> //Edmondo.
> >>>
> >>>
> >>>
> >>> On 2020/02/19 15:31:53, Ralph Goers <[hidden email]> wrote:
> >>>> LoggerContext context = LogManager.getContext(“false”);
> >>>> FileAppender appender = context.getConfiguration().getAppender("info");
> >>>>
> >>>> Ralph
> >>>>
> >>>>
> >>>>> On Feb 19, 2020, at 7:47 AM, EDMONDO SENA <[hidden email]> wrote:
> >>>>>
> >>>>> Ok, but they are the API not examples....
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> On 2020/02/19 14:29:41, Gary Gregory <[hidden email]> wrote:
> >>>>>> Please see
> >>>>>> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/config/Configuration.html#getAppender-java.lang.String-
> >>>>>>
> >>>>>> On Wed, Feb 19, 2020, 09:27 EDMONDO SENA <[hidden email]> wrote:
> >>>>>>
> >>>>>>>
> >>>>>>> Can you tell me where can I find out these examples?
> >>>>>>>
> >>>>>>> Kind regards.
> >>>>>>> //Edmondo.
> >>>>>>>
> >>>>>>>
> >>>>>>> On 2020/02/19 14:09:52, Matt Sicker <[hidden email]> wrote:
> >>>>>>>> Appenders and such are part of the core library now. There are likely
> >>>>>>>> features in log4j2 that could replace what you’re doing, though. In any
> >>>>>>>> case, there’s plenty of examples of how that is done in the tests.
> >>>>>>>>
> >>>>>>>> On Wed, Feb 19, 2020 at 04:23 EDMONDO SENA <[hidden email]> wrote:
> >>>>>>>>
> >>>>>>>>> how to getAppender from logger? we have a lot of code to get the
> >>>>>>> appender
> >>>>>>>>> in the project: logger.getAppender(appenderName). I read the api for
> >>>>>>> the
> >>>>>>>>> log4j2, I couldn't find any.
> >>>>>>>>>
> >>>>>>>>> How can I fix it?
> >>>>>>>>>
> >>>>>>>>> ---------------------------------------------------------------------
> >>>>>>>>> To unsubscribe, e-mail: [hidden email]
> >>>>>>>>> For additional commands, e-mail: [hidden email]
> >>>>>>>>>
> >>>>>>>>> --
> >>>>>>>> Matt Sicker <[hidden email]>
> >>>>>>>>
> >>>>>>>
> >>>>>>> ---------------------------------------------------------------------
> >>>>>>> To unsubscribe, e-mail: [hidden email]
> >>>>>>> For additional commands, e-mail: [hidden email]
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: [hidden email]
> >>>>> For additional commands, e-mail: [hidden email]
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: [hidden email]
> >>> For additional commands, e-mail: [hidden email]
> >>>
> >>>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getAppender

Doug Wegscheid
 There is no appender named "LoggerLog4jDebug". The appender is probably "LoggerLog4jDebugAppender"?

    On Thursday, March 19, 2020, 11:19:35 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
 
 The code is:
try {
                ConfigurationSource source = new ConfigurationSource(new
                    FileInputStream("Log4jApache.xml"));
                Configurator.initialize(null, source);
            } catch (IOException e) {
                System.err.println("Error while initializing log4j from file: log4j.xml");
                e.printStackTrace();
            }

LoggerContext context = (LoggerContext) LogManager.getContext(false);
Appender appender = context.getConfiguration().getAppender("LoggerLog4jDebug");
System.out.println("appender = " + appender);

File xml is:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR">
    <Appenders>
        <Console name="LoggerLog4jDebugAppender" target="SYSTEM_OUT">
            <PatternLayout pattern="log4j: %msg%n"/>
        </Console>
        <Console name="LoggerLog4jErrorAppender" target="SYSTEM_ERR">
            <PatternLayout pattern="log4j: %msg%n"/>
        </Console>       
    </Appenders>  
Reply | Threaded
Open this post in threaded view
|

Re: getAppender

EDMONDO SENA
Doesn't work also with LoggerLog4jDebugAppender.

Could it depends of the fact is the package is default?
I mean:

MainLog4j2
           src
              default package
                      file.java
             file.xml

On 2020/03/19 15:25:20, Doug Wegscheid <[hidden email]> wrote:

>  There is no appender named "LoggerLog4jDebug". The appender is probably "LoggerLog4jDebugAppender"?
>
>     On Thursday, March 19, 2020, 11:19:35 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
>  
>  The code is:
> try {
>                 ConfigurationSource source = new ConfigurationSource(new
>                     FileInputStream("Log4jApache.xml"));
>                 Configurator.initialize(null, source);
>             } catch (IOException e) {
>                 System.err.println("Error while initializing log4j from file: log4j.xml");
>                 e.printStackTrace();
>             }
>
> LoggerContext context = (LoggerContext) LogManager.getContext(false);
> Appender appender = context.getConfiguration().getAppender("LoggerLog4jDebug");
> System.out.println("appender = " + appender);
>
> File xml is:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="ERROR">
>     <Appenders>
>         <Console name="LoggerLog4jDebugAppender" target="SYSTEM_OUT">
>             <PatternLayout pattern="log4j: %msg%n"/>
>         </Console>
>         <Console name="LoggerLog4jErrorAppender" target="SYSTEM_ERR">
>             <PatternLayout pattern="log4j: %msg%n"/>
>         </Console>       
>     </Appenders>  

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: getAppender

Ralph Goers
It is very unlikely your package name has anything to do with the problem.

I would suggest changing status=“ERROR” to status=“DEBUG” and make sure you see your configuration be created and that it is created correctly.  If you see it created then use a debugger and stop it at the line where you get the appender and look at the data structures and see what appenders are there.

> On Mar 19, 2020, at 8:30 AM, EDMONDO SENA <[hidden email]> wrote:
>
> Doesn't work also with LoggerLog4jDebugAppender.
>
> Could it depends of the fact is the package is default?
> I mean:
>
> MainLog4j2
>           src
>              default package
>                      file.java
>             file.xml
>
> On 2020/03/19 15:25:20, Doug Wegscheid <[hidden email]> wrote:
>> There is no appender named "LoggerLog4jDebug". The appender is probably "LoggerLog4jDebugAppender"?
>>
>>    On Thursday, March 19, 2020, 11:19:35 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
>>
>> The code is:
>> try {
>>                 ConfigurationSource source = new ConfigurationSource(new
>>                     FileInputStream("Log4jApache.xml"));
>>                 Configurator.initialize(null, source);
>>             } catch (IOException e) {
>>                 System.err.println("Error while initializing log4j from file: log4j.xml");
>>                 e.printStackTrace();
>>             }
>>
>> LoggerContext context = (LoggerContext) LogManager.getContext(false);
>> Appender appender = context.getConfiguration().getAppender("LoggerLog4jDebug");
>> System.out.println("appender = " + appender);
>>
>> File xml is:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <Configuration status="ERROR">
>>     <Appenders>
>>         <Console name="LoggerLog4jDebugAppender" target="SYSTEM_OUT">
>>             <PatternLayout pattern="log4j: %msg%n"/>
>>         </Console>
>>         <Console name="LoggerLog4jErrorAppender" target="SYSTEM_ERR">
>>             <PatternLayout pattern="log4j: %msg%n"/>
>>         </Console>        
>>     </Appenders>  
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]