syslog-logger 1.6.5 → 1.6.6
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.
- data/README.rdoc +11 -12
- data/lib/syslog_logger_env_formatting.rb +6 -11
- data/test/test_syslog_logger.rb +5 -5
- metadata +3 -4
- data/lib/syslog_logger.rb +0 -116
data/README.rdoc
CHANGED
@@ -4,24 +4,24 @@ http://github.com/ngmoco/sysloglogger
|
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
|
-
|
8
|
-
with a few caveats. You can add
|
7
|
+
Logger::Syslog is a Logger replacement that logs to syslog. It is almost drop-in
|
8
|
+
with a few caveats. You can add Logger::Syslog to your Rails production
|
9
9
|
environment to aggregate logs between multiple machines.
|
10
10
|
|
11
|
-
NOTE! You can only set the
|
12
|
-
|
11
|
+
NOTE! You can only set the Logger::Syslog program name and facility when you initialize
|
12
|
+
Logger::Syslog for the first time. This is a limitation of the way Logger::Syslog
|
13
13
|
uses syslog (and in some ways, a limitation of the way syslog(3) works).
|
14
|
-
Attempts to change
|
14
|
+
Attempts to change Logger::Syslog's program name or facility after the first initialization
|
15
15
|
will be ignored.
|
16
16
|
|
17
|
-
This particular
|
17
|
+
This particular Logger::Syslog improves the original by correctly mapping Rails log severities to
|
18
18
|
the Syslog counterparts. It also adds the ability to select a syslog facility other than "user."
|
19
19
|
|
20
20
|
== SYNOPSIS:
|
21
21
|
|
22
22
|
=== config/environment.rb
|
23
23
|
|
24
|
-
config.gem '
|
24
|
+
config.gem 'syslog-logger'
|
25
25
|
|
26
26
|
=== Gemfile
|
27
27
|
|
@@ -31,13 +31,12 @@ the Syslog counterparts. It also adds the ability to select a syslog facility o
|
|
31
31
|
|
32
32
|
(Only this environment, since you probably only want to enable it for Production, and not Test or Development.)
|
33
33
|
|
34
|
-
|
35
|
-
RAILS_DEFAULT_LOGGER = SyslogLogger.new
|
34
|
+
RAILS_DEFAULT_LOGGER = Logger::Syslog.new
|
36
35
|
|
37
|
-
By default,
|
38
|
-
changed via the arguments to
|
36
|
+
By default, Logger::Syslog uses the program name 'rails' and the facility 'user', but this can be
|
37
|
+
changed via the arguments to Logger::Syslog.new:
|
39
38
|
|
40
|
-
RAILS_DEFAULT_LOGGER =
|
39
|
+
RAILS_DEFAULT_LOGGER = Logger::Syslog.new('mygreatapp', Syslog::LOG_LOCAL7)
|
41
40
|
|
42
41
|
=== BSD syslog setup
|
43
42
|
|
@@ -11,7 +11,7 @@
|
|
11
11
|
# logger.error {"Something is messed up!"}
|
12
12
|
# #=> [development] [ERROR: 2008-01-25 14:16:12.12345] [123] [ClassName] Something is messed up!
|
13
13
|
|
14
|
-
class
|
14
|
+
class Logger::Syslog
|
15
15
|
|
16
16
|
# short names for "DEBUG", "INFO", ...
|
17
17
|
# must be ordered to correspond to severity constants defined in
|
@@ -21,18 +21,13 @@ class SyslogLogger
|
|
21
21
|
|
22
22
|
@@log_level_names = %w( DEBUG INFO WARN ERROR FATAL UNKNOWN )
|
23
23
|
LOG_NAME_FIELD_WIDTH = 7
|
24
|
-
|
24
|
+
|
25
25
|
def add_with_formatting(severity, message = nil, progname = nil, &block)
|
26
26
|
severity ||= Logger::UNKNOWN
|
27
|
-
message = "[#{RAILS_ENV}] [#{@@log_level_names[severity].ljust(LOG_NAME_FIELD_WIDTH)}: #{time.strftime("%Y-%m-%d %H:%M:%S")}.#{time.usec.to_s.rjust(6, '0')}] #{message}"
|
27
|
+
message = "[#{RAILS_ENV}] [#{@@log_level_names[severity].ljust(LOG_NAME_FIELD_WIDTH)}: #{time.strftime("%Y-%m-%d %H:%M:%S")}.#{time.usec.to_s.rjust(6, '0')}] #{message || block.call}"
|
28
28
|
|
29
|
-
|
30
|
-
add_without_formatting(severity, message, progname,
|
31
|
-
&Proc.new{g_log_formatter(severity, nil, user, &block)})
|
32
|
-
else
|
33
|
-
add_without_formatting(severity, message, progname)
|
34
|
-
end
|
29
|
+
add_without_formatting(severity, message, progname)
|
35
30
|
end
|
36
31
|
alias_method_chain :add, :formatting
|
37
|
-
|
38
|
-
end
|
32
|
+
|
33
|
+
end
|
data/test/test_syslog_logger.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'tempfile'
|
3
|
-
require '
|
3
|
+
require 'syslog-logger'
|
4
4
|
|
5
5
|
module MockSyslog; end
|
6
6
|
|
@@ -8,7 +8,7 @@ class << MockSyslog
|
|
8
8
|
|
9
9
|
@line = nil
|
10
10
|
|
11
|
-
|
11
|
+
Logger::Syslog::LOGGER_MAP.values.uniq.each do |level|
|
12
12
|
eval <<-EOM
|
13
13
|
def #{level}(message)
|
14
14
|
@line = "#{level.to_s.upcase} - \#{message}"
|
@@ -29,7 +29,7 @@ class << MockSyslog
|
|
29
29
|
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
Logger::Syslog.const_set :SYSLOG, MockSyslog
|
33
33
|
|
34
34
|
class TestLogger < Test::Unit::TestCase
|
35
35
|
|
@@ -457,7 +457,7 @@ class TestSyslogLogger < TestLogger
|
|
457
457
|
|
458
458
|
def setup
|
459
459
|
super
|
460
|
-
@logger =
|
460
|
+
@logger = Logger::Syslog.new
|
461
461
|
end
|
462
462
|
|
463
463
|
class Log
|
@@ -466,7 +466,7 @@ class TestSyslogLogger < TestLogger
|
|
466
466
|
@line = line
|
467
467
|
return unless /\A(\w+) - (.*)\Z/ =~ @line
|
468
468
|
severity, @msg = $1, $2
|
469
|
-
severity =
|
469
|
+
severity = Logger::Syslog::LOGGER_MAP.invert[severity.downcase.intern]
|
470
470
|
@severity = severity.to_s.upcase
|
471
471
|
@severity = 'ANY' if @severity == 'UNKNOWN'
|
472
472
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 1.6.
|
8
|
+
- 6
|
9
|
+
version: 1.6.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Eric Hodel; Chris Powell; Matthew Boeh; Ian Lesperance; Dana Danger; Brian Smith; Ashley Martens
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-02-13 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -28,7 +28,6 @@ extra_rdoc_files:
|
|
28
28
|
- README.rdoc
|
29
29
|
files:
|
30
30
|
- README.rdoc
|
31
|
-
- lib/syslog_logger.rb
|
32
31
|
- lib/syslog_logger_env_formatting.rb
|
33
32
|
has_rdoc: true
|
34
33
|
homepage: http://github.com/ngmoco/syslog_logger
|
data/lib/syslog_logger.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'syslog'
|
2
|
-
require 'logger'
|
3
|
-
|
4
|
-
class SyslogLogger
|
5
|
-
include Logger::Severity
|
6
|
-
|
7
|
-
# The version of SyslogLogger you are using.
|
8
|
-
VERSION = '1.6.1'
|
9
|
-
|
10
|
-
# From 'man syslog.h':
|
11
|
-
# LOG_EMERG A panic condition was reported to all processes.
|
12
|
-
# LOG_ALERT A condition that should be corrected immediately.
|
13
|
-
# LOG_CRIT A critical condition.
|
14
|
-
# LOG_ERR An error message.
|
15
|
-
# LOG_WARNING A warning message.
|
16
|
-
# LOG_NOTICE A condition requiring special handling.
|
17
|
-
# LOG_INFO A general information message.
|
18
|
-
# LOG_DEBUG A message useful for debugging programs.
|
19
|
-
|
20
|
-
# From logger rdoc:
|
21
|
-
# FATAL: an unhandleable error that results in a program crash
|
22
|
-
# ERROR: a handleable error condition
|
23
|
-
# WARN: a warning
|
24
|
-
# INFO: generic (useful) information about system operation
|
25
|
-
# DEBUG: low-level information for developers
|
26
|
-
|
27
|
-
# Maps Logger warning types to syslog(3) warning types.
|
28
|
-
LOGGER_MAP = {
|
29
|
-
:unknown => :alert,
|
30
|
-
:fatal => :crit,
|
31
|
-
:error => :err,
|
32
|
-
:warn => :warning,
|
33
|
-
:info => :info,
|
34
|
-
:debug => :debug
|
35
|
-
}
|
36
|
-
|
37
|
-
# Maps Logger log levels to their values so we can silence.
|
38
|
-
LOGGER_LEVEL_MAP = {}
|
39
|
-
|
40
|
-
LOGGER_MAP.each_key do |key|
|
41
|
-
LOGGER_LEVEL_MAP[key] = Logger.const_get key.to_s.upcase
|
42
|
-
end
|
43
|
-
|
44
|
-
# Maps Logger log level values to syslog log levels.
|
45
|
-
LEVEL_LOGGER_MAP = {}
|
46
|
-
|
47
|
-
LOGGER_LEVEL_MAP.invert.each do |level, severity|
|
48
|
-
LEVEL_LOGGER_MAP[level] = LOGGER_MAP[severity]
|
49
|
-
end
|
50
|
-
|
51
|
-
# Builds a methods for level +meth+.
|
52
|
-
for severity in Logger::Severity.constants
|
53
|
-
class_eval <<-EOT, __FILE__, __LINE__
|
54
|
-
def #{severity.downcase}(message = nil, progname = nil, &block) # def debug(message = nil, progname = nil, &block)
|
55
|
-
add(#{severity}, message, progname, &block) # add(DEBUG, message, progname, &block)
|
56
|
-
end # end
|
57
|
-
#
|
58
|
-
def #{severity.downcase}? # def debug?
|
59
|
-
#{severity} >= @level # DEBUG >= @level
|
60
|
-
end # end
|
61
|
-
EOT
|
62
|
-
end
|
63
|
-
|
64
|
-
# Log level for Logger compatibility.
|
65
|
-
attr_accessor :level
|
66
|
-
|
67
|
-
# Fills in variables for Logger compatibility. If this is the first
|
68
|
-
# instance of SyslogLogger, +program_name+ may be set to change the logged
|
69
|
-
# program name and +facility+ may be set to specify a custom facility
|
70
|
-
# with your syslog daemon.
|
71
|
-
#
|
72
|
-
# Due to the way syslog works, only one program name may be chosen.
|
73
|
-
def initialize(program_name = 'rails', facility = Syslog::LOG_USER, logopts=nil)
|
74
|
-
@level = Logger::DEBUG
|
75
|
-
|
76
|
-
return if defined? SYSLOG
|
77
|
-
self.class.const_set :SYSLOG, Syslog.open(program_name, logopts, facility)
|
78
|
-
end
|
79
|
-
|
80
|
-
# Almost duplicates Logger#add. +progname+ is ignored.
|
81
|
-
def add(severity, message = nil, progname = nil, &block)
|
82
|
-
severity ||= Logger::UNKNOWN
|
83
|
-
if severity >= @level
|
84
|
-
message = clean(message || block.call)
|
85
|
-
SYSLOG.send LEVEL_LOGGER_MAP[severity], clean(message)
|
86
|
-
end
|
87
|
-
true
|
88
|
-
end
|
89
|
-
|
90
|
-
# Allows messages of a particular log level to be ignored temporarily.
|
91
|
-
def silence(temporary_level = Logger::ERROR)
|
92
|
-
old_logger_level = @level
|
93
|
-
@level = temporary_level
|
94
|
-
yield
|
95
|
-
ensure
|
96
|
-
@level = old_logger_level
|
97
|
-
end
|
98
|
-
|
99
|
-
# In Logger, this dumps the raw message; the closest equivalent
|
100
|
-
# would be Logger::UNKNOWN
|
101
|
-
def <<(message)
|
102
|
-
add(Logger::UNKNOWN, message)
|
103
|
-
end
|
104
|
-
|
105
|
-
private
|
106
|
-
|
107
|
-
# Clean up messages so they're nice and pretty.
|
108
|
-
def clean(message)
|
109
|
-
message = message.to_s.dup
|
110
|
-
message.strip!
|
111
|
-
message.gsub!(/%/, '%%') # syslog(3) freaks on % (printf)
|
112
|
-
message.gsub!(/\e\[[^m]*m/, '') # remove useless ansi color codes
|
113
|
-
return message
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|