sysloggable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.drone.yml +28 -0
- data/.gitignore +9 -0
- data/.rspec +4 -0
- data/Gemfile +9 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/dip.yml +35 -0
- data/docker-compose.development.yml +18 -0
- data/docker-compose.drone.yml +14 -0
- data/docker-compose.yml +9 -0
- data/lib/sysloggable/container.rb +12 -0
- data/lib/sysloggable/logger.rb +67 -0
- data/lib/sysloggable/version.rb +3 -0
- data/lib/sysloggable.rb +12 -0
- data/spec/lib/sysloggable/logger_spec.rb +35 -0
- data/spec/lib/sysloggable_spec.rb +31 -0
- data/spec/spec_helper.rb +15 -0
- data/sysloggable.gemspec +29 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 905c341697f07420f3fbba5a5118c0991f058cfc
|
4
|
+
data.tar.gz: 4bbb3c0b63fe1f68250395295dd32a943e776bef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78d7e3972c7476aedadec9c6eb5b9c3f4bf1c9bbb35e02307f4068041344ff7eb2a9b3f147383767da8444c5ff47eac3aa1243567287da93fa56350a9293e855
|
7
|
+
data.tar.gz: 5eede3bf94802cb56b478bcf1951d0f2f49c235be7781564e0b9f792b90b12f1e6eaea34985c2b10972c53842ebf714b58fd32464e4e7d9720c6d4c6732a0c8a
|
data/.drone.yml
ADDED
@@ -0,0 +1,28 @@
|
|
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
|
+
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
|
19
|
+
|
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
|
22
|
+
|
23
|
+
- docker load -i /images/ssh-agent.tar
|
24
|
+
- docker load -i /images/ruby_$RUBY_IMAGE_TAG.tar
|
25
|
+
|
26
|
+
- dip ssh add -T
|
27
|
+
- dip provision
|
28
|
+
- dip rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Sysloggable
|
2
|
+
|
3
|
+
Write your logs to syslog. Message is formatted with options and duration.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'sysloggable'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install sysloggable
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class FooService
|
25
|
+
include ::Sysloggable::InjectLogger(ident: 'banners_stats')
|
26
|
+
|
27
|
+
def call
|
28
|
+
message = "Heavy operation"
|
29
|
+
logger.info(message, operation: 'dump', counter: counter.id, date: date) do |params|
|
30
|
+
heavy_process!
|
31
|
+
end
|
32
|
+
rescue exception
|
33
|
+
logger.fatal(exception.message, trace: exception.backtrace.join("\n"))
|
34
|
+
raise
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
Install Docker, Docker-Compose and DIP https://github.com/bibendi/dip
|
42
|
+
|
43
|
+
```sh
|
44
|
+
dip provision
|
45
|
+
|
46
|
+
dip rspec
|
47
|
+
```
|
data/Rakefile
ADDED
data/dip.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
version: '1'
|
2
|
+
|
3
|
+
environment:
|
4
|
+
DOCKER_RUBY_VERSION: 2.2
|
5
|
+
RUBY_IMAGE_TAG: 2.2-1
|
6
|
+
COMPOSE_FILE_EXT: development
|
7
|
+
|
8
|
+
compose:
|
9
|
+
files:
|
10
|
+
- docker-compose.yml
|
11
|
+
- docker-compose.${COMPOSE_FILE_EXT}.yml
|
12
|
+
|
13
|
+
interaction:
|
14
|
+
sh:
|
15
|
+
service: app
|
16
|
+
|
17
|
+
irb:
|
18
|
+
service: app
|
19
|
+
command: irb
|
20
|
+
|
21
|
+
bundle:
|
22
|
+
service: app
|
23
|
+
command: bundle
|
24
|
+
|
25
|
+
rspec:
|
26
|
+
service: app
|
27
|
+
command: bundle exec rspec
|
28
|
+
|
29
|
+
clean:
|
30
|
+
service: app
|
31
|
+
command: rm -f Gemfile.lock
|
32
|
+
|
33
|
+
provision:
|
34
|
+
- docker volume create --name bundler_data
|
35
|
+
- dip bundle install
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "dry/container"
|
2
|
+
require "syslogger"
|
3
|
+
require "sysloggable/logger"
|
4
|
+
|
5
|
+
module Sysloggable
|
6
|
+
Container = ::Dry::Container.new
|
7
|
+
end
|
8
|
+
|
9
|
+
::Sysloggable::Container.namespace('lib') do
|
10
|
+
register 'logger', -> { ::Sysloggable::Logger }
|
11
|
+
register 'syslogger', -> { ::Syslogger }
|
12
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Sysloggable
|
2
|
+
class Logger
|
3
|
+
SEVERITIES = {
|
4
|
+
debug: ::Logger::DEBUG,
|
5
|
+
info: ::Logger::INFO,
|
6
|
+
warn: ::Logger::WARN,
|
7
|
+
error: ::Logger::ERROR,
|
8
|
+
fatal: ::Logger::FATAL,
|
9
|
+
unknown: ::Logger::UNKNOWN
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
SEVERITIES.each do |logger_method, logger_code|
|
17
|
+
define_method logger_method do |*args, &block|
|
18
|
+
add(logger_code, *args, &block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def logger
|
25
|
+
return @logger if defined?(@logger)
|
26
|
+
|
27
|
+
@logger = Container['lib.syslogger'].new(
|
28
|
+
@options.fetch(:ident),
|
29
|
+
::Syslog::LOG_PID | ::Syslog::LOG_CONS,
|
30
|
+
::Syslog::LOG_LOCAL0
|
31
|
+
)
|
32
|
+
|
33
|
+
@logger.level = @options.fetch(:level, ::Logger::INFO)
|
34
|
+
@logger.push_tags(@options[:tags]) if @options[:tags]
|
35
|
+
|
36
|
+
@logger
|
37
|
+
end
|
38
|
+
|
39
|
+
def add(severity, message, params = {})
|
40
|
+
if block_given?
|
41
|
+
beginning = Time.now.utc
|
42
|
+
yield params
|
43
|
+
duration = Time.now.utc - beginning
|
44
|
+
else
|
45
|
+
duration = 0
|
46
|
+
end
|
47
|
+
|
48
|
+
formated_message = format_message(severity, message, duration, params)
|
49
|
+
|
50
|
+
logger.add(severity, formated_message)
|
51
|
+
end
|
52
|
+
|
53
|
+
def format_message(severity, message, duration, params)
|
54
|
+
result = {
|
55
|
+
severity: ::Logger::SEV_LABEL[severity],
|
56
|
+
service: @options.fetch(:service_name, @options.fetch(:ident)),
|
57
|
+
operation: params.delete(:operation),
|
58
|
+
duration: duration,
|
59
|
+
message: message
|
60
|
+
}.merge!(params)
|
61
|
+
|
62
|
+
result.each_with_object(String.new) do |(key, value), memo|
|
63
|
+
memo << " " << "#{key}=#{value}"
|
64
|
+
end.strip!
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/sysloggable.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Sysloggable::Logger do
|
4
|
+
let(:syslogger) { spy("syslogger") }
|
5
|
+
subject(:logger) { described_class.new(ident: "test_ident") }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Sysloggable::Container.stub('lib.syslogger', syslogger)
|
9
|
+
end
|
10
|
+
|
11
|
+
described_class::SEVERITIES.each do |severity_name, severity_value|
|
12
|
+
it "responds to #{severity_name}" do
|
13
|
+
sev_label = (severity_name == :unknown) ? "ANY" : severity_name.upcase
|
14
|
+
|
15
|
+
expect(syslogger).to receive(:add).
|
16
|
+
with(severity_value, "severity=#{sev_label} service=test_ident operation= duration=0 message=msg")
|
17
|
+
|
18
|
+
logger.send(severity_name, "msg")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "counts duration" do
|
23
|
+
Timecop.freeze(Time.now.utc)
|
24
|
+
|
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
|
+
|
29
|
+
logger.info("msg") do
|
30
|
+
Timecop.freeze(Time.now.utc + 10)
|
31
|
+
end
|
32
|
+
|
33
|
+
Timecop.return
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Sysloggable do
|
4
|
+
it "has a version number" do
|
5
|
+
expect(Sysloggable::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it "defines logger instance method" do
|
9
|
+
klass = Class.new do
|
10
|
+
include Sysloggable::InjectLogger(ident: "test_name")
|
11
|
+
end
|
12
|
+
|
13
|
+
expect(klass.new.logger).to be_a(Sysloggable::Logger)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "defines logger class method" do
|
17
|
+
klass = Class.new do
|
18
|
+
extend Sysloggable::InjectLogger(ident: "test_name")
|
19
|
+
end
|
20
|
+
|
21
|
+
expect(klass.logger).to be_a(Sysloggable::Logger)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "passes an options to logger" do
|
25
|
+
klass = Class.new do
|
26
|
+
include Sysloggable::InjectLogger(ident: "test_name")
|
27
|
+
end
|
28
|
+
|
29
|
+
expect(klass.new.logger.send(:logger).ident).to eq "test_name"
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
require "simplecov"
|
4
|
+
SimpleCov.start do
|
5
|
+
minimum_coverage 95
|
6
|
+
end
|
7
|
+
|
8
|
+
require "sysloggable"
|
9
|
+
require "dry/container/stub"
|
10
|
+
require "timecop"
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.before { Sysloggable::Container.enable_stubs! }
|
14
|
+
config.after { Sysloggable::Container.unstub }
|
15
|
+
end
|
data/sysloggable.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sysloggable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sysloggable"
|
8
|
+
spec.version = Sysloggable::VERSION
|
9
|
+
spec.authors = ["Michail Merkushin"]
|
10
|
+
spec.email = ["merkushin.m.s@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "The Logger with writing to syslog"
|
13
|
+
spec.description = "Writes to syslog with user defined params"
|
14
|
+
spec.homepage = "https://github.com/abak-press/sysloggable"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "syslogger", "~> 1.6"
|
22
|
+
spec.add_runtime_dependency "dry-container", ">= 0.3.4"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "timecop", "~> 0.8"
|
28
|
+
spec.add_development_dependency "simplecov", "~> 0.12"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sysloggable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michail Merkushin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: syslogger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-container
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.13'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: timecop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.12'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.12'
|
111
|
+
description: Writes to syslog with user defined params
|
112
|
+
email:
|
113
|
+
- merkushin.m.s@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".drone.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- Gemfile
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- dip.yml
|
125
|
+
- docker-compose.development.yml
|
126
|
+
- docker-compose.drone.yml
|
127
|
+
- docker-compose.yml
|
128
|
+
- lib/sysloggable.rb
|
129
|
+
- lib/sysloggable/container.rb
|
130
|
+
- lib/sysloggable/logger.rb
|
131
|
+
- lib/sysloggable/version.rb
|
132
|
+
- spec/lib/sysloggable/logger_spec.rb
|
133
|
+
- spec/lib/sysloggable_spec.rb
|
134
|
+
- spec/spec_helper.rb
|
135
|
+
- sysloggable.gemspec
|
136
|
+
homepage: https://github.com/abak-press/sysloggable
|
137
|
+
licenses: []
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.6.1
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: The Logger with writing to syslog
|
159
|
+
test_files: []
|