log4j

Programmatically creating different log files using log4j

I have an automated integration test harness and would like to streamline the logging (which is implemented using log4j) I have a number of high-level tests, each with an id and require a separate log file per test. As the tests are created randomly the ids are not known until runtime. Therefore I would like to ensure that logging wit...

Configuring Grails to mail all exceptions generated in the production environment

Question: How do I configure Grails to send an e-mail with all log4j error messages (including exceptions) generated in the production environment? Worth noting: This question pertains to Grails 1.1, the solution for Grails 1.0 is described here. ...

How to enable Logger.debug() in Log4j

While trying to execute the following lines only the last two statements are displayed("Here is some ERROR" and "Here is some FATAL") and the first three statements are not displayed.I had just started to learn this topic, can anyone tell why is this happening? logger.debug("Here is some DEBUG"); logger.info("Here is some INFO")...

Log4J not providing correct source info.

I am using log4j for traces. I am using the following pattern for my trace: <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{dd-MM HH:mm:ss.SSS} | %X{sid} | [%t] | %F:%M:%L | %-5p | %m%n"/> </layout> In some classes I expect to get: [11/4/09 17:03:57:160 IST] 00000012 SystemOut O 04-11...

logging using Log4j

We are using Log4j in our project for logging. I want to log some statements for some of the classes without showing any extra information except from the content, e.g.: Currently it is like this, if log level is INFO: 05/11/2009 16:54:13 INFO TemplateManagerImpl - Templates in cache:1 I want only the information below, irrespe...

Log4J Custom Fields

Introduction: I'm trying to get additional fields to log with log4j, and its working but only when I create an appender in code and not in the log4j.properties Progress: Used this article Adding Conversion Characters to PatternLayout for log4j 1.1.3 Made a sample app for log4j 1.2 Problem: using the properties file it will run but...

What do you think about returning the logging sentence

I have this java code: if(isNull(office) || isNull(pricelist)) { log.warn("The document {0}-{1} is not valid.",codDoc,numDoc); return null; } Do you think it is ok if I rewrite it as: if(isNull(office) || isNull(pricelist)) return log.warn("The document {0}-{1} is not valid.",codDoc,numDoc); That way public void warn...

Removing access to System.out in java

I maintain an application which acts as a container for multiple individual programs. These programs have their own dedicated logging facility, i.e. everything they log does to a special log file. Nevertheless, application developers seem to love to throw System.out.println and e.printStackTrace calls all over, making it impossible to m...

Trimming down log output using log4j

How can I achieve the following using log4j: log only events coming from a specific category , i.e. com.example.app but not com.example.app.context or com.example.dao; log all events with a level of WARN or higher. ...

log4j: rotating log files based on time rather than size

I use log4j with the "RollingFileAppender" to create a log rotation based on a certain size per file. How can I configure it to log to each file for a certain amount of time before rotating? For example, so that each log file contains one hour of logs, rotating at the top of each hour? BTW, I configure log4j programatically in Java us...

How do you Change a Package's Log Level using Log4j?

I've encountered the following bug: http://issues.apache.org/jira/browse/AXIS2-4363 It states the following: This error only occurs when log level for org.apache.axiom is DEBUG so a workaround is to set log level > DEBUG. My question is HOW do I go about doing that? I've been scouring my directories for a properties file or something...

Configuring com.mysql.jdbc.log.Log4JLogger for multiple data sources

I've configured the MySQL connector for Java to report metrics using: logger=com.mysql.jdbc.log.Log4JLogger&gatherPerfMetrics=true&reportMetricsIntervalMillis=60000 That works just fine for one data source, but when I have three there is no way to distinguish them, since they all look like: 2009-11-13 12:37:05,506 INFO MySQL ** Perfo...

What are the available options to retrieve Spring-managed beans in a Log4J Appender inside a Spring-managed web application?

Hello. My current build lead has a great idea in theory - construct a custom Log4J appender that takes in Spring-managed beans and uses them to log errors to various other sources than just the standard log file. However, other than creating a singleton initialized at startup with the application context (code in just a moment), I can'...

How to validate Java logging properties files?

I have a basic facility for allowing users to remotely apply changes to the logging files in my application. Some logs are configured using java.util.logging properties files, and some are configured using log4j/log4cplus-style properties files. I'd like to do some basic validation of the properties that users try to apply. Namely, I ...

log4j logging to DB (in a cluster)

Hi, I have a Java application wich runs on two machines in a cluster and they both log to one mysql database. Everything works fine, but I would like to have an additional field in the database wich represents the IP where the requests is coming from. I solved this by having two different log4j.properties files, but I guess there is a ni...

Logging user agent info on login with Spring Security

Hi, I am using Spring Security with LDAP for an application and I want to log the user-agent when the user logs in. However, I cannot access the request object in the Authorities Populator so I cannot access the user-agent information from there. I also tried setting the pattern in our logger (log4j) so it would log the user agent by ...

Overriding log4j settings at deploy time

For an application which is deployed on a large number of machines I took the decision to deploy a standard log4j.xml file with the application package, just to make sure that have the same settings are present everywhere : appenders, categories, levels. This does have the downside that when modifying the levels locally we risk losing t...

Creating daily logs with Log4j?

What configuration values are needed to setup Log4j to use the following pattern? MyApp-Mon.log MyApp-Tue.log MyApp-Wed.log Etc With each file containing the days log. This sounds easy enough to do with Log4j's DailyRollingFileAppender but I am having trouble. Here is my current config; <appender name="daily-file" class="org.apache.lo...

Grails log4j configuration

Hi, I've repeatedly had problems with the DSL introduced by Grails in version 1.1 for configuring Log4J. My current configuration looks like this: log4j = { debug 'com.mypackages' appenders { console name: 'stdout', layout: pattern(conversionPattern: '%d{dd-MM-yyyy HH:mm:ss,SSS} %5p %c{1} - %m%n') rolli...

java wrapper around log4j logger and java.util.logging

I am writing a library. The library can be used by applications that use log4j loggers and java.util.logging loggers. So, I wrote a quick wrapper class, that encapsulates both loggers. I allow the application to set one or both loggers. And in my library I use the encapsulated class to print to either logger. My question is, since many...