0
votes

logj4 is what our app needs to use in order to create file logs, due to the way our server now handles generic systemout logging.

The Apache manual on logj4 ( http://logging.apache.org/log4j/1.2/manual.html )is pretty through in how to create a framework for logj4, but after putting this framework into my app, I find that the appender doesn't ever get implemented - I can log things to the console just fine, but I have no idea how to set up logging to an appender.

I'm clearly missing something, but I have no idea what because I've never set up a logj4 appender before. My supsicion is that I have to declare the usage in-app, but the Apache manual page doesn't show how to declare an appender in a Java class, so either I'm missing that part of the instruction, or trying to implement this incorrectly.

My log4j is set up, essentially, as seen in the Apache manual page, and partially based off of these two blog posts http://www.developer.com/open/article.php/3097221/Logging-with-log4jmdashAn-Efficient-Way-to-Log-Java-Applications.htm http://veerasundar.com/blog/2009/07/log4j-tutorial-adding-log4j-logging-to-your-project/

My assumption here is that the following line is NOT sufficient for implementing the appender (logger is already declared at the beginning of my java class):

logger.info("This is a successful log NUMBER NINE THOUSAAAAND");

So what additional steps (assuming I have the framework properly installed) do I need to take to implement the appender when using logj4?

EDIT: As requested, here is what my .properties file looks like, with actual file names and server extensions edited for security.

#define the console appender
log4j.appender.consoleAppender = org.apache.log4j.ConsoleAppender

# now define the layout for the appender
log4j.appender.consoleAppender.layout=full.server.extension.framework.logging.CustomLoggingPatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%p:%d{dd MMM yyyy HH:mm:ss,SSS}:%c() %m

# now map our console appender as a root logger, means all log messages will go to this appender
log4j.rootLogger = DEBUG, consoleAppender


log4j.logger.LoggingFramework=INFO,LogFramework 
log4j.appender.LogFramework=org.apache.log4j.RollingFileAppender
log4j.appender.LogFramework.File=/applogs/appname/appnameLogs.log
log4j.appender.LogFramework.MaxFileSize=1MB
log4j.appender.LogFramework.MaxBackupIndex=10
log4j.appender.LogFramework.layout=us.ny.state.labor.framework.logging.CustomLoggingPatternLayout
log4j.appender.LogFramework.layout.ConversionPattern=%p:%d{dd MMM yyyy HH:mm:ss,SSS}:%c() %m

log4j.rootLogger = INFO, rollingFile
1

1 Answers

0
votes

You can only have one rootLogger defined. I'm guessing you are trying to log to both the file and console. In which case you'll want the following:

log4j.rootLogger=DEBUG,consoleAppender,LogFramework

See this question:

how to make log4j to write to the console as well