auto_logger 0.1.2 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +26 -13
- data/README.md +30 -1
- data/auto_logger.gemspec +5 -4
- data/lib/auto_logger.rb +15 -11
- data/lib/auto_logger/named.rb +1 -1
- data/lib/auto_logger/version.rb +1 -1
- metadata +31 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f11f1f0a46aa7904f73ef2bdcf084469426331d06f2555ed622e7007aafa32b
|
4
|
+
data.tar.gz: d9be3d2f7c7eaa750f13a0e840632f7f5109ad7aac35df9176612e12851086f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87ad0c3b8cea74dfab805284b9db36f1d37e1a2edb967036c35db27808cf6755b03601c1a995f8540bafb4385df26e669e5a58a1ed23dfdb93a5d61eebea910d
|
7
|
+
data.tar.gz: cdcc3a79b885747d58e9d618185439ba5cedaabbbb55ea230893e1c5bc9de6d4e19f46464a1b984ef349973d60098830eed25ee793dffaf71c2b185dc5e4bc24
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,33 +1,44 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
auto_logger (0.1.
|
4
|
+
auto_logger (0.1.7)
|
5
5
|
activesupport
|
6
6
|
beautiful-log
|
7
|
-
logger
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: https://rubygems.org/
|
11
10
|
specs:
|
12
|
-
activesupport (
|
11
|
+
activesupport (6.1.3)
|
13
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>=
|
15
|
-
minitest (
|
16
|
-
tzinfo (~>
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
zeitwerk (~> 2.3)
|
17
17
|
awesome_print (1.8.0)
|
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
|
-
concurrent-ruby (1.
|
23
|
-
i18n (1.
|
24
|
+
concurrent-ruby (1.1.8)
|
25
|
+
i18n (1.8.9)
|
24
26
|
concurrent-ruby (~> 1.0)
|
25
|
-
|
27
|
+
logstash-event (1.2.02)
|
28
|
+
logstash-logger (0.26.1)
|
29
|
+
logstash-event (~> 1.2)
|
30
|
+
method_source (1.0.0)
|
26
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)
|
27
38
|
rake (10.5.0)
|
28
|
-
|
29
|
-
|
30
|
-
|
39
|
+
tzinfo (2.0.4)
|
40
|
+
concurrent-ruby (~> 1.0)
|
41
|
+
zeitwerk (2.4.2)
|
31
42
|
|
32
43
|
PLATFORMS
|
33
44
|
ruby
|
@@ -35,8 +46,10 @@ PLATFORMS
|
|
35
46
|
DEPENDENCIES
|
36
47
|
auto_logger!
|
37
48
|
bundler (~> 1.16)
|
49
|
+
logstash-logger
|
38
50
|
minitest (~> 5.0)
|
51
|
+
pry-byebug
|
39
52
|
rake (~> 10.0)
|
40
53
|
|
41
54
|
BUNDLED WITH
|
42
|
-
1.
|
55
|
+
1.17.2
|
data/README.md
CHANGED
@@ -25,8 +25,10 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
+
### Instance usage
|
29
|
+
|
28
30
|
```
|
29
|
-
|
31
|
+
class SomeService
|
30
32
|
include AutoLogger
|
31
33
|
|
32
34
|
def perform
|
@@ -35,6 +37,9 @@ module SomeService
|
|
35
37
|
end
|
36
38
|
```
|
37
39
|
|
40
|
+
|
41
|
+
### Grape example
|
42
|
+
|
38
43
|
Иногда необходимо насильно указать имя файла для лога. Например при подключении
|
39
44
|
в модули/класс без имени, в частности в grape-контролерах:
|
40
45
|
|
@@ -46,6 +51,30 @@ class PublicAPI::OrdersAPI < Grape::API
|
|
46
51
|
end
|
47
52
|
```
|
48
53
|
|
54
|
+
## Usage in module context
|
55
|
+
|
56
|
+
```
|
57
|
+
module Custom
|
58
|
+
extend AutoLogger
|
59
|
+
|
60
|
+
def self.perform
|
61
|
+
logger.info "Do..."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
Custom.logger.info "Do.."
|
66
|
+
```
|
67
|
+
|
68
|
+
## Setup custom logger
|
69
|
+
|
70
|
+
```
|
71
|
+
AutoLogger.logger_builder = -> (tag, default_formatter) {
|
72
|
+
ActiveSupport::TaggedLogging
|
73
|
+
.new(LogStashLogger.new(type: :stdout))
|
74
|
+
.tagged(tag)
|
75
|
+
}
|
76
|
+
```
|
77
|
+
|
49
78
|
## Development
|
50
79
|
|
51
80
|
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
@@ -34,9 +34,10 @@ Gem::Specification.new do |spec|
|
|
34
34
|
|
35
35
|
spec.add_runtime_dependency 'beautiful-log'
|
36
36
|
spec.add_runtime_dependency 'activesupport'
|
37
|
-
spec.add_runtime_dependency 'logger'
|
38
37
|
|
39
|
-
spec.add_development_dependency
|
40
|
-
spec.add_development_dependency
|
41
|
-
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'
|
42
43
|
end
|
data/lib/auto_logger.rb
CHANGED
@@ -28,14 +28,14 @@ require "auto_logger/named"
|
|
28
28
|
module AutoLogger
|
29
29
|
DEFAULT_LOG_DIR = './log'
|
30
30
|
|
31
|
-
mattr_accessor :log_dir
|
32
|
-
|
33
|
-
private
|
31
|
+
mattr_accessor :log_dir, :log_formatter, :logger_builder, :_cached_logger
|
34
32
|
|
35
33
|
def logger
|
36
|
-
|
34
|
+
_cached_logger ||= _build_auto_logger
|
37
35
|
end
|
38
36
|
|
37
|
+
private
|
38
|
+
|
39
39
|
# Логируем вместе с временем выполнения
|
40
40
|
#
|
41
41
|
def bm_log(message)
|
@@ -45,18 +45,18 @@ 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)
|
57
57
|
|
58
58
|
elsif defined? Rails
|
59
|
-
Rails.root.join file
|
59
|
+
Rails.root.join 'log', file
|
60
60
|
|
61
61
|
else
|
62
62
|
File.join(DEFAULT_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/named.rb
CHANGED
data/lib/auto_logger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danil Pismenny
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: beautiful-log
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: logger
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +80,34 @@ dependencies:
|
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
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'
|
97
111
|
description: Mixin that adds `logger` method authomatically configured to use log
|
98
112
|
name from module/class
|
99
113
|
email:
|
@@ -137,8 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '0'
|
139
153
|
requirements: []
|
140
|
-
|
141
|
-
rubygems_version: 2.7.7
|
154
|
+
rubygems_version: 3.0.3
|
142
155
|
signing_key:
|
143
156
|
specification_version: 4
|
144
157
|
summary: "'logger' method configured with class/module name"
|