Karaf 4.2.4 - Logging from class to file gets rid of all logging to STDOUT

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Karaf 4.2.4 - Logging from class to file gets rid of all logging to STDOUT

abdelb
This post was updated on .
I want to capture logs (level: INFO) from a class to a file, but when I do
this, the STDOUT logs no longer appear in Karaf.

Is there a way to capture STDOUT logs from a bundle to a file? The logging
comes from a library used in the bundle. Why do they no longer appear?

My log4j2 is below:

/# Logger for recording BBGVCON trade messages
log4j2.logger.myApp.name = myApp.myClass
log4j2.logger.myApp.level = INFO
log4j2.logger.myApp.additivity = false
log4j2.logger.myApp.appenderRef.myAppDailyRollingFile.ref =
myAppDailyRollingFile
log4j2.appender.myApp.type = RollingFile
log4j2.appender.myApp.name = myAppDailyRollingFile
log4j2.appender.myApp.fileName = /logs/${environment}/INFO.txt
log4j2.appender.myApp.filePattern =
/var/mw/logs/${environment}/INFO.txt.%d{dd-MM-yyyy}
log4j2.appender.myApp.append = true
log4j2.appender.myApp.layout.type = PatternLayout
log4j2.appender.myApp.layout.pattern = %m%n
log4j2.appender.myApp.policies.type = Policies
log4j2.appender.myApp.policies.time.type = TimeBasedTriggeringPolicy
log4j2.appender.myApp.policies.time.interval = 1
log4j2.appender.myApp.policies.time.modulate = true/

Thanks!



--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
Reply | Threaded
Open this post in threaded view
|

Re: Karaf 4.2.4 - Logging from class to file gets rid of all logging to STDOUT

jbonofre
Hi,

You mean that you have System.out.println statements in the bundle right ?

If you start with bin/karaf, this output will go on the shell.

If it’s not possible to « pipe » directly stdout to a log file with log4j2 (or eventually we can create a custom appender for that), in Karaf you can set KARAF_REDIRECT in bin/setenv.
Then stdout and stderr with be catched and sent to a file.

It’s especially interesting when you start karaf with bin/start.

If you start Karaf with the wrapper, then, the wrapper send stdout/stderr to a file as well.

Regards
JB

> Le 10 févr. 2020 à 03:02, abdelb <[hidden email]> a écrit :
>
> I want to capture logs (level: INFO) from a class to a file, but when I do
> this, the STDOUT logs no longer appear in Karaf.
>
> Is there a way to capture STDOUT logs from a bundle to a file? The logging
> comes from a library used in the bundle. Why do they no longer appear?
>
> My log4j2 is below:
>
> /# Logger for recording BBGVCON trade messages
> log4j2.logger.myApp.name = myApp.myClass
> log4j2.logger.myApp.level = INFO
> log4j2.logger.myApp.additivity = false
> log4j2.logger.myApp.appenderRef.myAppDailyRollingFile.ref =
> myAppDailyRollingFile
> log4j2.appender.myApp.type = RollingFile
> log4j2.appender.myApp.name = myAppDailyRollingFile
> log4j2.appender.myApp.fileName = /var/mw/logs/${environment}/INFO.txt
> log4j2.appender.myApp.filePattern =
> /var/mw/logs/${environment}/INFO.txt.%d{dd-MM-yyyy}
> log4j2.appender.myApp.append = true
> log4j2.appender.myApp.layout.type = PatternLayout
> log4j2.appender.myApp.layout.pattern = %m%n
> log4j2.appender.myApp.policies.type = Policies
> log4j2.appender.myApp.policies.time.type = TimeBasedTriggeringPolicy
> log4j2.appender.myApp.policies.time.interval = 1
> log4j2.appender.myApp.policies.time.modulate = true/
>
> Thanks!
>
>
>
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html