I have a Tomcat webapp that uses Log4j logging and is configured via a log4j.properties file. I'd rather it were configured via an xml file, which I understand better, but I don't have the time or inclination to change it.
The root logger is set up this way:
log4j.rootLogger=info, stdout
This is what I want, with one exception: A class I recently started using (AmazonHttpClient) is spewing out way too many INFO logs, and I want to restrict just that class to WARN level only, without changing anything else.
How do I do it?
I thought this would work, but it doesn't:
log4j.rootLogger.com.amazonaws.http.AmazonHttpClient=WARN
I also tried all of these:
log4j.logger.com.amazonaws.http.AmazonHttpClient=WARN
log4j.rootLogger.AmazonHttpClient=WARN
log4j.logger.AmazonHttpClient=WARN
What's the answer?
Related
I am adding a new appender and calling org.apache.log4j.PropertyConfigurator.configure(). However, this seems to override the default databricks logging and I can no longer see the logs as normal from driver-logs or executor logs view.
I think databricks probably use some FileAppender. How could I add new appender while keeping existing databricks ones please?
Don't call org.apache.log4j.PropertyConfigurator.configure yourself to extend the built-in logging configuration. Rather, do it by defining an arbitrarily-named log4j.properties file in the /databricks/spark/conf/ directory. (reference) Also, you might need to use an init-script to ensure that the file is added to all nodes in the cluster.
How can I redirect all the JSF error log messages to a log file? Currently it is being written to a SystemOut.log file.
I tried to change the System.out to a custom PrintStream which will write to a log file and it is logging the system out statements to the log file. But the JSF error messages are still being written to the SystemOut.log file.
Mojarra uses the java.util.logging logger. So all you need to do is to supply or change the logging.properties file in the runtime classpath. You can if necessary override/specify the properties file location using the VM argument -Djava.util.logging.config.file.
Another way is to configure it at the servletcontainer level. It's unclear which one you're using, but the exact filename SystemOut.log is typical for among others WebSphere. You can instead also just configure tracing/logging in its admin console.
I wrote a log parser that constantly reads the log file gets specific lines from the log and writes them into database. Logs are generated via LOG4J. Logs are being rotated when they reach specific size. My problem is that my log parser process is not allowing log4j to rotate the logs.
Can you please advice on this.
Regards.
A cleaner solution would be to use org.apache.log4j.jdbc.JDBCAppender for the log statements that you want in the database, and have log4j insert them directly.
Please help me with this query in using log4net.
I am using log4net in mhy we application. I am facing issues in configuring log4net to log errors at user level.
That is, If user X logs in, I like to create file name X and all error for user X should be written in X.log. Siilarly if Y user logs in the log file should be in name of Y.log and the most important point to note is, they could log in concurrently.
I tried the luck by creating log files whose name would be framed dynamically as soon as the user logs in. But issue here, if they are not using the application at the same time, the log files are creeated with correct name and writing as expected, but if both users have active sessions, log file is created only for user who FIRST logged in and error of second user has been recorded in log file that is created for FIRST user.
Please help me in this.
There has to be a better solution from this one, but you can change log4net configuration from code and even decide which config file to load - so you can do it in code, which is not as nice as editing an XML file.
so what you need to do, which is highly not recommended, is to create log4net configuration each time you call the logger static class, and do what needed based on the calling user.
again.. it doesn't feel right !
(and it will probably perform poorly).
another BETTER solution is to log everything to database (log4net supports it), with a user column, and then produce the logs from db....
We have multiple log files like database log, weblog, quartzlog in our application.
Any log from files under package /app/database will go to database log.
Any log from files under package /app/offline will go to quartzlog log.
What we need now is - want to direct the log staments from one of the java file under /app/database to be outputted to quartzlog instead of database log.
How can we select a particular log file in java file?
You need to define the appropriate appender that logs in the desired file. Read this short introduction to see how you can do it.
Then in the configuration file, you can instruct all messages from a specific package to go in the selected appender:
log4j.logger.my.package = DEBUG, myFileAppender
EDIT:
I believe that in log4j only package resolution is possible - you can't use an appender per file or method. You could try to work around this by adding an extra layer on top of log4j or implementing your own appender.
For example, instead of log.debug use:
my.loggerproxy.log.debug(message);
If you only need to do it from a single method, then the above will be enough. Just instruct the logger proxy package to be logged in a different file.