~Abhi$hek~ | 30 Jan 06:33 2014
Picon

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
Saibabu Vallurupalli | 23 Jan 20:46 2014
Picon

Unable to detect RewriteAppender

Hi,

I am using log4j 1.2.17 version and have log4j.properties.
This has properties defined for Console appender and RollingFileAppender.

Our application is working good since last 3 and half years.

Now, I am trying to introduce a new property as below:

log4j.appender.A1 = org.apache.log4j.rewrite.RewriteAppender
log4j.appender.A1.appender-ref=R

The RewriteAppender class is not even getting detected. My logging parser
just ignores these lines and goes to the later ones to interpret.

Please advice.

Thanks,
Sai
Saibabu Vallurupalli | 23 Jan 16:29 2014
Picon

Help with rewrite appender

Hi Good morning.

I am trying to implement Rewrite Appender logic and based on my other
conversations I understood the way I am doing below, But still I am unable
to control certain messages.

My Policy class is:
***************
 <at> Override
    public LoggingEvent rewrite(LoggingEvent source) {
        String msgToInspect = source.getMessage().toString();
        if (null != msgToInspect && msgToInspect.contains("///")) {
            return null;
        }

        return new LoggingEvent(source.getFQNOfLoggerClass(),
                source.getLogger(), source.getTimeStamp(),
source.getLevel(),
                source.getMessage(), source.getThreadName(),
                source.getThrowableInformation(), source.getNDC(),
                source.getLocationInformation(), source.getProperties());
    }
***************

My log4j.properties file I configured these lines:
log4j.appender.rewrite = org.apache.log4j.rewrite.RewriteAppender
log4j.appender.rewrite.appender-ref = R, C
log4j.appender.rewrite.rewritePolicy =
gov.hhs.fha.nhinc.log4j.policy.CONNECTLog4jRewritePolicy

(Continue reading)

Steven Yang | 22 Jan 03:42 2014
Picon

Log files rename failed

I have observed a file-rename issue while using rolling appender.
I am using log4j2-beta9.
This main reason I switched to log4j2 is because the same problem occurs in
log4j 1.x and the only way to fix it is to modify the source which is
something we dont want to do unless it's the last option, while not
modifying any of our current source code.
Therefore addition to the log4j2 core jars we also have log4j-1.2-api.jar have
to replace the original log4j we also have binding from commons-logging to
log4j2.

The environment is running on a VM with Windows Server 2008 running
Websphere 8.

My configuration looks like

<RollingFile name="wmsRollingFile" fileName="${fileroot}/wms/wms.log"
filePattern="${fileroot}/wms/wms-%d{MM-dd-yyyy}-%i.log.gz">
      <PatternLayout pattern="%d [%t] %C %l %-5p %c - %m%n"/>
      <Policies>
        <SizeBasedTriggeringPolicy size="10 MB"/>
        <TimeBasedTriggeringPolicy />
      </Policies>
</RollingFile>

<logger name="org.springframework" level="debug" additivity="false">
        <appender-ref ref="wmsRollingFile"/>
    </logger>

    <logger name="org.apache.http" level="debug" additivity="false">
        <appender-ref ref="wmsRollingFile"/>
(Continue reading)

Dave Levitt | 21 Jan 17:15 2014
Picon

Servlet 2.5 compatibility - Log4jServletContainerInitializer

I'm trying to add log4j 2.x to a Servlet 2.5 web app.

One goal is to also be able to deploy the artifact on a Servlet 3.x
container as the servers are migrated [from JBoss 5.x to 7].

When testing on JBoss 7.1, an exception is thrown from
Log4jServletContainerInitializer [line 49] as the servlet context gets the
major version [3.x] from the container instead of the 'effective' major
version [from the artifact's web.xml file].

The comment in the [2,0 RC1] onStartup method says "… For consistency
across all containers, if the effective Servlet major version of the
application is less than 3.0, this initializer does nothing."

So, should the code be invoking servletContainer.getEffectiveMajorVersion()
??
Ilya Tepikin | 10 Jan 18:29 2014
Picon

log4j2 SMTP Appender: include previous messages with another level

Hi All,

I'm using log4j2-beta9 and I have the following config (part of it):

    <Appenders>
        <SMTP name="Mailer" suppressExceptions="false"
              subject="${subject}" to="${receipients}" from="${from}"
              smtpHost="${smtpHost}" smtpPort="${smtpPort}"
              smtpProtocol="${smtpProtocol}" smtpUsername="${smtpUser}"
              smtpPassword="${smtpPassword}" smtpDebug="false"
bufferSize="20">
            <PatternLayout>
                <pattern>%d{dd-MM-yyyy HH:mm:ss,SSS} %5p %m%n</pattern>
            </PatternLayout>
        </SMTP>

        <Async name="AsyncMailer">
            <AppenderRef ref="Mailer"/>
        </Async>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="AsyncMailer" level="error"/>
        </Root>
    </Loggers>

With this configuration I receive email with just 1 error message.
How can I configure log4j2 to receive 1 error message and N previous
messages with LEVEL=INFO?

(Continue reading)

Markus Pscheidt | 7 Jan 18:25 2014
Picon

Archiving PDF/A

I'm looking for a way to archive log files in PDF/A format. One option
might be to write a custom rolling file appender that archives in the
desired PDF format, instead of a standard text format. With the plugin
structure of Log4j 2 this seems possible.

Has anybody done something similar or any related hints?

Thanks,
Markus
Matt Sicker | 7 Jan 00:40 2014
Picon

What's the point of logger.catching(e)?

In my own projects, I was using it manually to log exactly what I thought
it was for. However, the method with no specified level uses Level.TRACE if
I recall correctly, and that level is usually disabled.

Anyway, is this provided more so as a method to be automatically injected
via bytecode manipulation (along with logger.entry(), logger.exit(),
logger.throwing(), etc.)? Or done manually? If done manually, you can get
some rather amusingly messy methods. For example, from some code I've
written like that:

<
https://raw.github.com/jvz/dynunit/master/src/main/java/atg/tools/dynunit/DynUnit.java
>

Anyway, I'm asking now because I don't see log4j2 even using it internally
where appropriate. Is this more of a personal preference thing?

--

-- 
Matt Sicker <boards <at> gmail.com>
Giovanni Mondo | 30 Dec 17:57 2013
Picon

log4j2 and ServletContextListeners

Hi,

I’m migrating a web application running on Tomcat from log4j to log4j2.
 
The web application has Filters, ServletContextListeners and Servlets .
 
Log is expected to be addressed by a Log4jServletContextListener whilst default log is addressed by a
log4j2.xml in classpath.
 
Filters and Servlets are now logging in the expected log whilst ServletContextListeners are logging in
default log.
 
Do you think this is the right behaviour or there could be an error in my configuration ?
 
Regards,
 
Giovanni
流子℡ | 19 Dec 03:38 2013

how to filter JakartaCommonsLoggingImpl's print log

hi,all,      I meet a problem that com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl's debug
log can't be filtered,in log4j2.xml ,I have configured as follows:
<logger name="com.ibatis.common" level="warn">
</logger>



but in console,the log still printed as this:
.......
2013-12-19 10:25:27.695 DEBUG [main][JakartaCommonsLoggingImpl.java:27] - {conn-100143} Connection
2013-12-19 10:25:27.695 DEBUG [main][JakartaCommonsLoggingImpl.java:27] - {conn-100143}
Preparing Statement:    update id_gen    set     value = value + 1          where id = ?    
2013-12-19 10:25:27.696 DEBUG [main][JakartaCommonsLoggingImpl.java:27] - {pstm-100144}
Executing Statement:    update id_gen    set     value = value + 1          where id = ?    
2013-12-19 10:25:27.696 DEBUG [main][JakartaCommonsLoggingImpl.java:27] - {pstm-100144}
Parameters: [33d39b36-1db7-471d-b034-56fba8d5229d]



.....


the class 's source code as follows:
package com.ibatis.common.logging.jakarta;


import com.ibatis.common.logging.Log;
import org.apache.commons.logging.LogFactory;


(Continue reading)

Marcin Zajączkowski | 19 Dec 00:02 2013
Picon

ClassCastException when using log4j2 with gradle-tomcat-plugin

Hi,

I'm playing with log4j2 and today I've found the issue when I tried to
use it with gradle-tomcat-plugin [1]. In the web application with Spring
4 when the context is starting I've got:

> java.lang.ClassCastException:
> org.apache.logging.log4j.core.web.Log4jServletContainerInitializer
> cannot be cast to javax.servlet.ServletContainerInitializer on startup.

I reported an issue [2] to the plugin author also with simple quickstart
application [3] which reproduces the problem, but we have no clue why it
happens.

Maybe you have any hints?

[1] - https://github.com/bmuschko/gradle-tomcat-plugin/
[2] - https://github.com/bmuschko/gradle-tomcat-plugin/issues/78
[3] -
https://github.com/szpak/code-examples-and-poc/tree/master/gradle-tomcat-plugin-log4j2-poc

Marcin

--

-- 
http://blog.solidsoft.info/ - Working code is not enough

Gmane