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
(Continue reading)

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)

(Continue reading)

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

Blaine Bergeson (bbergeson | 15 Jan 18:54 2015

Getting Started

Hi,

I am just getting started using Log4j2 and after pouring over the documentation which is pretty good I would
still like some assurance that I am heading the right direction.  I feel like my use case is the most
fundamental case but there must be a slicker way than how I am implementing it.

I only need one log file for my entire application(isn't this true for most applications?); therefore I am
using the root logger with the level set at info, and 1 Async RollingRandomAccessFile appender.  My
understanding of logging up to this point has been, add logging statements all over the place using
entry(), exit(), debug(), info(), etc.,  and then based upon the type of user that is using the
application, programmatically change the logging level so that the correct events are allowed to be
logged for that type of user.  Outside of wanting to use a different pattern or appender based  upon some
criteria, other than the level, why wouldn't you always want to do it this way?  It seems like the
configuration file is just used to define the destinations and patterns based upon some critiera, but the
most basic typical use case is to change the log level based upon a user or mode of the application.  Another
words as far as the logging level is concerned it seems like the configuration file just contains some
default value but then in my code I have to get the context, then get the configuration, then get the root
logger config, set the new log level, and finally update all the loggers every time I want to change what is
logged based upon some mode or user.  I can pass the user name or mode to the configuration by way of the
context map but then what do I put in the configuration to allow certain events to be logged if it is a certain
log level or more specific?

For example given the following user types I would the logging level to change, and the user type can change
at any time while the application is running:

General User:  log level should be ERROR so error and more specific events are logged
Support User: log level should be INFO so info and more specific events are logged
Advanced User: log level should be DEBUG so debug and more specific events are logged
Developer:  log level should be TRACE so trace and more specific events are logged

(Continue reading)

M Sumantha Kannantha | 14 Jan 03:49 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)
(Continue reading)

ppiman | 8 Jan 06:02 2015
Picon

Log4j2 - Custom HTML Layout footer not getting called to end the log file

Hello,

I've run into a problem that I just can't figure out and I'm hoping you
will be able to help me.

My goal is to have log4j keep adding to the log file and at some point be
able called the log url address and my app display the log file on the fly
with out stopping the app or undeploying it.

So here goes:

I'm trying to do a log file for a web app. My app is JSF 2 (xhtml). I've
got my custom HTML Layout  that I extend from AbstractStringLayout. (Reason
I made custom HTML Layout was with XHTML this line in the log4j HTMLLayout
was throwing an error:  sbuf.append("<hr size=\"1\" noshade">") and XHTML
wants an <hr size=\"1\" noshade=\"noshade\">)

Now when I run my app, the log is generated and everthing is working except
the getFooter() method never gets called to finish the table and file.
Which when I call the URL to the log file I get a error saying the document
structure is not complete.

log4j2.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" packages="com.qualcomm.asictracker.util">
    <Properties>
        <Property name="log-path">${web:rootDir}/WEB-INF/logs</Property>
    </Properties>
    <Appenders>
(Continue reading)


Gmane