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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f0ba652ee30b298f62ce43a5f68b5012da95114
4
- data.tar.gz: 3113c3c7988c85eeee2b47374cd1d6416118e9df
3
+ metadata.gz: bb2c8cd7ece38c4a7c4a89eb399b69c4bb3ecdfe
4
+ data.tar.gz: 1218e60b84489f909a819043ce6a922f762ab51a
5
5
  SHA512:
6
- metadata.gz: 5e838f101bad4925f901d1f532635d56fc8d84f115371864304003e418ac1a0a943fcd5a162db5ffcf8f79b49fa0261e72c8dfd67ce4a1954df9492b920c6941
7
- data.tar.gz: eefd1fbe38891dc0285b8eca726cc431eba1810513023014337b69e35348b08c03d87827adf35b2d9096a1f132ef578aaeba260544e8505586a5ffeeadab1afd
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
- image: abakpress/dind:1
11
- privileged: true
12
- volumes:
13
- - /home/data/drone/images:/images
14
- - /home/data/drone/gems:/bundle
15
- environment:
16
- - COMPOSE_FILE_EXT=drone
17
- commands:
18
- - wrapdocker docker -v
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
- - if [ ! -e /images/ssh-agent.tar ]; then docker pull whilp/ssh-agent; docker save whilp/ssh-agent > /images/ssh-agent.tar; fi
21
- - if [ ! -e /images/ruby_$RUBY_IMAGE_TAG.tar ]; then docker pull abakpress/ruby:$RUBY_IMAGE_TAG; docker save abakpress/ruby:$RUBY_IMAGE_TAG > /images/ruby_$RUBY_IMAGE_TAG.tar; fi
14
+ - fetch-images
15
+ --image whilp/ssh-agent
16
+ --image abakpress/ruby-app:$RUBY_IMAGE_TAG
22
17
 
23
- - docker load -i /images/ssh-agent.tar
24
- - docker load -i /images/ruby_$RUBY_IMAGE_TAG.tar
18
+ - dip ssh add -T
19
+ - dip provision
20
+ - dip rspec
25
21
 
26
- - dip ssh add -T
27
- - dip provision
28
- - dip rspec
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
@@ -2,8 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in sysloggable.gemspec
4
4
  gemspec
5
-
6
- if RUBY_VERSION < '2'
7
- gem 'json', '< 2.0.0'
8
- gem 'dry-container', '= 0.3.4'
9
- end
data/dip.yml CHANGED
@@ -2,7 +2,7 @@ version: '1'
2
2
 
3
3
  environment:
4
4
  DOCKER_RUBY_VERSION: 2.2
5
- RUBY_IMAGE_TAG: 2.2-1
5
+ RUBY_IMAGE_TAG: 2.2-latest
6
6
  COMPOSE_FILE_EXT: development
7
7
 
8
8
  compose:
@@ -2,7 +2,7 @@ version: '2'
2
2
 
3
3
  services:
4
4
  app:
5
- image: abakpress/ruby:$RUBY_IMAGE_TAG
5
+ image: abakpress/ruby-app:$RUBY_IMAGE_TAG
6
6
  environment:
7
7
  - SSH_AUTH_SOCK=/ssh/auth/sock
8
8
  - BUNDLE_PATH=/bundle/$DOCKER_RUBY_VERSION
@@ -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.each_with_object(String.new) do |(key, value), memo|
67
- memo << " " << "#{key}=#{value}"
68
- end.strip!
73
+ result.
74
+ map { |key, value| "#{key}=#{value}" }.
75
+ join(@options.fetch(:separator, " "))
69
76
  end
70
77
  end
71
78
  end
@@ -1,3 +1,3 @@
1
1
  module Sysloggable
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -2,7 +2,8 @@ require "spec_helper"
2
2
 
3
3
  describe Sysloggable::Logger do
4
4
  let(:syslogger) { spy("syslogger") }
5
- subject(:logger) { described_class.new(ident: "test_ident") }
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
- it "counts duration" do
23
- Timecop.freeze(Time.now.utc)
23
+ context 'duration' do
24
+ context 'when normal task' do
25
+ it "counts duration" do
26
+ Timecop.freeze(Time.now.utc)
24
27
 
25
- expect(syslogger).to receive(:add).
26
- with(described_class::SEVERITIES[:info],
27
- "severity=INFO service=test_ident operation= duration=10.0 message=msg")
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
- logger.info("msg") do
30
- Timecop.freeze(Time.now.utc + 10)
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
- Timecop.return
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.0
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: 2016-12-07 00:00:00.000000000 Z
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.0.14.1
155
+ rubygems_version: 2.6.1
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: The Logger with writing to syslog