sysloggable 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.drone.yml +25 -24
- data/Gemfile +0 -5
- data/dip.yml +1 -1
- data/docker-compose.yml +1 -1
- data/lib/sysloggable/logger.rb +24 -17
- data/lib/sysloggable/version.rb +1 -1
- data/spec/lib/sysloggable/logger_spec.rb +38 -9
- metadata +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb2c8cd7ece38c4a7c4a89eb399b69c4bb3ecdfe
|
4
|
+
data.tar.gz: 1218e60b84489f909a819043ce6a922f762ab51a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1164f74e38afdfabd3374995bce5b41ad0a44671226a403cee8497e33471de6549c393c55a6d75ce22b6fe69271f2798bff506cc890cd2cd31b81a6d0a6f8600
|
7
|
+
data.tar.gz: 497510d0ac3eed483e82ab22d8bdb79cde5adb166bdb3c7b7d431daa54f040f1aa9a921aa3ccac8d167665d0e5f4283263d9db2a71d448c922c08772bf252aea
|
data/.drone.yml
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
matrix:
|
2
|
-
include:
|
3
|
-
- DOCKER_RUBY_VERSION: 2.2
|
4
|
-
RUBY_IMAGE_TAG: 2.2-1
|
5
|
-
|
6
|
-
- DOCKER_RUBY_VERSION: 1.9.3
|
7
|
-
RUBY_IMAGE_TAG: 1.9.3-2
|
8
|
-
|
9
1
|
build:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
2
|
+
test:
|
3
|
+
image: abakpress/dind-testing
|
4
|
+
pull: true
|
5
|
+
privileged: true
|
6
|
+
volumes:
|
7
|
+
- /home/data/drone/images:/images
|
8
|
+
- /home/data/drone/gems:/bundle
|
9
|
+
environment:
|
10
|
+
- COMPOSE_FILE_EXT=drone
|
11
|
+
commands:
|
12
|
+
- wrapdocker docker -v
|
19
13
|
|
20
|
-
|
21
|
-
|
14
|
+
- fetch-images
|
15
|
+
--image whilp/ssh-agent
|
16
|
+
--image abakpress/ruby-app:$RUBY_IMAGE_TAG
|
22
17
|
|
23
|
-
|
24
|
-
|
18
|
+
- dip ssh add -T
|
19
|
+
- dip provision
|
20
|
+
- dip rspec
|
25
21
|
|
26
|
-
|
27
|
-
-
|
28
|
-
|
22
|
+
release:
|
23
|
+
image: abakpress/gem-publication:latest
|
24
|
+
pull: true
|
25
|
+
when:
|
26
|
+
branch: master
|
27
|
+
event: push
|
28
|
+
commands:
|
29
|
+
- release-gem
|
data/Gemfile
CHANGED
data/dip.yml
CHANGED
data/docker-compose.yml
CHANGED
data/lib/sysloggable/logger.rb
CHANGED
@@ -9,6 +9,13 @@ module Sysloggable
|
|
9
9
|
unknown: ::Logger::UNKNOWN
|
10
10
|
}.freeze
|
11
11
|
|
12
|
+
# Public: Initializer
|
13
|
+
#
|
14
|
+
# options : Hash
|
15
|
+
# ident : String - syslog tag.
|
16
|
+
# level : Integer - minimum level for messages to be written in the log.
|
17
|
+
# service_name : String - service identifier.
|
18
|
+
# separator : String - message separator.
|
12
19
|
def initialize(options)
|
13
20
|
@options = options
|
14
21
|
end
|
@@ -19,6 +26,20 @@ module Sysloggable
|
|
19
26
|
end
|
20
27
|
end
|
21
28
|
|
29
|
+
def add(severity, message, params = {})
|
30
|
+
if block_given?
|
31
|
+
beginning = Time.now.utc
|
32
|
+
yield params
|
33
|
+
duration = (Time.now.utc - beginning).round(3)
|
34
|
+
else
|
35
|
+
duration = 0
|
36
|
+
end
|
37
|
+
|
38
|
+
formated_message = format_message(severity, message, duration, params)
|
39
|
+
|
40
|
+
logger.add(severity, formated_message)
|
41
|
+
end
|
42
|
+
|
22
43
|
private
|
23
44
|
|
24
45
|
def logger
|
@@ -40,20 +61,6 @@ module Sysloggable
|
|
40
61
|
@logger
|
41
62
|
end
|
42
63
|
|
43
|
-
def add(severity, message, params = {})
|
44
|
-
if block_given?
|
45
|
-
beginning = Time.now.utc
|
46
|
-
yield params
|
47
|
-
duration = Time.now.utc - beginning
|
48
|
-
else
|
49
|
-
duration = 0
|
50
|
-
end
|
51
|
-
|
52
|
-
formated_message = format_message(severity, message, duration, params)
|
53
|
-
|
54
|
-
logger.add(severity, formated_message)
|
55
|
-
end
|
56
|
-
|
57
64
|
def format_message(severity, message, duration, params)
|
58
65
|
result = {
|
59
66
|
severity: ::Logger::SEV_LABEL[severity],
|
@@ -63,9 +70,9 @@ module Sysloggable
|
|
63
70
|
message: message
|
64
71
|
}.merge!(params)
|
65
72
|
|
66
|
-
result.
|
67
|
-
|
68
|
-
|
73
|
+
result.
|
74
|
+
map { |key, value| "#{key}=#{value}" }.
|
75
|
+
join(@options.fetch(:separator, " "))
|
69
76
|
end
|
70
77
|
end
|
71
78
|
end
|
data/lib/sysloggable/version.rb
CHANGED
@@ -2,7 +2,8 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Sysloggable::Logger do
|
4
4
|
let(:syslogger) { spy("syslogger") }
|
5
|
-
|
5
|
+
let(:options) { {ident: "test_ident"} }
|
6
|
+
subject(:logger) { described_class.new(options) }
|
6
7
|
|
7
8
|
before do
|
8
9
|
Sysloggable::Container.stub('lib.syslogger', syslogger)
|
@@ -19,18 +20,34 @@ describe Sysloggable::Logger do
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
context 'duration' do
|
24
|
+
context 'when normal task' do
|
25
|
+
it "counts duration" do
|
26
|
+
Timecop.freeze(Time.now.utc)
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
expect(syslogger).to receive(:add).
|
29
|
+
with(described_class::SEVERITIES[:info],
|
30
|
+
"severity=INFO service=test_ident operation= duration=9.524 message=msg")
|
28
31
|
|
29
|
-
|
30
|
-
|
32
|
+
logger.info("msg") do
|
33
|
+
Timecop.freeze(Time.now.utc + 9.523531)
|
34
|
+
end
|
35
|
+
|
36
|
+
Timecop.return
|
37
|
+
end
|
31
38
|
end
|
32
39
|
|
33
|
-
|
40
|
+
context 'when very quick task' do
|
41
|
+
it "counts duration" do
|
42
|
+
expect(syslogger).to receive(:add).
|
43
|
+
with(described_class::SEVERITIES[:info],
|
44
|
+
"severity=INFO service=test_ident operation= duration=0.0 message=msg")
|
45
|
+
|
46
|
+
logger.info("msg") do
|
47
|
+
# no-op
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
34
51
|
end
|
35
52
|
|
36
53
|
context 'when ident is invalid' do
|
@@ -39,4 +56,16 @@ describe Sysloggable::Logger do
|
|
39
56
|
expect{ logger.info('msg') }.to raise_error(ArgumentError)
|
40
57
|
end
|
41
58
|
end
|
59
|
+
|
60
|
+
context "custom separator" do
|
61
|
+
let(:options) { {ident: "test_ident", separator: " | "} }
|
62
|
+
|
63
|
+
it do
|
64
|
+
expect(syslogger).to receive(:add).
|
65
|
+
with(described_class::SEVERITIES[:info],
|
66
|
+
"severity=INFO | service=test_ident | operation= | duration=0 | message=msg")
|
67
|
+
|
68
|
+
logger.info("msg")
|
69
|
+
end
|
70
|
+
end
|
42
71
|
end
|
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sysloggable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michail Merkushin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: syslogger
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dry-container
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.3.4
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.3.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.13'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.13'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '10.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '3.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: timecop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0.8'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.8'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0.12'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - ~>
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.12'
|
111
111
|
description: Writes to syslog with user defined params
|
@@ -115,9 +115,9 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- .drone.yml
|
119
|
-
- .gitignore
|
120
|
-
- .rspec
|
118
|
+
- ".drone.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
121
|
- Gemfile
|
122
122
|
- README.md
|
123
123
|
- Rakefile
|
@@ -142,17 +142,17 @@ require_paths:
|
|
142
142
|
- lib
|
143
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
|
-
- -
|
145
|
+
- - ">="
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.6.1
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: The Logger with writing to syslog
|