xlog 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/README.md +54 -5
- data/lib/xlog.rb +13 -11
- data/lib/xlog/version.rb +1 -1
- data/lib/xlog/xlogger.rb +10 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8863710eaab6d3927f227924b036248dd2bb416839a3df5b955f12c7a51cd4b5
|
4
|
+
data.tar.gz: 7259415eb72a926f64d91d4eb9f888476a39927a13335873aeb7e179a92fc7db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9da1a515bb2cf27829dc81a947a224aaba7eea61eb15d5f48a2221bbf0f06d3e077ab8d75f8cde273a9be827d6d99b1b3c9a55bbb9eacb8b65bc69abc78a0ab
|
7
|
+
data.tar.gz: e360df5da61c0d47353d95f4850bd4e7a524c29c54fcf4e0e8f0dc9a3055f78e84b32b1caf6b668bbe3cced6c4f6f36b91373bc499df4a1954a513892bb54544
|
data/README.md
CHANGED
@@ -1,19 +1,30 @@
|
|
1
|
-
# Xlog v0.1.
|
1
|
+
# Xlog v0.1.6
|
2
2
|
|
3
3
|
Xlog - awesome logger for your Rails app. Logs everything you need in well-formatted view with timestamp, caller path and tags.
|
4
4
|
|
5
5
|
## Usage
|
6
|
-
|
6
|
+
|
7
|
+
### `.info`
|
8
|
+
|
7
9
|
Log any info with `.info` method
|
10
|
+
|
8
11
|
```ruby
|
9
12
|
Xlog.info('Some info text') # [2019-04-30 12:29:13 UTC] [ArtilesController.show] [info] Message: Some info text
|
10
13
|
```
|
14
|
+
|
15
|
+
|
16
|
+
### `.warn`
|
17
|
+
|
11
18
|
Log important info with `.warn` method
|
19
|
+
|
12
20
|
```ruby
|
13
21
|
Xlog.warn('Validation failed') # [2019-04-30 12:29:13 UTC] [ArticlesController.update] [warn] Message: Validation failed
|
14
22
|
```
|
15
23
|
|
24
|
+
### `.error` and `.and_raise_error`
|
25
|
+
|
16
26
|
Xlog has awesome `.error` and `.and_raise_error` methods
|
27
|
+
|
17
28
|
```ruby
|
18
29
|
def index
|
19
30
|
10 / 0
|
@@ -22,7 +33,9 @@ def index
|
|
22
33
|
Xlog.and_raise_error(e, data: { params: params }, message: 'Some message text here')
|
23
34
|
end
|
24
35
|
```
|
36
|
+
|
25
37
|
...and the output
|
38
|
+
|
26
39
|
```
|
27
40
|
[2019-04-30 11:48:33 UTC] [Admin::OrdersController.index] [error] ZeroDivisionError: divided by 0.
|
28
41
|
| Message: Some message text here
|
@@ -31,23 +44,56 @@ end
|
|
31
44
|
| /home/me/test_app/app/controllers/admin/orders_controller.rb:7:in `/'
|
32
45
|
| /home/me/test_app/app/controllers/admin/orders_controller.rb:7:in `index'
|
33
46
|
```
|
47
|
+
|
34
48
|
The only difference between `Xlog.error` and `Xlog.and_raise_error` is that second one raises error after logging.
|
35
49
|
|
50
|
+
Log any info with `.info` method
|
51
|
+
|
36
52
|
Xlog automatically defines Rails application name and environment.
|
37
53
|
It writes logs into `log/xlog_[environement].log`
|
38
54
|
|
39
|
-
|
55
|
+
### Data
|
56
|
+
|
57
|
+
Any log method (`.info`, `.warn`, `.error`, `.and_raise_error`) supports `data: ` - named argument. Put any object as `data: my_object`
|
58
|
+
and it will be logged as "inspected" object.
|
59
|
+
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
Xlog.info('test info', data: { my: 'hash' })
|
63
|
+
# [2020-10-01 15:41:45 +0300] [(irb):4:in `irbBinding'.irb_binding] [info] Message: test info
|
64
|
+
# | Data: {:my=>"hash"}
|
65
|
+
|
66
|
+
```
|
67
|
+
|
68
|
+
### Tags
|
69
|
+
|
70
|
+
As far as `.tag_logger` is deprecated as it's not thread-safe, the new tags mechanism is presented.
|
71
|
+
Any log method (`.info`, `.warn`, `.error`, `.and_raise_error`) supports `tag: ` - named argument
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
Xlog.info('Some info text', tags: 'my_custom_tag') # [2019-04-30 12:29:13 UTC] [ArtilesController.show] [info] [my_custom_tag] Message: Some info text
|
75
|
+
Xlog.warn('Validation failed', tags: %w[validation input_error]) # [2019-04-30 12:29:13 UTC] [ArticlesController.update] [warn] [validation] [input_error] Message: Validation failed
|
76
|
+
Xlog.warn(error, tags: %w[fatal]) # [2019-04-30 12:29:13 UTC] [ArticlesController.update] [error] [fatal] Message: Zero division error
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
### `.tag_logger` [DEPRECATED]
|
81
|
+
|
40
82
|
```ruby
|
41
83
|
Xlog.tag_logger('custom_tag')
|
42
84
|
Xlog.info('Some text') # [2019-04-30 12:29:13 UTC] [ArtilesController.show] [info] [custom_tag] Message: Some info text
|
43
85
|
```
|
44
86
|
|
45
|
-
Clear tags with:
|
87
|
+
Clear tags with: [DEPRECATED]
|
88
|
+
|
46
89
|
```ruby
|
47
90
|
Xlog.clear_tags
|
48
91
|
```
|
49
|
-
|
92
|
+
|
93
|
+
## Middleware
|
94
|
+
|
50
95
|
From version 0.1.4 Xlog could be used as Rails middleware. It catches `StandardError` using `Xlog.and_raise_error`.
|
96
|
+
|
51
97
|
```ruby
|
52
98
|
# /config/application.rb
|
53
99
|
module MyApp
|
@@ -60,6 +106,7 @@ From version 0.1.4 Xlog could be used as Rails middleware. It catches `StandardE
|
|
60
106
|
```
|
61
107
|
|
62
108
|
## Configuration
|
109
|
+
|
63
110
|
Xlog is ready to use right out of the box, but it's possible to reconfigure default logger. Default logger is simple `Logger.new`. Add this code to `config/initializers/xlog.rb` and set any custom logger you want.
|
64
111
|
|
65
112
|
```ruby
|
@@ -67,7 +114,9 @@ Xlog.configure do |config|
|
|
67
114
|
config.custom_logger = Logger.new(STDOUT) # or Logger.new('foo.log', 10, 1024000) or any other
|
68
115
|
end
|
69
116
|
```
|
117
|
+
|
70
118
|
It's possible to set third-party logger like Logentries(r7rapid)
|
119
|
+
|
71
120
|
```ruby
|
72
121
|
require 'le'
|
73
122
|
|
data/lib/xlog.rb
CHANGED
@@ -9,28 +9,30 @@ module Xlog
|
|
9
9
|
class << self
|
10
10
|
attr_accessor :config, :app_name, :app_root, :base_logger, :xlogger
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
# rubocop:disable Layout/LineLength
|
13
|
+
def tag_logger(*_tags)
|
14
|
+
puts "\e[33mWARING: 'tag_logger' is no longer supported as it's not thread safe. Use 'tags: ' named argument instead for 'info', 'warn', 'error', 'and_raise_error'.\e[0m"
|
14
15
|
end
|
16
|
+
# rubocop:enable Layout/LineLength
|
15
17
|
|
16
18
|
def clear_tags
|
17
|
-
|
19
|
+
puts "\e[33mWARING: 'clear_tags' is no longer supported as it's not thread safe\e[0m"
|
18
20
|
end
|
19
21
|
|
20
|
-
def info(message, data: nil)
|
21
|
-
config.xlogger.info(message, data)
|
22
|
+
def info(message, data: nil, tags: [])
|
23
|
+
config.xlogger.info(message, data, tags)
|
22
24
|
end
|
23
25
|
|
24
|
-
def warn(message, data: nil)
|
25
|
-
config.xlogger.warn(message, data)
|
26
|
+
def warn(message, data: nil, tags: [])
|
27
|
+
config.xlogger.warn(message, data, tags)
|
26
28
|
end
|
27
29
|
|
28
|
-
def error(e, message: nil, data: nil)
|
29
|
-
config.xlogger.error(e, message, data)
|
30
|
+
def error(e, message: nil, data: nil, tags: [])
|
31
|
+
config.xlogger.error(e, message, data, tags)
|
30
32
|
end
|
31
33
|
|
32
|
-
def and_raise_error(e, message: nil, data: nil)
|
33
|
-
config.xlogger.and_raise_error(e, message, data)
|
34
|
+
def and_raise_error(e, message: nil, data: nil, tags: [])
|
35
|
+
config.xlogger.and_raise_error(e, message, data, tags)
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
data/lib/xlog/version.rb
CHANGED
data/lib/xlog/xlogger.rb
CHANGED
@@ -13,35 +13,27 @@ module Xlog
|
|
13
13
|
@folder_names_to_remove = Dir.glob('app/*').map { |f| f.gsub('app/', '') }
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def clear_tags
|
21
|
-
@tags = nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def log(type, text)
|
25
|
-
tags = [time_stamp, called_from(type), type] + Array.wrap(@tags)
|
16
|
+
def log(type, text, tags)
|
17
|
+
tags = [time_stamp, called_from(type), type] + Array.wrap(tags)
|
26
18
|
@base_logger.tagged(tags.compact) { @base_logger.send(type, text) }
|
27
19
|
end
|
28
20
|
|
29
|
-
def info(message, data)
|
30
|
-
log(:info, compose_log(message, data))
|
21
|
+
def info(message, data, tags)
|
22
|
+
log(:info, compose_log(message, data), tags)
|
31
23
|
end
|
32
24
|
|
33
|
-
def warn(message, data)
|
34
|
-
log(:warn, compose_log(message, data))
|
25
|
+
def warn(message, data, tags)
|
26
|
+
log(:warn, compose_log(message, data), tags)
|
35
27
|
end
|
36
28
|
|
37
29
|
# do NOT refactor error and and_raise_error
|
38
|
-
def error(e, message, data)
|
30
|
+
def error(e, message, data, tags)
|
39
31
|
# they MUST BE NOT DRY in order to log correct backtrace
|
40
|
-
log(:error, "#{e.class}: #{e.try(:message)}. \n #{compose_log(message, data)} \n Error backtrace: \n#{backtrace(e)}")
|
32
|
+
log(:error, "#{e.class}: #{e.try(:message)}. \n #{compose_log(message, data)} \n Error backtrace: \n#{backtrace(e)}", tags)
|
41
33
|
end
|
42
34
|
|
43
|
-
def and_raise_error(e, message, data)
|
44
|
-
log(:error, "#{e.class}: #{e.try(:message)}. #{newline} #{compose_log(message, data)} #{newline} Error backtrace: #{newline} #{backtrace(e)}")
|
35
|
+
def and_raise_error(e, message, data, tags)
|
36
|
+
log(:error, "#{e.class}: #{e.try(:message)}. #{newline} #{compose_log(message, data)} #{newline} Error backtrace: #{newline} #{backtrace(e)}", tags)
|
45
37
|
message.present? ? raise(e, message) : raise(e)
|
46
38
|
end
|
47
39
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlog
|
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
|
- OrestF
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|