Class: Relaton::Logger::Log
- Inherits:
-
Logger
- Object
- Logger
- Relaton::Logger::Log
- Defined in:
- lib/relaton/logger/log.rb
Instance Attribute Summary collapse
-
#levels ⇒ Object
Returns the value of attribute levels.
Instance Method Summary collapse
-
#add(severity, message = nil, progname = nil, **args) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
- #add_level(level) ⇒ Object
- #format_message(severity, datetime, progname, msg, **args) ⇒ Object
-
#initialize(logdev, shift_age = 0, shift_size = 1_048_576, **args) ⇒ Log
constructor
rubocop:disable Lint/MissingSuper.
- #remove_level(level) ⇒ Object
- #truncate ⇒ Object
- #unknown(message = nil, progname = nil, **args, &block) ⇒ Object
Constructor Details
#initialize(logdev, shift_age = 0, shift_size = 1_048_576, **args) ⇒ Log
rubocop:disable Lint/MissingSuper
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/relaton/logger/log.rb', line 5 def initialize(logdev, shift_age = 0, shift_size = 1_048_576, **args) # rubocop:disable Lint/MissingSuper self.levels = args.delete(:levels) || [UNKNOWN, FATAL, ERROR, WARN, INFO] self.level = @levels.min self.progname = args.delete(:progname) @default_formatter = FormatterString.new self.datetime_format = args.delete(:datetime_format) self.formatter = args.delete(:formatter) self.formatter = self.formatter.new if self.formatter.is_a? Class @logdev = nil @level_override = {} if logdev && logdev != File::NULL @logdev = LogDevice.new(logdev, shift_age: shift_age, shift_size: shift_size, **args) end end |
Instance Attribute Details
#levels ⇒ Object
Returns the value of attribute levels.
3 4 5 |
# File 'lib/relaton/logger/log.rb', line 3 def levels @levels end |
Instance Method Details
#add(severity, message = nil, progname = nil, **args) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/relaton/logger/log.rb', line 42 def add(severity, = nil, progname = nil, **args) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity severity ||= UNKNOWN return true if @logdev.nil? || !@levels.include?(severity) if block_given? progname ||= || @progname = yield else progname ||= @progname end @logdev.write (format_severity(severity), Time.now, progname, , **args) true end |
#add_level(level) ⇒ Object
25 26 27 28 |
# File 'lib/relaton/logger/log.rb', line 25 def add_level(level) @levels << Severity.coerce(level) self.level = @levels.min end |
#format_message(severity, datetime, progname, msg, **args) ⇒ Object
56 57 58 |
# File 'lib/relaton/logger/log.rb', line 56 def (severity, datetime, progname, msg, **args) (@formatter || @default_formatter).call(severity, datetime, progname, msg, **args) end |
#remove_level(level) ⇒ Object
30 31 32 33 |
# File 'lib/relaton/logger/log.rb', line 30 def remove_level(level) @levels.delete Severity.coerce(level) self.level = @levels.min end |
#truncate ⇒ Object
60 61 62 |
# File 'lib/relaton/logger/log.rb', line 60 def truncate @logdev.truncate end |
#unknown(message = nil, progname = nil, **args, &block) ⇒ Object
35 36 37 38 |
# File 'lib/relaton/logger/log.rb', line 35 def unknown( = nil, progname = nil, **args, &block) level = Object.const_get "Logger::#{__callee__.to_s.upcase}" add(level, , progname, **args, &block) end |