Skip to content

Instantly share code, notes, and snippets.

@h1ddengames
Created May 20, 2020 03:45
Show Gist options
  • Save h1ddengames/015bc811b4ad2a0f8f1a2790bead8218 to your computer and use it in GitHub Desktop.
Save h1ddengames/015bc811b4ad2a0f8f1a2790bead8218 to your computer and use it in GitHub Desktop.
Log4j Properties
# Root logger
# console and file are just names.
log4j.rootLogger=INFO, console, file
# Example: [INFO - main] 2020-05-19 20:37:57 xyz.hiddengames.Base.Test:12 - Hello
# %-4p -> INFO (Log Level)
# %t -> main (The calling thread)
# %d{yyyy-MM-dd HH:mm:ss} -> 2020-05-19 20:37:57
# %C.%M:%L -> xyz.hiddengames.TestClass:9 (Calling Class + Method Name + Line Number) (ALL ARE SLOW -- REMOVE IF SPEED IS REQUIRED)
# %l -> xyz.hiddengames.TestClass.loggerTest(TestClass.java:9) (Same as above but slower)
# %m%n -> Hello (Message + newline)
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%-4p - %t] %d{yyyy-MM-dd HH:mm:ss} %C.%M:%L - %m%n
# Direct log messages to a log file
# RollingFileAppender will switch to a new file once the file size goes over the MaxFileSize defined below.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logs/info.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%-4p - %t] %d{yyyy-MM-dd HH:mm:ss} %C.%M:%L - %m%n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment