We used Apache commons logging API for logging (debug,error etc methods), and we had used log4j implementation.
we used LogManager.getCurrentLoggers() from log4j to get all the loggers.
Now we deployed our application in jboss wildfly which uses different logging implementation (Jboss logging) so our code is not working since all our loggers now are from Jboss.
Now either i have to find alternate equivalent of LogManager.getCurrentLoggers() in Jboss or exclude logging subsystem in jboss-deployment-structure.xml.
is there any way to get listofloggers through common logging api? so that my code always works irrespective of the logging implementations?
Related
I am working with embedded undertow and using org.jboss.logging.Logger for logging. I cannot use log4j or slf4j since the application which is gonna use my jar might not be using different version of log4j and there might be some conflicts. And also since undertow already has jobss.logging in-built I do not want to add any dependency to my jar.
So, is there any way I can add the logging level at run time by passing the level as a parameter to a method or constructor?
JBoss Logging is just a logging facade like slf4j. You need a log manager to configure logging. JBoss Logging works with JUL, JBoss Log Manager, log4j, log4j2 and logback. If you don't have a log manager on your class path then JUL will be used.
You can also define which log manager JBoss Logging should attempt to bind using the org.jboss.logging.provider system property. The valid values are:
jboss for the JBoss Log Manager
jdk for JUL
log4j2 for log4j2
log4j for log4j
slf4j for logback
I want to use Log4J2 API, but I want all logs to be processed by java.util.logging (which will use Tomcat implementation). For example it's possible with SLF4J and slf4j-jdk14 library. Is it possible with Log4J2? I've found log4j-jul library, but it seems to work the other way: JUL API will be redirected to Log4J implementation.
I'm aware that it's possible to replace Tomcat logging subsystem with Log4J2, but it seems a fragile solution to me.
Why do you consider using Log4j 2 to handle the logging as fragile? Have you seen http://logging.apache.org/log4j/2.x/log4j-appserver/index.html?
No, Log4j does not provide a bridge to route logging to java.util.logging. You can route the Log4j 2 API to SLF4J and then route that to java.util.logging.
I'm running a web application in a Weblogic server (Im not realy familiar with ).
Via JVM args a log4j config is passed with log level DEBUG to the application.
In the log file I can also find some log entries of DEBUG level.
So far so good.
During debugging I found some calls to logger.debug() that are not in the log file.
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ActionCtr.class);
The method call is definitely hit but nothing is written to a file.
If I do a step into during debugging I see in the logger:
org.slf4j.impl.JDK14LoggerAdapter(com.example.application.ActionCtr)
"java.util.logging.FileHandler.pattern" -> "%h/java%u.log"
And this leads to some questions for me (as I can not change the running application):
1) how could it bee that it uses the application is using a mixed up log4j and java.util.logging
2) How could I determine what is used in what classes?
3) There is no %h/java%u.log (~/java*.log) so I've tried to provide a java.util.logging conform properties file,
but this changed nothing - how an I determine where the running logger got its config from to configure it right?
1) how could it be that it uses the application is using a mixed up log4j and java.util.logging
Any of those logging frameworks could be used by the application directly or a dependent library that the application is using. It doesn't take too many dependencies to end up with a bunch of logging framework hitchhikers.
The SLF4J manual explains how that logging framework wrangles all of these other frameworks. This why you are seeing the org.slf4j.impl.JDK14LoggerAdapter.
How could I determine what is used in what classes?
Assuming you mean direct usages you can use Jdeps or Javap.
how an I determine where the running logger got its config from to configure it right?
The JConsole tool can access the JUL loggers at runtime. It will also show you all of the system properties which may include paths to logging.properties files.
If the application is pragmatically configuring the logging in an non-standard way then one option would be to use the java.security.debug using the access option. Run the application under a security manager will all or all required permissions but then enable access tracing.
I've inherited some java code that uses the JBoss Logging implementation explicitly. I know that this is normally configured as a JBoss Subsytem, and I'm able to observe various log tuning operations just fine when running on the server. However, I'm not getting any log message output for unit tests. I've dropped several configuration files on the test classpath to include:
logging.properties
log4j.xml
log4j2.xml
but have not seen any results. Has anyone been able to configure the JBoss Logging system such that they're visible outside of the container in unit tests? Is this even possible? The logging configuration guide didn't speak to how to do this.
You can make log4j.xml work, but you need to make sure that you have a compatible vanilla log4j version on the test classpath, e.g. 1.2.17, and that you don't have the modified version, log4j-jboss-logmanager, on the the classpath, which doesn't read log4j.xml.
Details.
See https://stackoverflow.com/a/18323126/1341535.
I take this:
I would recommend you configure the log manager using the logging
subsystem provided with the application server. This is the only way
to configure the server logging.
to imply that it's basically impossible to configure the JBoss Log Manager in tests, because there is no server subsystem configuration and nothing to parse it. Maybe you could configure it programmatically, but that's too inconvenient.
So this leaves us using the JBoss Logging facade with log4j for the log manager, which can be easily configured with log4j.xml.
Now, that I think of it, there is a logging.properties file in Wildfly, that configures logging before the logging subsystem is initialized. That means you can configure the JBoss Log Manager with logging.properties, you just need to put the relevant jars on the test classpath, probably jboss-logmanager and log4j-jboss-logmanager.
I will try to test the code using Arquillian Test Cases, it features the possibility to deploy parts of your code only to test it in a "real environment".
It is reccomended in a lot of RH JBoss documentation.
You can try reusing your junit code, and modify them using this guide: http://arquillian.org/guides/getting_started/
I'm not a guru of that technology. I hope it would help you.
I am writing standalone java application which is using Hibernate. Maven brought jboss-logging library for me. I am not using JBoss. The question is: can I log with this library only, or I need to download some logging implementation like log4j?
JBoss Logging is just a logging facade. To configure your loggers, e.g. use/add handlers, you need a log manager like JBoss Log Manager, the J.U.L. log manager, logback or log4j.
JBoss Logging will attempt to discover which log manager is being used. You can specify which log manager you'd like to use with the org.jboss.logging.provider system property. The allowed values for `org.jboss.logging.provider' are:
jboss - for JBoss Log Manager
jdk - For the J.U.L. log manager
log4j - For the log4j log manager
slf4j - For logback with slf4j
Hibernate uses JBoss Logging for it's i18n capabilities, it's vararg logging methods and the ability to not be tied to a log manager.
Of course you can absolutely use JBoss Logging in your project. If you want to configure logging handlers you'd also have to use a log manager as well.
afaik, jboss-logging is more a extra layer on top of normal logging api, to provide more sophisticated feature like i18n etc.
JBoss-logging can use other logging library (e.g. SLF4J) as the underlying handler for log.
I believe if you are writing a simple standalone Java app, you do not need to use JBoss-logging (unless you know you really want and need to do so).
Using SLF4J (with LogBack or Log4J binding) will be a good choice. Visit http://slf4j.org for more information
Make sure you have jboss-logging and your logger implementation in your classpath and set the system property org.jboss.logging.provider to log4j, jdk, slf4j or jboss depending on what you want. In theory autodetection may also work.
https://github.com/jboss-logging/jboss-logging/blob/master/src/main/java/org/jboss/logging/LoggerProviders.java#L29