File: audit_log.rb

package info (click to toggle)
ruby-train 3.13.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,208 kB
  • sloc: ruby: 10,002; sh: 17; makefile: 8
file content (21 lines) | stat: -rw-r--r-- 727 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Train
  class AuditLog
    # Default values for audit log options are set in the options.rb
    def self.create(options = {})
      # Load monkey-patch to disable leading comment in logfiles
      require_relative "logger_ext"

      logger = Logger.new(options[:audit_log_location], options[:audit_log_frequency], options[:audit_log_size])
      logger.level = options[:level] || Logger::INFO
      logger.progname = options[:audit_log_app_name]
      logger.datetime_format = "%Y-%m-%d %H:%M:%S"
      logger.formatter = proc do |severity, datetime, progname, msg|
        {
          timestamp: datetime.to_s,
          app: progname,
        }.merge(msg).compact.to_json + $/
      end
      logger
    end
  end
end