la_logger 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +67 -0
- data/README.md +22 -5
- data/config/fluent.conf +12 -12
- data/lib/la_logger/version.rb +1 -1
- data/lib/la_logger.rb +4 -4
- data/spec/helpers/mongo_helper.rb +1 -1
- data/spec/la_logger_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- metadata +18 -6
- checksums.yaml +0 -15
- data/tuser.rb +0 -21
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://ruby.taobao.org/
|
3
|
+
specs:
|
4
|
+
ast (1.1.0)
|
5
|
+
backports (3.3.3)
|
6
|
+
bson (1.9.2)
|
7
|
+
bson_ext (1.9.2)
|
8
|
+
bson (~> 1.9.2)
|
9
|
+
cool.io (1.1.1)
|
10
|
+
iobuffer (>= 1.0.0)
|
11
|
+
diff-lcs (1.2.4)
|
12
|
+
dotenv (0.9.0)
|
13
|
+
fluent-logger (0.4.6)
|
14
|
+
msgpack (>= 0.4.4, < 0.6.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0)
|
15
|
+
yajl-ruby (~> 1.0)
|
16
|
+
fluent-plugin-mongo (0.6.7)
|
17
|
+
fluentd (>= 0.10.7)
|
18
|
+
mongo (>= 1.6.0)
|
19
|
+
fluentd (0.10.38)
|
20
|
+
cool.io (~> 1.1.1)
|
21
|
+
http_parser.rb (~> 0.5.1)
|
22
|
+
json (>= 1.4.3)
|
23
|
+
msgpack (>= 0.4.4, < 0.6.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0)
|
24
|
+
yajl-ruby (~> 1.0)
|
25
|
+
foreman (0.63.0)
|
26
|
+
dotenv (>= 0.7)
|
27
|
+
thor (>= 0.13.6)
|
28
|
+
http_parser.rb (0.5.3)
|
29
|
+
iobuffer (1.1.2)
|
30
|
+
json (1.8.0)
|
31
|
+
mongo (1.9.1)
|
32
|
+
bson (~> 1.9.1)
|
33
|
+
msgpack (0.5.5)
|
34
|
+
parser (2.0.0.pre6)
|
35
|
+
ast (~> 1.1)
|
36
|
+
slop (~> 3.4, >= 3.4.5)
|
37
|
+
powerpack (0.0.6)
|
38
|
+
rainbow (1.1.4)
|
39
|
+
rspec (2.14.1)
|
40
|
+
rspec-core (~> 2.14.0)
|
41
|
+
rspec-expectations (~> 2.14.0)
|
42
|
+
rspec-mocks (~> 2.14.0)
|
43
|
+
rspec-core (2.14.5)
|
44
|
+
rspec-expectations (2.14.2)
|
45
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
46
|
+
rspec-mocks (2.14.3)
|
47
|
+
rubocop (0.12.0)
|
48
|
+
backports (~> 3.3.3)
|
49
|
+
parser (~> 2.0.0.pre6)
|
50
|
+
powerpack (~> 0.0.3)
|
51
|
+
rainbow (>= 1.1.4)
|
52
|
+
slop (3.4.6)
|
53
|
+
thor (0.18.1)
|
54
|
+
yajl-ruby (1.1.0)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
bson_ext
|
61
|
+
fluent-logger
|
62
|
+
fluent-plugin-mongo
|
63
|
+
fluentd
|
64
|
+
foreman
|
65
|
+
mongo
|
66
|
+
rspec
|
67
|
+
rubocop
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Require: ruby 1.9.x, fluent-logger (not working on JRuby without modification).
|
|
4
4
|
|
5
5
|
## Concepts
|
6
6
|
|
7
|
-
-
|
7
|
+
- Initialize a logger object with `label` and log level:
|
8
8
|
|
9
9
|
class LoggerUser
|
10
10
|
def logger
|
@@ -13,18 +13,21 @@ Require: ruby 1.9.x, fluent-logger (not working on JRuby without modification).
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def logger_this
|
16
|
+
# use warn, error, fatal, ... to log messages with optional
|
17
|
+
# extra information in hash format:
|
16
18
|
logger.error('oops! an error happend!', {extra: 'data'})
|
19
|
+
|
20
|
+
# send (post) message using fluent-logger object directly
|
17
21
|
logger.post('custom.tag', {custom: 'message'})
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
25
|
- Silently fails-over to `STDOUT` if `ENV['FLUENTD']` not defined.
|
22
26
|
|
23
|
-
To use fluentd service, define: `ENV[FLUENTD] = 'localhost:24224'`
|
24
|
-
somewhere in your code before use the logger.
|
27
|
+
To use fluentd service, define: `ENV[FLUENTD] = 'localhost:24224:label'`
|
28
|
+
somewhere in your code before use the logger.
|
25
29
|
|
26
|
-
|
27
|
-
fluent-logger.
|
30
|
+
Default port `24224` is optional, `label` is also optional (default is `nil`).
|
28
31
|
|
29
32
|
Note: as logger object is wrapped by a singleton class, there is no effect to
|
30
33
|
change this setting after logger object has created.
|
@@ -33,3 +36,17 @@ change this setting after logger object has created.
|
|
33
36
|
|
34
37
|
Imported from ruby's default `Logger::Severity`, namely: `debug, info, warn, error,
|
35
38
|
fatal, unknown`.
|
39
|
+
|
40
|
+
## Develop or Test
|
41
|
+
|
42
|
+
Run `foreman start` to start the `fluentd` server fro test.
|
43
|
+
|
44
|
+
## Production
|
45
|
+
|
46
|
+
Set up your fluentd conf file, set
|
47
|
+
|
48
|
+
<match lalogger.**>
|
49
|
+
|
50
|
+
where `lalogger` equals the tag parts you set in your `ENV['FLUENTD']` variable.
|
51
|
+
|
52
|
+
Optionally set `remove_tag_prefix lalogger.` to remove tag from collection names.
|
data/config/fluent.conf
CHANGED
@@ -18,31 +18,31 @@
|
|
18
18
|
# http://localhost:24220/api/plugins
|
19
19
|
# http://localhost:24220/api/plugins?type=TYPE
|
20
20
|
# http://localhost:24220/api/plugins?tag=MYTAG
|
21
|
-
<source>
|
22
|
-
|
23
|
-
|
24
|
-
</source>
|
25
|
-
|
21
|
+
# <source>
|
22
|
+
# type monitor_agent
|
23
|
+
# port 24220
|
24
|
+
# </source>
|
25
|
+
#
|
26
26
|
# Listen DRb for debug
|
27
27
|
# <source>
|
28
28
|
# type debug_agent
|
29
29
|
# port 24230
|
30
30
|
# </source>
|
31
31
|
|
32
|
-
<match
|
32
|
+
<match lalogger.**>
|
33
33
|
# plugin type
|
34
34
|
type mongo
|
35
|
-
|
35
|
+
|
36
36
|
# mongodb host + port
|
37
37
|
host localhost
|
38
38
|
port 27017
|
39
|
-
|
39
|
+
|
40
40
|
# mongodb db + collection
|
41
|
-
database
|
41
|
+
database lalogger_test
|
42
42
|
tag_mapped
|
43
|
-
collection default
|
44
|
-
|
45
|
-
remove_tag_prefix
|
43
|
+
collection default
|
44
|
+
|
45
|
+
remove_tag_prefix lalogger.
|
46
46
|
|
47
47
|
# interval
|
48
48
|
flush_interval 1s
|
data/lib/la_logger/version.rb
CHANGED
data/lib/la_logger.rb
CHANGED
@@ -19,11 +19,11 @@ class LaLogger
|
|
19
19
|
|
20
20
|
def initialize
|
21
21
|
if ENV['FLUENTD']
|
22
|
-
host_, port_ = ENV['FLUENTD'].split ':'
|
23
|
-
host_
|
24
|
-
port_
|
22
|
+
host_, port_, tag_ = ENV['FLUENTD'].split ':'
|
23
|
+
host_ = 'localhost' unless host_ and host_.size > 0
|
24
|
+
port_ = 24224 unless port_ and port_.size > 0
|
25
25
|
@logger = Fluent::Logger::FluentLogger.new(
|
26
|
-
|
26
|
+
tag_, host: host_.to_s, port: port_.to_i
|
27
27
|
)
|
28
28
|
else
|
29
29
|
@logger = Fluent::Logger::ConsoleLogger.open($stderr)
|
data/spec/la_logger_spec.rb
CHANGED
@@ -12,7 +12,7 @@ include MongoHelper
|
|
12
12
|
# first test class
|
13
13
|
class UserA
|
14
14
|
def logger
|
15
|
-
@logger ||= LaLogger.new('
|
15
|
+
@logger ||= LaLogger.new('user_a', LaLogger::INFO)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_log_error(msg = 'error message from A')
|
@@ -27,7 +27,7 @@ end
|
|
27
27
|
# second test class
|
28
28
|
class UserB
|
29
29
|
def logger
|
30
|
-
@logger ||= LaLogger.new('
|
30
|
+
@logger ||= LaLogger.new('user_b')
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_log_error(msg = 'error message from B')
|
@@ -50,7 +50,7 @@ describe LaLogger do
|
|
50
50
|
|
51
51
|
describe 'default level' do
|
52
52
|
it 'log error messages' do
|
53
|
-
LaLogger.new('
|
53
|
+
LaLogger.new('global').error('error message from global')
|
54
54
|
has_log('global', 'error', 'error message from global').should be_true
|
55
55
|
end
|
56
56
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: la_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Huang Wei
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-08 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: fluent-logger
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,6 +30,7 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rspec
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
@@ -34,6 +38,7 @@ dependencies:
|
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ~>
|
39
44
|
- !ruby/object:Gem::Version
|
@@ -41,6 +46,7 @@ dependencies:
|
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: mongo
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -55,6 +62,7 @@ dependencies:
|
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: bson_ext
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
67
|
- - ! '>='
|
60
68
|
- !ruby/object:Gem::Version
|
@@ -62,6 +70,7 @@ dependencies:
|
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
75
|
- - ! '>='
|
67
76
|
- !ruby/object:Gem::Version
|
@@ -69,6 +78,7 @@ dependencies:
|
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: simplecov
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
83
|
- - ~>
|
74
84
|
- !ruby/object:Gem::Version
|
@@ -76,6 +86,7 @@ dependencies:
|
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
91
|
- - ~>
|
81
92
|
- !ruby/object:Gem::Version
|
@@ -88,6 +99,7 @@ extra_rdoc_files: []
|
|
88
99
|
files:
|
89
100
|
- .rspec
|
90
101
|
- Gemfile
|
102
|
+
- Gemfile.lock
|
91
103
|
- Procfile
|
92
104
|
- README.md
|
93
105
|
- benchmark/singleton.rb
|
@@ -99,30 +111,30 @@ files:
|
|
99
111
|
- spec/helpers/mongo_helper.rb
|
100
112
|
- spec/la_logger_spec.rb
|
101
113
|
- spec/spec_helper.rb
|
102
|
-
- tuser.rb
|
103
114
|
homepage: https://github.com/7lime/la_logger-gem
|
104
115
|
licenses:
|
105
116
|
- MIT
|
106
|
-
metadata: {}
|
107
117
|
post_install_message:
|
108
118
|
rdoc_options: []
|
109
119
|
require_paths:
|
110
120
|
- lib
|
111
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
112
123
|
requirements:
|
113
124
|
- - ! '>='
|
114
125
|
- !ruby/object:Gem::Version
|
115
126
|
version: '0'
|
116
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
117
129
|
requirements:
|
118
130
|
- - ! '>='
|
119
131
|
- !ruby/object:Gem::Version
|
120
132
|
version: '0'
|
121
133
|
requirements: []
|
122
134
|
rubyforge_project:
|
123
|
-
rubygems_version:
|
135
|
+
rubygems_version: 1.8.23
|
124
136
|
signing_key:
|
125
|
-
specification_version:
|
137
|
+
specification_version: 3
|
126
138
|
summary: Wrap fluent logger as a singleton object, silently fail-over to STDOUT if
|
127
139
|
fluentd service not defined.
|
128
140
|
test_files:
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
MmMzNjQ0YTZhMWFmYTYxMDI3MmUzODYxM2VmNWZiNDFhMjBkZWY3NA==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZmNiOTRjOGIyODdlYjdmMWI4NjIwMWZiYTJkNGJmNzA3MmVjMGNkMw==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
NTZhNmZkMmFkMzYzMTliNDMzYmUyNzQyYTg2N2YxN2ZiN2U2MTIzMWE5Nzkz
|
10
|
-
MmM5NmExYjljMTExNWM1YzI0NmY1YjA2NzUwZDVhNTM4ODBjMTk4NmQ0OWUw
|
11
|
-
ZWVmZjEwMzJhOGIyNTE4NmUwODdiMzRhY2Q4ZDYzNTgwYmRmYTU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YzI2ZTA2YWMyNDdhMjFlM2Q1NGNiNjliMDY1Y2ZkMWYxZWYxMzJkNjFhYTYz
|
14
|
-
YzZmM2VmZjk3ZjAwOTEwYmJhYzVkZDBlNDdiNjE3MThlMDAxMGJmYTQxMDMw
|
15
|
-
MDhiYzY3MmFlYjUxODcyOWRlMjM1ODFkMTI5Yjk5ODc5NWJlYWI=
|
data/tuser.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib'
|
2
|
-
|
3
|
-
require 'la_logger'
|
4
|
-
|
5
|
-
LaLogger.logger.post('La', {message: 'La Mon'})
|
6
|
-
|
7
|
-
class User
|
8
|
-
include LaLogger
|
9
|
-
|
10
|
-
def say
|
11
|
-
log_error('An error occured.')
|
12
|
-
end
|
13
|
-
|
14
|
-
def say_other
|
15
|
-
logger_init('La Mancha')
|
16
|
-
log_error('Error occured again.')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
User.new.say
|
21
|
-
User.new.say_other
|