Eric Scheie | 17 May 2013 06:44
Picon

Programmatically setting log4j2 log level

I'm developing a web application and would like to be able to dynamically
change log levels from within my application instead of editing the log4j2
configuration file.   I'm using log4j 2.0 beta5.

I'm currently setting the log level after a form submit using:

((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogManager.
ROOT_LOGGER_NAME)).setLevel(Level.XXXXX);

And when I call:

((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogManager.
ROOT_LOGGER_NAME)).getLevel()

I get the level that I previously set as expected but I don't see the level
reflected in the logs.  For example, when changing the level to DEBUG on
the root logger I do not see debug messages written to the console.  If I
change the level of the root logger in my log4j2.xml configuration file I
do see the debug messages written to the console.

Here is my log4j2.xml file.

<?xml version="1.0" encoding="UTF-8"?>

<configuration status="DEBUG" monitorInterval="10">

    <appenders>

        <Console name="Console" target="SYSTEM_OUT">

(Continue reading)

Te Ta | 15 May 2013 03:59
Picon

Re: Adding appenders programatically

What is the recommended way of adding appenders in log4j 2.

In older version we were able to do
Logger.getLogger(theCategory).addAppender(appender).

Thanks!

On Tue, May 14, 2013 at 7:51 PM, Te Ta <ttashiuwyo <at> gmail.com> wrote:

> What is the recommended way of adding appenders in log4j 2.
>
> In older version we were able to do
> Logger.getLogger(theCategory).addAppender(appender).
>
> Thanks!
>
Jason B | 14 May 2013 21:47
Picon
Gravatar

Burst Filter - Use to limit messages sent over a specific period?

I'm attempting to leverage a burst filter in my application.  I wish to log
errors and send e-mails any time we log an error.  The main thing is, I
don't want to send more than a few e-mails in a given time period (say, one
per event per fifteen minutes), to avoid overwhelming my inbox with these
error events.

Burst Filter seems appropriate for this role, but the documentation is
lacking.  For instance:

 - If I want a filter to accept only those events that happen after the
threshold, but "rest" for that fifteen minute period of time, how would I
accomplish this?  The configuration is less than intuitive here.

 - What is the role of <TimeBasedTriggeringPolicy />? It's not mentioned
anywhere on the site, and only by digging in the source could I actually
determine what it's supposed to be doing.  It's also listed in every
example for filters on the site.

Thanks for clearing up any confusion.

- Jason Black
Mary Laude | 14 May 2013 02:46
Picon

Need help: Steps in your INSTALL doc failing

Hello -

I can write, compile, and successfully run a Java program
to look at a .jar file and list the classes defined therein, but
I can't for the life of me get your "Using log4j" java code shown
in 1-2.17's INSTALL doc to work.

Perhaps there's some other magic that needs to happen to get
this code snippet you wrote to yield output?
----------------------------------------------------------------------------------------
 You can now test your installation by first compiling the following
   simple program.

    import org.apache.log4j.Logger;
    import org.apache.log4j.BasicConfigurator;

    public class Hello {

      private static final Logger logger = Logger.getLogger(Hello.class);

      public
      static
      void main(String argv[]) {
        BasicConfigurator.configure();
        logger.debug("Hello world.");
        logger.info("What a beatiful day.");
      }
    }
-----------------------------------------------------------------------------------------
I understand how CLASSPATH works, etc.  I can get it to compile but
(Continue reading)

Jason B | 13 May 2013 20:38
Picon
Gravatar

Custom Syslog Format: Appending Exceptions?

Looking around at the Syslog support, and I noticed that exceptions aren't
being sent across the wire.  I understand that there may be some limit to
how much data we're sending across with Syslog via TCP, but I was curious
if there was any custom support for formatters with exceptions.

I came across this old JIRA for that support:

https://issues.apache.org/jira/browse/LOG4J2-136

... and looking into RFC5424Layout, I see that it could be added, but I'm
not sure if our setup is configured properly to make use of it.

- Jason Black
Jason B | 13 May 2013 18:32
Picon
Gravatar

Convient way to specify Log4J2 configuration outside of webapp?

Hello,

I'm wondering if there is a convenient way to configure Log4J2 logging
without having it inside of our resources directory.  I don't want to use
symbolic links, as that has the potential of introducing security holes
into our platform.

We're looking into other options such as specifying file locations, but the
documentation is incomplete or does not apply to our unique solution.

Could some light be shed on this?

Thanks,

Jason Black
Christian Grobmeier | 11 May 2013 06:53
Picon
Gravatar

[ANNOUNCEMENT] Welcome Nick Williams

Hi,

it is my pleasure to announce to the community
that Nick Williams has joined our ranks.

He made remarkable contributions to log4j 2
and we all believe he is a valuable member
of Apache Logging Services now and in future.

Kind regards,
Christian
Matej Vitásek | 9 May 2013 14:32
Picon
Gravatar

Two problems with SMTPAppender

Hi all,

I'd like to report 2 problems I am encountering using the SMTPAppender. I
am using it* to send me mails whenever an ERROR is logged in a web
application.

1) Buffer size is ignored. Excerpt from my log4j2.xml:
<SMTP name="Mail" suppressExceptions="false" subject="Error Log"
to="..." from="..." smtpHost="smtp.gmail.com"
 smtpPort="465" *bufferSize="10"* smtpProtocol="smtps" smtpUsername="..."
smtpPassword="...">
 </SMTP>

You will notice that the buffer size is 10. I'd expect to be getting
e-mails with 10 errors aggregated, but every e-mail always contains only
one error.

Looking into SMTPAppender.append() I see a call to manager.sendEvents()
which does not aggregate the message - it just sends it. To me it seems
that append() should write into SMTPManager.buffer and send only if it's
full...

2) Sending the e-mail blocks the thread that logged the error. I don't know
how to "prove" this empirically, it's just a really clear subjective
feeling: whenever an error gets logged, the whole application just lags for
the time it takes to send the mail.

Can I provide you some help in pinpointing this problem?

Overall: just ask if you need more information,
(Continue reading)

Scott Deboy | 3 May 2013 09:04
Picon

Chainsaw support for java.util.logging file format

For those who may be interested, Chainsaw has been updated to include
support for multi-line log file formats, including the default
java.util.logging file format.

If you want to try it out, the developer snapshot of Chainsaw, in Mac dmg
or zip file format, is available at
http://people.apache.org/~sdeboy

If you want to try out Chainsaw's ability to parse and tail a
java.util.logging-formatted file, follow these steps:

 - start Chainsaw
 - Select the 'File, Load Chainsaw configuration' menu
 - Select 'process a log file'
 - Select the log file you want to parse by pressing the 'Open File' button
and browsing to the file
 - Log file format: TIMESTAMP LOGGER THREAD(LF)LEVEL: MESSAGE
 - Log file timestamp format: MMM dd, yyyy HH:mm:ss a

You may want to check the box at the bottom to tell Chainsaw to always run
with this configuration, or save it off for later use.

Feedback always welcome!

Scott Deboy
John Smith | 1 May 2013 22:41
Picon

Custom Converter plugin won't load.

Using log4j2-beta5

I'm writing a custom PatternConverter to mask logs for such things as
Credit Card and Card Security Code and some additional elements.

My converter looks like so....

package com.xxx.log4j.converters;

import java.util.List;
import java.util.regex.Pattern;

import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.apache.logging.log4j.core.pattern.ConverterKeys;
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
import org.apache.logging.log4j.core.pattern.PatternFormatter;
import org.apache.logging.log4j.core.pattern.PatternParser;

 <at> Plugin(name = "MaskConverter", type = "Converter")
 <at> ConverterKeys({"ma", "mask" })
public class MaskConverter extends LogEventPatternConverter  {

private final List<PatternFormatter> formatters;
private final Pattern ccPattern;
private final Pattern cvnPattern;

public static final String CARD_PATTERN =
(Continue reading)

Remko Popma | 30 Apr 2013 07:44
Picon
Favicon

Re: Log4j2 UDP socket configure error. Class not found org.apache.logging.log4j.core.impl.Log4jLogEvent$LogEventProxy

Hi Imesh,

I'll take a look, thank you. 
I'll attach the files to the Jira when I get home.

About Jira, I think anyone can create an account. Maybe for next time... :-)

Remko

Sent from my iPhone

On 2013/04/30, at 14:40, Imesh Damith <imesh <at> rezgateway.com> wrote:

> Hi Remko,
> 
> Sorry, I do not have access to your JIRA. (User name pwd).
> 
> Here with I have attached relevant files. My whole program needs to configure but within these classes you
should be able to understand.
> 
> 
> client code (Logs_test.java class) send the debug log and TCPServer_test.java class receive it.  
> 
> But there is an error catching in line 111 ( class not found). 
> 
> 
> 
> Let me know if I miss any jar file. My pom.xml file also attached.
> 
> 
(Continue reading)


Gmane