File: severity.rb

package info (click to toggle)
ruby-gelf 3.1.0-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 244 kB
  • sloc: ruby: 1,039; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 2,155 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module GELF
  # There are two things you should know about log levels/severity:
  #  - syslog defines levels from 0 (Emergency) to 7 (Debug).
  #    0 (Emergency) and 1 (Alert) levels are reserved for OS kernel.
  #  - Ruby default Logger defines levels from 0 (DEBUG) to 4 (FATAL) and 5 (UNKNOWN).
  #    Note that order is inverted.
  # For compatibility we define our constants as Ruby Logger, and convert values before
  # generating GELF message, using defined mapping.

  module Levels
    DEBUG   = 0
    INFO    = 1
    WARN    = 2
    ERROR   = 3
    FATAL   = 4
    UNKNOWN = 5
    # Additional native syslog severities. These will work in direct mapping mode
    # only, for compatibility with syslog sources unrelated to Logger.
    EMERGENCY     = 10
    ALERT         = 11
    CRITICAL      = 12
    WARNING       = 14
    NOTICE        = 15
    INFORMATIONAL = 16
  end

  include Levels

  # Maps Ruby Logger levels to syslog levels as SyslogLogger and syslogger gems. This one is default.
  LOGGER_MAPPING = {DEBUG   => 7, # Debug
                    INFO    => 6, # Informational
                    WARN    => 5, # Notice
                    ERROR   => 4, # Warning
                    FATAL   => 3, # Error
                    UNKNOWN => 1} # Alert – shouldn't be used

  # Maps Syslog or Ruby Logger levels directly to standard syslog numerical severities.
  DIRECT_MAPPING = {DEBUG         => 7, # Debug
                    INFORMATIONAL => 6, # Informational (syslog source)
                    INFO          => 6, # Informational (Logger source)
                    NOTICE        => 5, # Notice
                    WARNING       => 4, # Warning (syslog source)
                    WARN          => 4, # Warning (Logger source)
                    ERROR         => 3, # Error
                    CRITICAL      => 2, # Critical (syslog source)
                    FATAL         => 2, # Critical (Logger source)
                    ALERT         => 1, # Alert (syslog source)
                    UNKNOWN       => 1, # Alert - shouldn't be used (Logger source)
                    EMERGENCY     => 0} # Emergency (syslog source)
end