Jordán E Moisés | 2 Feb 23:43 2015

Why RollingFileAppender do not work by size on WebLogic 10.3.3 with Log4J 1.2.16 and jdk 1.6.0_33?

Why RollingFileAppender do not work by size on WebLogic 10.3.3 with Log4J 1.2.16 and jdk 1.6.0_33 ?

 

PROBLEM

The file grows over the limit set by configuration. It only creates a new one when the WebLogic is restarted.

 

DATA

My "log4j.properties" is place at WEBAPP.war:\WEB-INF\classes

My "log4j-1.2.16.jar" is place at WEBAPP.war:\WEB-INF\lib

 

This is my 1st version of "log4j.properties"

# Root logger option

log4j.rootLogger=DEBUG, XMLRA, CA, RA

 

# Direct log messages to a log file

log4j.appender.RA=org.apache.log4j.RollingFileAppender

log4j.appender.RA.layout=org.apache.log4j.PatternLayout

log4j.appender.RA.layout.ConversionPattern=[%d{dd/MMM/yyyy HH:mm:ss:SSS}] %-5p %c -> %m%n

log4j.appender.RA.File=c:\\Oracle\\Middleware\\user_projects\\domains\\bpm\\servers\\BPMServer\\logs\\OBPMConnectorWebService.log

log4j.appender.RA.append=true

log4j.appender.RA.MaxFileSize=2MB

log4j.appender.RA.MaxBackupIndex=10

log4j.appender.RA.BufferedIO=true

log4j.appender.RA.ImmediateFlush=false

log4j.appender.RA.BufferSize=4096

log4j.appender.RA.Threshold=warn

 

# Direct log messages to stdout

log4j.appender.CA=org.apache.log4j.ConsoleAppender

log4j.appender.CA.layout=org.apache.log4j.PatternLayout

log4j.appender.CA.layout.ConversionPattern=[%d{dd/MMM/yyyy HH:mm:ss:SSS}] %-5p %c -> %m%n

log4j.appender.CA.Target=System.out

log4j.appender.cA.Threshold=all

 

# Direct log messages to a log xml

log4j.appender.XMLRA=org.apache.log4j.RollingFileAppender

log4j.appender.XMLRA.layout=org.apache.log4j.xml.XMLLayout

log4j.appender.XMLRA.File=c:\\Oracle\\Middleware\\user_projects\\domains\\bpm\\servers\\BPMServer\\logs\\OBPMConnectorWebService.xml

log4j.appender.XMLRA.append=true

log4j.appender.XMLRA.MaxFileSize=20MB

log4j.appender.XMLRA.MaxBackupIndex=100

log4j.appender.XMLRA.BufferedIO=true

log4j.appender.XMLRA.ImmediateFlush=false

log4j.appender.XMLRA.BufferSize=4096

 

This is my 2nd version of "log4j.properties" (I found some examples on the Internet and I applied the changes without a solution)

# Root logger option

log4j.rootLogger=DEBUG, XMLRA, CA, RA

 

# Direct log messages to a log file

log4j.appender.RA=org.apache.log4j.RollingFileAppender

log4j.appender.RA.layout=org.apache.log4j.PatternLayout

log4j.appender.RA.layout.ConversionPattern=[%d{dd/MMM/yyyy HH:mm:ss:SSS}] %-5p %c -> %m%n

log4j.appender.RA.File=c:\\Oracle\\Middleware\\user_projects\\domains\\bpm\\servers\\BPMServer\\logs\\OBPMConnectorWebService.log

log4j.appender.RA.append=true

log4j.appender.RA.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy 

log4j.appender.RA.rollingPolicy.maxIndex=10 

log4j.appender.RA.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy 

log4j.appender.RA.triggeringPolicy.MaxFileSize=2048 

log4j.appender.RA.BufferedIO=true

log4j.appender.RA.ImmediateFlush=false

log4j.appender.RA.BufferSize=4096

log4j.appender.RA.Threshold=warn

 

# Direct log messages to stdout

log4j.appender.CA=org.apache.log4j.ConsoleAppender

log4j.appender.CA.layout=org.apache.log4j.PatternLayout

log4j.appender.CA.layout.ConversionPattern=[%d{dd/MMM/yyyy HH:mm:ss:SSS}] %-5p %c -> %m%n

log4j.appender.CA.Target=System.out

log4j.appender.cA.Threshold=all

 

# Direct log messages to a log xml

log4j.appender.XMLRA=org.apache.log4j.RollingFileAppender

log4j.appender.XMLRA.layout=org.apache.log4j.xml.XMLLayout

log4j.appender.XMLRA.File=c:\\Oracle\\Middleware\\user_projects\\domains\\bpm\\servers\\BPMServer\\logs\\OBPMConnectorWebService.xml

log4j.appender.XMLRA.append=true

log4j.appender.XMLRA.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy 

log4j.appender.XMLRA.rollingPolicy.maxIndex=100 

log4j.appender.XMLRA.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy 

log4j.appender.XMLRA.triggeringPolicy.MaxFileSize=20480

log4j.appender.XMLRA.BufferedIO=true

log4j.appender.XMLRA.ImmediateFlush=false

log4j.appender.XMLRA.BufferSize=4096

 

This is my 3rd version of "log4j.properties" (I set the suffix of unit of size without a solution)

# Root logger option

log4j.rootLogger=DEBUG, XMLRA, CA, RA

 

# Direct log messages to a log file

log4j.appender.RA=org.apache.log4j.RollingFileAppender

log4j.appender.RA.layout=org.apache.log4j.PatternLayout

log4j.appender.RA.layout.ConversionPattern=[%d{dd/MMM/yyyy HH:mm:ss:SSS}] %-5p %c -> %m%n

log4j.appender.RA.File=c:\\Oracle\\Middleware\\user_projects\\domains\\bpm\\servers\\BPMServer\\logs\\OBPMConnectorWebService.log

log4j.appender.RA.append=true

log4j.appender.RA.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy 

log4j.appender.RA.rollingPolicy.maxIndex=10 

log4j.appender.RA.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy 

log4j.appender.RA.triggeringPolicy.MaxFileSize=2MB 

log4j.appender.RA.BufferedIO=true

log4j.appender.RA.ImmediateFlush=false

log4j.appender.RA.BufferSize=4096

log4j.appender.RA.Threshold=warn

 

# Direct log messages to stdout

log4j.appender.CA=org.apache.log4j.ConsoleAppender

log4j.appender.CA.layout=org.apache.log4j.PatternLayout

log4j.appender.CA.layout.ConversionPattern=[%d{dd/MMM/yyyy HH:mm:ss:SSS}] %-5p %c -> %m%n

log4j.appender.CA.Target=System.out

log4j.appender.cA.Threshold=all

 

# Direct log messages to a log xml

log4j.appender.XMLRA=org.apache.log4j.RollingFileAppender

log4j.appender.XMLRA.layout=org.apache.log4j.xml.XMLLayout

log4j.appender.XMLRA.File=c:\\Oracle\\Middleware\\user_projects\\domains\\bpm\\servers\\BPMServer\\logs\\OBPMConnectorWebService.xml

log4j.appender.XMLRA.append=true

log4j.appender.XMLRA.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy 

log4j.appender.XMLRA.rollingPolicy.maxIndex=100 

log4j.appender.XMLRA.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy 

log4j.appender.XMLRA.triggeringPolicy.MaxFileSize=20MB

log4j.appender.XMLRA.BufferedIO=true

log4j.appender.XMLRA.ImmediateFlush=false

log4j.appender.XMLRA.BufferSize=4096

 

---------------------------------------------------------------------------

 

Before using "log4j.properties" I set all this properties by code

Both the coded version as with the 1st "log4j.properties" file version, works fine outside WebLogic. I mean it worked with an application launched from the OS console.

 

 

I 'm using a wrong version of Log4J? I have to use the "log4j.xml" file instead for a Web application?

May be I have to change the roll over by time?

 

Please I need some help and I have no response at Oracle WebLogic Forum

 

Regards

Jordán

 

 

Jordán Eduardo Moisés

Av Belgrano 768 - piso 5 depto I
C.P: C1092AAU
Buenos Aires - Argentina
Teléfono: (54 11) 5256-4060
Móvil: (54 9 11) 5751-1359
Web: www.kennen-consulting.com

 

Blaine Bergeson (bbergeson | 29 Jan 22:49 2015

Add Filter to a Logger

How does the DynamicThreshold filter work?  I want to add a filter to the root logger so that if I add a key to the
thread context map it will override the logger level and still pass it on?  This will allow me to turn up
logging on a certain class or set of methods without having to change the configuration file.

Also, I can see that in general filters can be added to a logger as shown below, but how is this evaluated? 
Normally the loggers' log level is evaluated first, correct?  So if a logging event is TRACE then the
following filter wouldn't even be evaluated, correct?  What if I change the filter to a DynamicThreshold
filter, would it then temporarily override the logger level?

<Loggers>
<Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
<Filter type="ThreadContextMapFilter">
<KeyValuePair key="test" value="123"/>
</Filter>
<AppenderRef ref="STDOUT"/>
</Logger>
</Loggers>

Thx Blaine
Mikhail Dobrinin | 28 Jan 18:27 2015

Changing the LogEventFactory?

Hi,

Is there a way to change the LogEventFactory for all loggers at runtime?

Don’t Miss FOCUS 2015 Orlando – over 100 customer-led sessions and 1 Grammy-winning singer! Learn
More > <http://www.jda.com/focus>
Fabio | 26 Jan 09:44 2015
Picon

Timestamp reliability (log4j in Hadoop)

Hi everyone,
I am using Hadoop, that uses log4j as logging system.
Since I don't know anything about how log4j works, and since I am 
relying on the logs for my work, I would like to ask you how reliable is 
the timestamp I see in the logs.
Is each timestamp I see the exact real system time at which each 
"LOG.info(...)" function is called within the Hadoop code? Or is the log 
request enqueued in some buffer so that the timestamp includes some 
delay to process the entries in this buffer?
I asked this in the Hadoop mailing list but with no answer, hope to have 
more luck here.

Thanks in advance

Fabio
Onion Crucian | 23 Jan 20:17 2015
Picon

migration from log4j 1.2 to log4j2: locationInformation and getAppender() are missing

Hi,

I am doing POC to migrate current project from using log4j1 to log4j2.
There are custom appenders in our projects and we are using a lot of log4j
internal APIs. There are a few things I couldn't find the new way to
achieve. I appreciate if anyone can help.

1 LocationInfomation.

we used to get locationinformation like this in case of no exception thrown
from caller:

locationInfo = new LocationInfo(new Throwable(),
logEvent.getFQNOfLoggerClass());

I couldn't find the log4j2 implenentation to do the similar thing.
2 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.

Thank you all for your time.

Wei
Blaine Bergeson (bbergeson | 22 Jan 17:38 2015

Programmatically loading of the configuration file

I can't seem to load a configuration file?  The reason I am doing this is because I have my configuration file
in a package that is not on the default classpath.  Adding the package to the classpath is not straight
forward.  Also, I don't want to add a system property or environment variable because we will be reusing
this package throughout all of our projects.  So the idea is that this package will just be pulled into a
project and it will contain the configuration file along with a class that will add the correct items to the
context map and will load the configuration file.  The developer should just be able to include the package
and they are off and running.

I am using the following code to load the config file which resides in the same package as the class that this
method is part of, but it is not working.  As I step through the code I can see that inside
ConfigurationSource the stream is loaded correctly with the contents of my file so I know that it found it
but when the getContext line is executed I get an error saying that it could not locate a configuration
file.  What am I missing?

        try {
            InputStream is = MyLogFactory.class.getResourceAsStream("log4j2.xml");
            ConfigurationSource source = new ConfigurationSource(is);
            Configuration config = XmlConfigurationFactory.getInstance().getConfiguration(source);
            LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
            ctx.stop();
            ctx.start(config);
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }

Thx Blaine
David Lee | 19 Jan 13:50 2015

"Custom Container" logging

I have an normally command line or embedded application that can start a separate instance of itself
in a GUI (could be non GUI ...) this instance is in a new thread and  thread group.

I would like to be able to capture the log events generated by this new instance in some way that's
independent of the other instances or the main app.
The main purpose is to show a 'event logging' debug window.

In log4j(1) I was able to add a new appended at runtime, and I was somewhat but not quite as successful
in log4j2.   I came to the conclusion that trying to mimic log4j1 runtime appenders is not the best way to do this.
( as is documented,  updating the configuration is the recommendation).

Before proceeding on that route I'd like to consider alternatives.   For example the ContextSelector looks like
the right integration point.
I am a bit unclear on how this works.   Currently I use exclusives static variable defined loggers, e.g.
         Logger mLogger = LogManager.getLogger();
But while I make heavy use of custom class loaders and the default is documented as ClassLoaderContextSelector(),
they all seem to end up in the same context (which is generally good) ...  - but the docs don't describe how that works,
"This ContextSelector chooses a LoggerContext based upon the ClassLoader of the caller."

One read of this implies each class loader would get its own logger context, but I'm not seeing that - or maybe
Im not looking
hard enough ( log events from all loggers seem to correctly go through the same context, configuration and spenders).

The BasicContextSelector looks promising:
  "Returns either this Thread's context or the default LoggerContext."

But I don't see where it is that I would set this context instance.  I do manage the thread local storage,
associate the correct class loader
into the thread local and also assign each independent set instances into their own thread group.
But I understand how I would arrange for a particular context select to make use of this or where I would
configure it

Another alternative I tested does seem to work, which is to create a top level generic appended that always
gets every event.
Right now it does  nothing but I can arrange for it to at runtime examine the thread local and route messages accordingly.

Suggestions on what approaches to consider that are intended for this type of use are appreciated.

----------------------------------------
David A. Lee
dlee <at> calldei.com<mailto:dlee <at> calldei.com>
http://www.xmlsh.org<http://www.xmlsh.org/>

David Lee | 19 Jan 13:32 2015

Loggers for internal purposes

I am interested in using Log4j to record log information (events?) for internal purposes,
not routed as default as configured with the default configuration.
Reading "Event Logging" seems very close, but I can't see where it defines what happens to the events
logged with
1.     EventLogger.logEvent(msg);
Where do these events go ? where does one 'capture' the events ?
The docs say it uses a logger  "EventLogger" ... does that mean this uses the same LoggerContext and config as
other loggers ?  If so what is the difference between this logger and say any logger I created with
      Logger logger = LogManager.getLogger("MyLogger") ?

Thanks.

----------------------------------------
David A. Lee
dlee <at> calldei.com<mailto:dlee <at> calldei.com>
http://www.xmlsh.org<http://www.xmlsh.org/>

Sumantha Kannantha | 17 Jan 09:33 2015
Picon

Log4j2 error in the console

Hi All,

We are getting below error in stderr.

java.io.StreamCorruptedException: invalid stream header: 1B252D31

       at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:806)

        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299)

        at org.apache.logging.log4j.core.net.server.ObjectInputStreamLogEventBridge.wrapStream(ObjectInputStreamLogEventBridge.java:43)

        at org.apache.logging.log4j.core.net.server.ObjectInputStreamLogEventBridge.wrapStream(ObjectInputStreamLogEventBridge.java:29)

        at org.apache.logging.log4j.core.net.server.TcpSocketServer$SocketHandler.<init>(TcpSocketServer.java:53)

        at org.apache.logging.log4j.core.net.server.TcpSocketServer.run(TcpSocketServer.java:225)

        at com.hp.sa.logger.service.SaLogger.startLoggerService(SaLogger.java:28)

        at com.hp.sa.logger.service.LoggerService.start(LoggerService.java:24)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:483)

        at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:243)

We are using L0g4j2 (v2.1).

Can you please help me to identify the reason for this error?

--

-- 

Best Regards,
M Sumantha Kannantha
Blaine Bergeson (bbergeson | 17 Jan 09:24 2015

Log level

It seems that when I set the log level in my application it will change the level for all the loggers,
including the root, even though I only called setLevel on one specific loggerConfig. Is that normal?  I
would like to set the log level on a specific logger and have it apply to that logger and all its descendants,
but not all its ancestors up to and including the root.

Blaine 

Sent from my iPhone
Blaine Bergeson (bbergeson | 17 Jan 09:18 2015

Observations about the Context Map and the Header attribute

Here are some things I have observed when trying to use the context map and the header attribute for a
pattern.  Are these bugs or are they suppose to work this way?

  1.   When I try to use the context map values in the header attribute of a patternLayout of a
RollingRandomAccessFile appender the values are not available the first time the log file is created but
they do become available when the log is created as part of a rollover event.  It seems that a rollover must
occur before the context values are available to the header attribute.  Also, if I make the logger and/or
appender async then the values also don’t seem to be available even though I have the location attribute
set to true on the async logger and the async ref appender.
  2.  If I add items to the context map from within a specific class those values will not be available to the Root
logger.  I have to define at least 1 logger that is defined with a portion of the path to the class where the
items were added.  For example if I have a class called com.sample.MyClass then any items I add to the
context map will be available to a logger defined as at least com, but the Root Logger and any appender used
by the Root logger will not see them.
  3.  It appears that the header attribute value can’t use any of the formatting or substitution features,
i.e. it has to be an exact string.  This means that to enter the date, time, or just a  newline I have to add it to
the end of the string that is entered in the context map in the application rather than just adding it in the
configuration file.
  4.  When the appender is stdout it won’t display the header attribute value.

Blaine

Sent from my iPhone

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe <at> logging.apache.org
For additional commands, e-mail: log4j-user-help <at> logging.apache.org


Gmane