logging-remote-syslog 0.0.4 → 0.0.5
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/.gitignore +1 -0
- data/README.md +28 -5
- data/lib/logging/VERSION +1 -1
- data/lib/logging/appenders/remote-syslog.rb +5 -1
- data/spec/logging/appenders/remote_syslog_spec.rb +5 -0
- metadata +24 -20
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# logging/remote-syslog
|
2
2
|
|
3
|
-
logging/remote-syslog is a remote syslog appender for use with the Logging library. 
|
3
|
+
logging/remote-syslog is a remote syslog appender for use with the [Logging](https://github.com/TwP/logging) library. 
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,10 +20,13 @@ Or install it yourself as:
|
|
20
20
|
```
|
21
21
|
|
22
22
|
## Options
|
23
|
-
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
23
|
+
|
24
|
+
:ident - [String] Identity of the sender, such as a hostname or app ID
|
25
|
+
:syslog_server [String] - Syslog server hostname or IP (default: `127.0.0.1`)
|
26
|
+
:port [Integer] - Syslog server port (default: `514`)
|
27
|
+
:strip_colors [True|False] - Some loggers like shell colors, should we remove them? (default: `True`)
|
28
|
+
:facility [String] - A syslog facility name (default: `user`)
|
29
|
+
:modifier [Method] - A callback for altering the original message (takes original message; returns modified one)
|
27
30
|
|
28
31
|
## Usage
|
29
32
|
|
@@ -41,12 +44,32 @@ logger.info 'MyApp Message'
|
|
41
44
|
|
42
45
|
```
|
43
46
|
|
47
|
+
Note that as shown above, a name is required as the first argument when
|
48
|
+
adding the appender. (If an `ident:` options hash key is also provided,
|
49
|
+
its value will be used as the sender instead of the name.)
|
50
|
+
|
51
|
+
## Example
|
52
|
+
|
53
|
+
This registers a new appender named after the system's hostname. It will
|
54
|
+
log to `logs.example.com:1111`.
|
55
|
+
|
56
|
+
```
|
57
|
+
require 'socket'
|
58
|
+
logger = Logging.logger['MyApp']
|
59
|
+
logger.add_appenders(
|
60
|
+
Logging.appenders.remote_syslog(Socket.gethostname, syslog_server: 'logs.example.com', port: 1111)
|
61
|
+
)
|
62
|
+
```
|
63
|
+
|
44
64
|
## Tests
|
45
65
|
|
46
66
|
```
|
47
67
|
rake
|
48
68
|
```
|
49
69
|
|
70
|
+
## Change Log
|
71
|
+
0.0.3 - Strip ANSI shell codes by default
|
72
|
+
|
50
73
|
## Contributing
|
51
74
|
|
52
75
|
1. Fork it
|
data/lib/logging/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
@@ -34,6 +34,7 @@ module Logging::Appenders
|
|
34
34
|
# :syslog_server => address of the remote syslog server
|
35
35
|
# :port => port of the remote syslog server
|
36
36
|
# :facility => the syslog facility to use
|
37
|
+
# :modifier => an optional callback method for altering original message; takes original message and returns updated one
|
37
38
|
#
|
38
39
|
# The parameter :ident is a string that will be prepended to every
|
39
40
|
# message. The :facility parameter encodes a default facility to be
|
@@ -78,6 +79,7 @@ module Logging::Appenders
|
|
78
79
|
@ident = opts.getopt(:ident, name)
|
79
80
|
@syslog_server = opts.getopt(:syslog_server, '127.0.0.1')
|
80
81
|
@port = opts.getopt(:port, 514, :as => Integer)
|
82
|
+
@modifier = opts.getopt(:modifier)
|
81
83
|
|
82
84
|
@strip_colors = opts.getopt(:strip_colors, true)
|
83
85
|
|
@@ -123,7 +125,9 @@ module Logging::Appenders
|
|
123
125
|
end
|
124
126
|
|
125
127
|
def prepare_message(message)
|
126
|
-
@strip_colors ? strip_ansi_colors(message) : message
|
128
|
+
message = @strip_colors ? strip_ansi_colors(message) : message
|
129
|
+
message = @modifier.call(message) if @modifier
|
130
|
+
message
|
127
131
|
end
|
128
132
|
|
129
133
|
private
|
@@ -65,4 +65,9 @@ describe Logging::Appenders::RemoteSyslog do
|
|
65
65
|
appender = Logging.appenders.remote_syslog('Test', :syslog_server => '127.0.0.1', :facility => SyslogProtocol::FACILITIES['local6'], :strip_colors => false)
|
66
66
|
appender.prepare_message("\e[KTest Message\e[0m").should == "\e[KTest Message\e[0m"
|
67
67
|
end
|
68
|
+
|
69
|
+
it 'can modify original message' do
|
70
|
+
appender = Logging.appenders.remote_syslog('Test', :syslog_server => '127.0.0.1', :facility => SyslogProtocol::FACILITIES['local6'], :strip_colors => false, :modifier => lambda{|msg| "foo: #{msg}"})
|
71
|
+
appender.prepare_message("Test").should == "foo: Test"
|
72
|
+
end
|
68
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logging-remote-syslog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: logging
|
@@ -126,38 +126,42 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
126
|
- - ! '>='
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
|
-
segments:
|
130
|
-
- 0
|
131
|
-
hash: -3667170423268001466
|
132
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
130
|
none: false
|
134
131
|
requirements:
|
135
132
|
- - ! '>='
|
136
133
|
- !ruby/object:Gem::Version
|
137
134
|
version: '0'
|
138
|
-
segments:
|
139
|
-
- 0
|
140
|
-
hash: -3667170423268001466
|
141
135
|
requirements: []
|
142
136
|
rubyforge_project:
|
143
137
|
rubygems_version: 1.8.24
|
144
138
|
signing_key:
|
145
139
|
specification_version: 3
|
146
140
|
summary: ! '# logging/remote-syslog logging/remote-syslog is a remote syslog appender
|
147
|
-
for use with the Logging library.  library.  ## Installation Add
|
143
|
+
this line to your application''s Gemfile: ``` gem ''logging-remote-syslog'', :require
|
144
|
+
=> ''logging/remote-syslog'' ``` And then execute: ``` $ bundle ``` Or install
|
145
|
+
it yourself as: ``` $ gem install logging-remote-syslog ``` ## Options :ident
|
146
|
+
- [String] Identity of the sender, such as a hostname or app ID :syslog_server [String]
|
147
|
+
- Syslog server hostname or IP (default: `127.0.0.1`) :port [Integer] - Syslog server
|
148
|
+
port (default: `514`) :strip_colors [True|False] - Some loggers like shell colors,
|
149
|
+
should we remove them? (default: `True`) :facility [String] - A syslog facility
|
150
|
+
name (default: `user`) :modifier [Method] - A callback for altering the original
|
151
|
+
message (takes original message; returns modified one) ## Usage ``` require ''logging''
|
154
152
|
require ''logging/remote-syslog'' logger = Logging.logger[''MyApp''] logger.add_appenders(
|
155
153
|
Logging.appenders.remote_syslog(ident, syslog_server: syslog_host, port: syslog_port)
|
156
|
-
) logger.level = :info logger.info ''MyApp Message'' ```
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
154
|
+
) logger.level = :info logger.info ''MyApp Message'' ``` Note that as shown above,
|
155
|
+
a name is required as the first argument when adding the appender. (If an `ident:`
|
156
|
+
options hash key is also provided, its value will be used as the sender instead
|
157
|
+
of the name.) ## Example This registers a new appender named after the system''s
|
158
|
+
hostname. It will log to `logs.example.com:1111`. ``` require ''socket'' logger
|
159
|
+
= Logging.logger[''MyApp''] logger.add_appenders( Logging.appenders.remote_syslog(Socket.gethostname,
|
160
|
+
syslog_server: ''logs.example.com'', port: 1111) ) ``` ## Tests ``` rake ``` ##
|
161
|
+
Change Log 0.0.3 - Strip ANSI shell codes by default ## Contributing 1. Fork it
|
162
|
+
2. Create your feature branch (`git checkout -b my-new-feature`) 3. Write code and
|
163
|
+
add _tests_ 4. Commit your changes (`git commit -am ''Added some feature''`) 5.
|
164
|
+
Push to the branch (`git push origin my-new-feature`) 6. Create new Pull Request'
|
161
165
|
test_files:
|
162
166
|
- spec/logging/appenders/remote_syslog_spec.rb
|
163
167
|
- spec/spec_helper.rb
|