java - Log4j to write json array to disk -


im creating log file system. log file in json format server can read after dont think thats important. need know can log4j configured write file without tags info,debug, timestamp etc in file. have looked here

but polutes file with other things. want data write show in file. i'd set kind of file rotation on file if gets big after max size reached.

this relatively easy, using log4j.properties configuration file (place @ top of classpath, , log4j 'just find it'):

# default logger, logs console log4j.logger.com.foo.bar=debug,a1 log4j.appender.a1=org.apache.log4j.consoleappender log4j.appender.a1.layout=org.apache.log4j.patternlayout  # note pattern here, emits lot of stuff - btw, don't use in production # %c expensive - see javadoc conversionpattern meaning of # % modifiers: log4j.appender.a1.layout.conversionpattern=%d{mmm dd, hh:mm:ss} [%c{2}] %-5p - %m%n  # logging file can enabled using 1 log4j.logger.com.example=debug, r  log4j.appender.r=org.apache.log4j.rollingfileappender log4j.appender.r.file=/var/log/generic.log log4j.appender.r.maxfilesize=100kb # keep 1 backup file log4j.appender.r.maxbackupindex=1  # minimalist layout can have: 'm'essage emitted # (and \n newline): log4j.appender.r.layout=org.apache.log4j.patternlayout log4j.appender.r.layout.conversionpattern=%m%n 

all classes in com.foo.bar package (and subpackages) log console, in com.example (and below) log /var/log/generic.log.

to emit json, use jackson (com.fasterxml) convert data json object , write out string.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -