Hello Wim,
On Saturday, 10 March 2012 00:46:43 UTC+9, Wim Deblauwe wrote:
How
do I specify where that the log4j logger should output the logging if I
don't load a log4j.properties file, but just configure it in code?
I think I do not properly understand this question. Basically speaking: Loading the properties file does not do anything different but calling properties in code.
This means a properties file like:
log4j.rootLogger=WARN, FILE
could be written in AS3 like
import org.as3commons.logging.setup.log4j.log4j;
log4j.rootLogger = "WARN, FILE";
You can load the air target by its class name:
log4j.appender.FILE = org.as3commons.logging.setup.target.AirFileTarget
unfortunately right now there is no public property to the "path" in the AirFileTarget so I (someone) would need to add it (not as easy as it sounds).
log4j.rootLogger=WARN, FILE
# Set root logger level to WARN
log4j.appender.FILE=org.apache.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.FILE.File=air-app-logging.log
log4j.appender.FILE.MaxFileSize=10MB
log4j.appender.FILE.MaxRollFileCount=20
log4j.appender.FILE.DatePattern=.yyyy-MM-dd
log4j.appender.FILE.CompressionAlgorithm=GZ
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{DATE} [%t] %-5p %c{4} %x - %m%n
log4j.appender.FILE.BufferedIO=false
log4j.logger.com.mycompany=DEBUG
Will this be parsed ok ? What if I use 'org.apache.log4j.FileAppender' instead ? If this works, on what location will the log file 'air-app-logging.log' be saved ?
It will be parsed just fine but it will not work. (as3commons is not in the business of throwing exceptions, errors will be logged). The log4j implementation is
referring to the syntax not the existing adapters (again: Time is my enemy). So: you can reference/generate the existing Appenders (targets) as explained in the asdocs.
Since there is no "TimeAndRolling" equivalent in as3commons-logging it will not work. Here is a simple example of a log4j properties file for as3commons:
log4j.rootLogger = WARN, TRACE;
log4j.appender.TRACE = org.as3commons.logging.setup.target::TraceTarget
log4j.appender.TRACE.format = {time} {logLevel} - {shortName}{atPerson} - {message}
log4j.logger.com.mycompany=DEBUG
I hope this clarifies the current situation.
yours
Martin.