Advertisement
kwandes

Logging configuration

Sep 9th, 2020
2,442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Logback config is stored in the application.properties file, along with other springboot properties
  2. The syntax is very simple but your control is very limited
  3. server.port=5000
  4. # Database connection
  5. spring.datasource.url=${TREECREATE_JDBC_URL}
  6. spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  7. # Session
  8. spring.session.store-type=jdbc
  9. spring.session.jdbc.initialize-schema=always
  10. # How long does a session last without activity, in seconds
  11. spring.session.timeout=900
  12. # Logging with a roll over every day
  13. logging.file.name=logs/treecreate.log
  14. logging.pattern.rolling-file-name=logs/treecreate-%d{yyyy-MM-dd}.%i.log.gz
  15. logging.file.max-size=100MB
  16. logging.file.total-size-cap=2GB
  17. logging.file.max-history=60
  18.  
  19.  
  20. LOG4j2 config in a log4j2.properties file
  21. Offers far more control but is a bit harder to configure
  22. # basic properties
  23. name=LoggerProperties
  24. property.filename = logs
  25. appenders = console, discord, rolling
  26.  
  27. # Console output
  28. appender.console.type = Console
  29. appender.console.name = Console
  30. appender.console.layout.type = PatternLayout
  31. appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
  32.  
  33. # Rolling File output. Rollover occurs on every 7th day ()
  34. appender.rolling.type = RollingFile
  35. appender.rolling.name = RollingFile
  36. appender.rolling.fileName = ${filename}/program.log
  37. appender.rolling.filePattern = ${filename}/%d{yyyy-MM-dd}.log.gz
  38. appender.rolling.layout.type = PatternLayout
  39. appender.rolling.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
  40. appender.rolling.policies.type = Policies
  41. appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
  42. appender.rolling.policies.time.interval = 7
  43. appender.rolling.policies.time.modulate = true
  44. appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
  45. appender.rolling.policies.size.size=5MB
  46. appender.rolling.strategy.type = DefaultRolloverStrategy
  47. appender.rolling.strategy.max = 5
  48.  
  49. # Discord error logging
  50. appender.discord = dev.hotdeals.bob_the_discord_bot.Service.DiscordAppender
  51. appender.discord.name = DiscordAppender
  52. appender.discord.type = DiscordAppender
  53.  
  54. logger.rolling.name = dev.hotdeals.bob_the_discord_bot
  55. logger.rolling.level = debug
  56. logger.rolling.additivity = true
  57. logger.rolling.appenderRef.rolling.ref = RollingFile
  58.  
  59. rootLogger.level = debug
  60. rootLogger.appenderRefs = console, discord
  61. rootLogger.appenderRef.stdout.ref = Console
  62. rootLogger.appenderRef.discord.ref = DiscordAppender
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement