right_support 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,7 +30,7 @@ module RightSupport::Log
30
30
  # to keep the syslog from having weird characters or being susceptible to log
31
31
  # forgery.
32
32
  class SystemLogger < Logger
33
- LOGGER_LEVELS = {
33
+ SEVERITY_MAP = {
34
34
  UNKNOWN => :alert,
35
35
  FATAL => :err,
36
36
  ERROR => :warning,
@@ -39,10 +39,38 @@ module RightSupport::Log
39
39
  DEBUG => :debug
40
40
  }
41
41
 
42
- SYSLOG_LEVELS = LOGGER_LEVELS.invert
43
- DEFAULT_SYSLOG_LEVEL = :alert
42
+ # Translation table that maps human-readable syslog facility names to
43
+ # integer constants used by the Syslog module. Compiled from the
44
+ # Linux header file 'sys/syslog.h'
45
+ # (see http://linux.die.net/include/sys/syslog.h)
46
+ FACILITY_MAP = {
47
+ 'kern' => (0<<3),
48
+ 'user' => (1<<3),
49
+ 'mail' => (2<<3),
50
+ 'daemon' => (3<<3),
51
+ 'auth' => (4<<3),
52
+ 'syslog' => (5<<3),
53
+ 'lpr' => (6<<3),
54
+ 'news' => (7<<3),
55
+ 'uucp' => (8<<3),
56
+ 'cron' => (9<<3),
57
+ 'authpriv' => (10<<3),
58
+ 'ftp' => (11<<3),
59
+ 'local0' => (16<<3),
60
+ 'local1' => (17<<3),
61
+ 'local2' => (18<<3),
62
+ 'local3' => (19<<3),
63
+ 'local4' => (20<<3),
64
+ 'local5' => (21<<3),
65
+ 'local6' => (22<<3),
66
+ 'local7' => (23<<3),
67
+ }
44
68
 
45
- DEFAULT_OPTIONS = {:split=>false, :color=>false}
69
+ DEFAULT_OPTIONS = {
70
+ :split=>false,
71
+ :color=>false,
72
+ :facility=>'local0'
73
+ }
46
74
 
47
75
  @@syslog = nil
48
76
 
@@ -58,15 +86,18 @@ module RightSupport::Log
58
86
  # split(true|false):: if true, splits multi-line messages into separate syslog entries
59
87
  # color(true|false):: if true, passes ANSI escape sequences through to syslog
60
88
  #
89
+ # === Raise
90
+ # ArgumentError:: if an invalid facility is given
61
91
  def initialize(program_name='ruby', options={})
62
92
  @options = DEFAULT_OPTIONS.merge(options)
63
- @level = Logger::DEBUG
93
+ @level = Logger::DEBUG
64
94
 
65
- facility = options[:facility] || 'local0'
66
- fac_map = {'user'=>8}
67
- (0..7).each { |i| fac_map['local'+i.to_s] = 128+8*i }
95
+ facility = FACILITY_MAP[@options[:facility].to_s]
96
+ if facility.nil?
97
+ raise ArgumentError, "Invalid facility '#{@options[:facility]}'"
98
+ end
68
99
 
69
- @@syslog ||= Syslog.open(program_name, nil, fac_map[facility.to_s])
100
+ @@syslog ||= Syslog.open(program_name, nil, facility)
70
101
  end
71
102
 
72
103
  # Log a message if the given severity is high enough. This is the generic
@@ -139,8 +170,8 @@ module RightSupport::Log
139
170
  # === Return
140
171
  # true:: always returns true
141
172
  def emit_syslog(severity, message)
142
- level = SYSLOG_LEVELS[severity] || DEFAULT_SYSLOG_LEVEL
143
- @@syslog.send(level, message)
173
+ level = SEVERITY_MAP[severity] || SEVERITY_MAP[UNKNOWN]
174
+ @@syslog.__send__(level, message)
144
175
  return true
145
176
  end
146
177
 
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
7
7
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
8
8
 
9
9
  s.name = 'right_support'
10
- s.version = '1.3.2'
11
- s.date = '2012-03-14'
10
+ s.version = '1.3.3'
11
+ s.date = '2012-03-23'
12
12
 
13
13
  s.authors = ['Tony Spataro', 'Sergey Sergyenko', 'Ryan Williamson', 'Lee Kirchhoff']
14
14
  s.email = 'support@rightscale.com'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 2
10
- version: 1.3.2
9
+ - 3
10
+ version: 1.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2012-03-14 00:00:00 -07:00
21
+ date: 2012-03-23 00:00:00 -07:00
22
22
  default_executable:
23
23
  dependencies: []
24
24