在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.logger创建# 输出到标准输出 logger = Logger.new(STDERR) logger = Logger.new(STDOUT) # 输出到指定文件 logger = Logger.new('logfile.log') # 输出到指定打开/创建模式的文件 file = File.open('foo.log', File::WRONLY | File::APPEND | File::CREAT) # To create new (and to remove old) logfile, add File::CREAT like: # file = File.open('foo.log', File::WRONLY | File::APPEND | File::CREAT) logger = Logger.new(file) # 指定日志大小及保留日志个数 logger = Logger.new('foo.log', 10, 1024000) # 日志生成周期
2.设置日志级别logger.level = Logger::DEBUG logger.level = Logger::INFO logger.level = Logger::WARN logger.level = Logger::FATAL logger.level = Logger::UNKNOWN
3.设置日志输出格式# datetime_format=时间格式化 logger.datetime_format = '%Y-%m-%d %H:%M:%S' # formatter=方法改变整体格式 logger.formatter = proc do |severity, datetime, progname, msg| "#{datetime}: #{msg}\n" end
4.日志打印logger.info("User-input: #{input.dump}") logger.info("User-input: %p" % input) logger.info "Waiting for input from user" logger.info { "User typed #{input}" }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论