BRUNO MELLONI | 3 Apr 17:24 2012
Picon

forcing [root] logging - to a separate appender

I support a server that uses log4j.  Of the many applications on it, a few dump their logs as [root] log4j entries.

I would like to setup a category or even separate appender that allows me to control and/or separate these
bad log entries.  The problem is that I only want to affect things "just at the root", not every single
package in the server.

How would I write such a category or appender configuration?
Denny Lee | 6 Apr 01:43 2012
Picon

Writing binary data to log fine

Hello,
I am having trouble trying to log some binary data to the log file. I wrote an application that receives some
log from a network device in binary format; all the app does is take the output via TCP from the device and
writes it to a file.  I wrote the application on Windows 7 computer using Eclipse and I was able to receive
the log from the network device, writes it to a file and then parse the log file with another program.  But
when I ran the program on Redhat 5.5, I was not able to parse the log and got a bunch of errors.  I tried a
Windows log on the Redhat system and used dos2unix on the file and I was able to parse that log just fine.

Can anyone possibly shed some light on this?  I am not sure where to even begin to troubleshoot this.  Thanks.

Denny
Sean A. | 7 Apr 03:23 2012
Picon

Re: forcing [root] logging - to a separate appender

On 04/03/2012 11:24 AM, BRUNO MELLONI wrote:
> I support a server that uses log4j.  Of the many applications on it, a few dump their logs as [root] log4j entries.
>
> I would like to setup a category or even separate appender that allows me to control and/or separate these
bad log entries.  The problem is that I only want to affect things "just at the root", not every single
package in the server.
>
> How would I write such a category or appender configuration?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe <at> logging.apache.org
> For additional commands, e-mail: log4j-user-help <at> logging.apache.org
>
	You could try implementing you own filter.  Have your class implement 
org.apache.log4j.spi.Filter, and implement the decide() method.  That 
gets passed a LoggingEvent, and you can look at getThreadName for root. 
  From there you'd need to add that filter in your config to whatever 
appender you'd like.
	Hope I understand the issue you're having here.  Maybe you could post 
some example log entries to clarify the problem.

		--Sean
tommmmmm | 10 Apr 12:23 2012
Picon

Log4J doesn't work at all

From: http://hc.apache.org/httpcomponents-client-ga/logging.html
I copy pasted

log4j.rootLogger=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n

log4j.logger.org.apache.http=DEBUG
log4j.logger.org.apache.http.wire=ERROR

Into a file I named log4j.properties that I put into src folder a'ka
<default package>

Didn't work at all.

Then I put this in my class:

System.setProperty("log4j.rootLogger", "INFO, stdout");

System.setProperty("log4j.appender.stdout",
"org.apache.log4j.ConsoleAppender");

System.setProperty("log4j.appender.stdout.layout",
"org.apache.log4j.PatternLayout");

System.setProperty("log4j.appender.stdout.layout.ConversionPattern",
"%5p [%c] %m%n");

(Continue reading)

Michael Erskine | 10 Apr 13:27 2012

Re: Log4J doesn't work at all

I know this might sound daft but is your class actually trying to log anything?
Michael Erskine | 10 Apr 13:40 2012

Re: Log4J doesn't work at all

On 10 April 2012 12:27, Michael Erskine <msemtd <at> googlemail.com> wrote:
> I know this might sound daft but is your class actually trying to log anything?

OK, I see where you're coming from:
http://hc.apache.org/httpcomponents-client-ga/logging.html

...and you would expect the HttpClient to log to the console. I'm not
familiar with HttpClient but I would expect it to work.

Any luck with Commons Logging or Java Logging?

Any luck with Log4J for a simple application?

If you are new to logging and Log4J concepts I recommend starting off
by adding some simple logging to a simple console application (as per
http://logging.apache.org/log4j/1.2/manual.html under the
"Configuration" heading).

You mentioned Tomcat: Getting Log4j working correctly under Tomcat is
a few steps beyond simple! Are you using HttpClient at the server side
under Tomcat or as a standalone client?
Gary Gregory | 10 Apr 13:56 2012
Picon

Re: Log4J doesn't work at all

See http://logging.apache.org/log4j/1.2/manual.html under "Default
Initialization Procedure"

Gary

On Tue, Apr 10, 2012 at 6:23 AM, tommmmmm <tommmmmm <at> gmail.com> wrote:

> From: http://hc.apache.org/httpcomponents-client-ga/logging.html
> I copy pasted
>
> log4j.rootLogger=INFO, stdout
>
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
>
> log4j.logger.org.apache.http=DEBUG
> log4j.logger.org.apache.http.wire=ERROR
>
> Into a file I named log4j.properties that I put into src folder a'ka
> <default package>
>
>
> Didn't work at all.
>
>
> Then I put this in my class:
>
> System.setProperty("log4j.rootLogger", "INFO, stdout");
>
(Continue reading)

tommmmmm | 10 Apr 14:16 2012
Picon

Re: Log4J doesn't work at all

In reply to the questions:

By Michael Erskine
1. I know this might sound daft but is your class actually trying to log
anything?
2. Any luck with Log4J for a simple application?
3. Are you using HttpClient at the server side under Tomcat or as a
standalone client?

1. Yes it does. I use:
PropertyConfigurator.configure("./src/logging/log4j.properties");
And shortly after logger.debug("some test message"); just to test IF the
proprties file was loaded and if it was loaded correctly. Yes it was.

2. logger.debug("some test message"); <- works.

3. Standalone client

By Gary Gregory:
1. See "Default Initialization Procedure"

1. Just in case I added  *log4j.defaultInitOverride=true *Didn't work. Also
IF the configuration file specified by me was somehow overridden, then
 logger.debug("some
test message"); wouldn't work. And it works exactly as specified with
configuration file I provided. I tested it with different levels than just
debug level.
tommmmmm | 10 Apr 15:09 2012
Picon

Re: Log4J doesn't work at all

I did this for a test:
logger.debug("some test message"); // <- DOES get printed.
my_code_here_based_on_HttpClient; // <- should produce tons of logging
output
logger.debug("some test message"); // <- DOES get printed.

So why the middle part doesn't produce any output? Just to recall I am using
log4j.rootLogger=DEBUG, stdout
so it shouldn't matter what and why.

I am really puzzled now. Why the middle part doesn't produce any output?
Jacob Kjome | 10 Apr 15:34 2012

Re: Log4J doesn't work at all


That system property stuff only applies to commons-logging, not Log4j.  Look 
more closely at the instructions [1].

BTW, are you using commons-logging-api.jar?  If so, that's the problem.  You 
need commons-logging.jar.  See the commons-logging release notes [2].

[1] http://hc.apache.org/httpcomponents-client-ga/logging.html
[2] http://commons.apache.org/logging/RELEASE-NOTES.txt

Jake

On Tue, 10 Apr 2012 12:23:55 +0200
 tommmmmm <tommmmmm <at> gmail.com> wrote:
>From: http://hc.apache.org/httpcomponents-client-ga/logging.html
> I copy pasted
> 
> log4j.rootLogger=INFO, stdout
> 
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
> 
> log4j.logger.org.apache.http=DEBUG
> log4j.logger.org.apache.http.wire=ERROR
> 
> Into a file I named log4j.properties that I put into src folder a'ka
> <default package>
> 
> 
(Continue reading)


Gmane