slf4j logging in console instead of file
Just edit your log4j file to be something like this:
log4j.rootLogger=DEBUG, A2
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p %c %x - %m%n
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=/a.log
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-5p %c %x - %m%n
log4j.logger.io.milton=TRACE
If the logger settings arent being applied (ie you're not seeing logs appear in your file) then you probably have another log4j.properties file somewhere in your classpath which is being used instead of this one. Sometimes it can be included in jar files (eek!)
paulochf
Updated on July 09, 2022Comments
-
paulochf almost 2 years
I'm testing Milton WebDAV API and I need to log when some document is opened. I can have it logging on Eclipse's console, but can't make it put the message on a external file.
Found several links here at SO and Google, but none worked. I've spent about 4h in this already. Any guesses?
Here's the situation (tried to format as best as I could):
log4j.properties
# Direct log messages to a log file log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File=/home/paulo/workspace/MiltonTutorial/logs/log.txt log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n # Root logger option log4j.rootLogger=INFO, file
DocumentResource.java
public class DocumentResource implements GetableResource, PropFindableResource, DeletableResource, MoveableResource, CopyableResource, ReplaceableResource, PropPatchableResource, MultiNamespaceCustomPropertyResource { private final static Logger log = LoggerFactory.getLogger(DocumentResource.class); Document doc; (...) @Override public void sendContent(OutputStream out, Range arg1, Map<String, String> arg2, String arg3) throws IOException, NotAuthorizedException, BadRequestException { log.info(">>> File {} opened", doc.getFileName()); out.write(this.doc.getContent()); }
Eclipse's console when execute 'get testfile' on a WebDAV client
08/02/2013 18:03:15 com.ettrema.tutorial.milton.DocumentResource sendContent INFO: >>> File testfile opened
log.txt big content here
Thanks!
-
paulochf about 11 yearsHey Brad! I'm sure that isn't another .properties file anywhere, but I'm going to try your suggestion. =)
-
paulochf about 11 yearsTks for the tip! I'm going to check this out (tomorrow! Today is holiday =)
-
paulochf about 11 yearsYeah,
slf4j-log4j12.jar
is there. -
paulochf about 11 yearsIt keeps logging just messages from
org.hibernate...
,io.milton
is not on the file. -
paulochf about 11 yearsI realized now that your .properties last line references
io.milton
. Shouldn't it reference the DocumentResource.java package?