auto_logger 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -1
- data/README.md +25 -1
- data/auto_logger.gemspec +5 -3
- data/lib/auto_logger.rb +12 -8
- data/lib/auto_logger/version.rb +1 -1
- metadata +29 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7f51d8f2d708e675544564798a8d494fda2668780e994ec7da69ec087549b1d
|
4
|
+
data.tar.gz: 677853ea89d8f8ab5fc71edee5451b40fbfd37714e7adb9055eddcda32bfcb0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18db633851ae1906b20f33f2d76c863839bb68789077d0f85a8ce791654b97e2db6e94a347a8570500afc7d2a125afa215bc051cad3724a154c9935b662693b2
|
7
|
+
data.tar.gz: 60cdb6c581ddfb1b2dca3c78fdeecb3c2d458d393f60e478082f3ae83256fbc415e681d11fda78ac33924d090386fc8efb5994fd5d48b016c0dc3afce672ade9
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
auto_logger (0.1.
|
4
|
+
auto_logger (0.1.6)
|
5
5
|
activesupport
|
6
6
|
beautiful-log
|
7
7
|
|
@@ -18,11 +18,23 @@ GEM
|
|
18
18
|
beautiful-log (0.2.2)
|
19
19
|
awesome_print (~> 1.8.0)
|
20
20
|
colorize (~> 0.8.1)
|
21
|
+
byebug (11.1.3)
|
22
|
+
coderay (1.1.3)
|
21
23
|
colorize (0.8.1)
|
22
24
|
concurrent-ruby (1.1.8)
|
23
25
|
i18n (1.8.9)
|
24
26
|
concurrent-ruby (~> 1.0)
|
27
|
+
logstash-event (1.2.02)
|
28
|
+
logstash-logger (0.26.1)
|
29
|
+
logstash-event (~> 1.2)
|
30
|
+
method_source (1.0.0)
|
25
31
|
minitest (5.11.3)
|
32
|
+
pry (0.13.1)
|
33
|
+
coderay (~> 1.1)
|
34
|
+
method_source (~> 1.0)
|
35
|
+
pry-byebug (3.9.0)
|
36
|
+
byebug (~> 11.0)
|
37
|
+
pry (~> 0.13.0)
|
26
38
|
rake (10.5.0)
|
27
39
|
tzinfo (2.0.4)
|
28
40
|
concurrent-ruby (~> 1.0)
|
@@ -34,7 +46,9 @@ PLATFORMS
|
|
34
46
|
DEPENDENCIES
|
35
47
|
auto_logger!
|
36
48
|
bundler (~> 1.16)
|
49
|
+
logstash-logger
|
37
50
|
minitest (~> 5.0)
|
51
|
+
pry-byebug
|
38
52
|
rake (~> 10.0)
|
39
53
|
|
40
54
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
|
|
26
26
|
## Usage
|
27
27
|
|
28
28
|
```
|
29
|
-
|
29
|
+
class SomeService
|
30
30
|
include AutoLogger
|
31
31
|
|
32
32
|
def perform
|
@@ -46,6 +46,30 @@ class PublicAPI::OrdersAPI < Grape::API
|
|
46
46
|
end
|
47
47
|
```
|
48
48
|
|
49
|
+
Usage in module context:
|
50
|
+
|
51
|
+
```
|
52
|
+
module Custom
|
53
|
+
extend AutoLogger
|
54
|
+
|
55
|
+
def self.perform
|
56
|
+
logger.info "Do..."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
Custom.logger.info "Do.."
|
61
|
+
```
|
62
|
+
|
63
|
+
Setup custom logger:
|
64
|
+
|
65
|
+
```
|
66
|
+
AutoLogger.logger_builder = -> (tag, default_formatter) {
|
67
|
+
ActiveSupport::TaggedLogging
|
68
|
+
.new(LogStashLogger.new(type: :stdout))
|
69
|
+
.tagged(tag)
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
49
73
|
## Development
|
50
74
|
|
51
75
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/auto_logger.gemspec
CHANGED
@@ -35,7 +35,9 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_runtime_dependency 'beautiful-log'
|
36
36
|
spec.add_runtime_dependency 'activesupport'
|
37
37
|
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency
|
40
|
-
spec.add_development_dependency
|
38
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
39
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
40
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
41
|
+
spec.add_development_dependency 'pry-byebug'
|
42
|
+
spec.add_development_dependency 'logstash-logger'
|
41
43
|
end
|
data/lib/auto_logger.rb
CHANGED
@@ -28,10 +28,10 @@ require "auto_logger/named"
|
|
28
28
|
module AutoLogger
|
29
29
|
DEFAULT_LOG_DIR = './log'
|
30
30
|
|
31
|
-
mattr_accessor :log_dir
|
31
|
+
mattr_accessor :log_dir, :log_formatter, :logger_builder, :_cached_logger
|
32
32
|
|
33
33
|
def logger
|
34
|
-
|
34
|
+
_cached_logger ||= _build_auto_logger
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
@@ -45,12 +45,12 @@ module AutoLogger
|
|
45
45
|
res
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
self.class.
|
48
|
+
def _auto_logger_tag
|
49
|
+
([Class, Module].include?(self.class) ? self.name : self.class.name).underscore.gsub('/','_')
|
50
50
|
end
|
51
51
|
|
52
52
|
def _auto_logger_file
|
53
|
-
file = "#{
|
53
|
+
file = "#{_auto_logger_tag}.log"
|
54
54
|
|
55
55
|
if log_dir.present?
|
56
56
|
File.join(log_dir, file)
|
@@ -64,11 +64,15 @@ module AutoLogger
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def _log_formatter
|
67
|
-
!defined?(Rails) || Rails.env.test? ? Logger::Formatter.new : Formatter.new
|
67
|
+
@log_formatter || !defined?(Rails) || Rails.env.test? ? Logger::Formatter.new : Formatter.new
|
68
68
|
end
|
69
69
|
|
70
70
|
def _build_auto_logger
|
71
|
-
|
72
|
-
|
71
|
+
if logger_builder.nil?
|
72
|
+
ActiveSupport::Logger.new(_auto_logger_file).
|
73
|
+
tap { |logger| logger.formatter = _log_formatter }
|
74
|
+
else
|
75
|
+
logger_builder.call(_auto_logger_tag, _log_formatter)
|
76
|
+
end
|
73
77
|
end
|
74
78
|
end
|
data/lib/auto_logger/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danil Pismenny
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: logstash-logger
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: Mixin that adds `logger` method authomatically configured to use log
|
84
112
|
name from module/class
|
85
113
|
email:
|