我使用simpleLogger登录我的应用程序。我想每天都有滚动日志,即我想为每天创建一个单独的日志文件。
我在网上搜索过,但是我已经找到了使用log4J和logback https://www.mkyong.com/logging/logback-xml-example/进行搜索的方法(两者都没有在这个项目中使用)
我想知道是否可以使用SLF4执行此操作,或者我必须使用其他日志记录工具来实现此目的。
以下是项目的simplelogger.properties文件
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
org.slf4j.simpleLogger.defaultLogLevel=info
# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.xxxxx=
# Set to true if you want the current date and time to be included in output messages.
# Default is false, and will output the number of milliseconds elapsed since startup.
org.slf4j.simpleLogger.showDateTime=true
# The date and time format to be used in the output messages.
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
# If the format is not specified or is invalid, the default format is used.
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS
# Set to true if you want to output the current thread name.
# Defaults to true.
org.slf4j.simpleLogger.showThreadName=false
# Set to true if you want the Logger instance name to be included in output messages.
# Defaults to true.
#org.slf4j.simpleLogger.showLogName=true
# Set to true if you want the last component of the name to be included in output messages.
# Defaults to false.
#org.slf4j.simpleLogger.showShortLogName=false
org.slf4j.simpleLogger.levelInBrackets=true
答案 0 :(得分:0)
使用slf4j简单记录器无法滚动文件。
Slf4j是一个日志记录抽象,只需包含api jar就可以包含在项目中。您可以自由使用任何日志记录实现,如log4j或logback。他们都有预定义的appender你可以使用。事实上,简单的记录器也是一个只记录到stdout的日志记录实现。
要使用简单的记录器,您可以在项目中包含slf4j-api和slf4j-simple jar。将slf4j-simple jar替换为特定于log4j或logback实现的jar,并将日志配置文件放在类路径中。
阅读https://www.slf4j.org/manual.html以了解您需要包含的确切jar文件。