smart_logger_wrapper 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/lib/smart_logger_wrapper/version.rb +1 -1
- data/lib/smart_logger_wrapper.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 444b6317f04b10930e9ad6ec0d0efde371ecc9ca
|
4
|
+
data.tar.gz: 39aa6ff2667da7d5f8ec1b83d8bfb3bdd09e3307
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07f7e3686b7e480b09b20cd39f1a09b62af4b004073792a2f46076ad841b65ede344f3cc28db455fd9fed4ac6a42c7d4abd318295f2e1e2be28ac9606daa5d4f
|
7
|
+
data.tar.gz: 5da56581d007acb6d0646e817fbf2d85a78b52b72f0352810172a59cb330eba5fb059d0786970598c59fa81418e7c8b6047026d357c730b85048f7de9ac8c7a9
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
### For Ruby on Rails
|
24
24
|
|
25
|
-
Wrap your logger with `SmartLoggerWrapper`, for example
|
25
|
+
Wrap your logger with `SmartLoggerWrapper`, for example, in `config/environments/production.rb`:
|
26
26
|
|
27
27
|
```diff
|
28
28
|
- config.logger = Logger.new('log/production.log', 'daily')
|
@@ -31,6 +31,14 @@ Wrap your logger with `SmartLoggerWrapper`, for example:
|
|
31
31
|
|
32
32
|
Note that it is strongly recommended to use the wrapper for all environments so that you can avoid exceptions such as `NoMethodError` due to the unique features of this library.
|
33
33
|
|
34
|
+
You may want to put log messages to STDOUT in the development environment. Then:
|
35
|
+
|
36
|
+
```
|
37
|
+
logger = ActiveSupport::Logger.new("log/development.log")
|
38
|
+
logger.extend ActiveSupport::Logger.broadcast(ActiveSupport::Logger.new(STDOUT))
|
39
|
+
config.logger = SmartLoggerWrapper.new(logger)
|
40
|
+
```
|
41
|
+
|
34
42
|
## Usage
|
35
43
|
|
36
44
|
### Basic
|
data/lib/smart_logger_wrapper.rb
CHANGED
@@ -21,21 +21,21 @@ class SmartLoggerWrapper
|
|
21
21
|
@options = options
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
24
|
+
def add(severity, *args, &block)
|
25
|
+
_add(severity, *args, &block)
|
26
26
|
end
|
27
|
-
alias add
|
27
|
+
alias log add
|
28
28
|
|
29
29
|
SEVERITY_MAPPING.each do |severity_name, severity|
|
30
30
|
define_method(severity_name) do |*args, &block|
|
31
|
-
|
31
|
+
_add(severity, *args, &block)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
37
|
# All methods calling this must have the synchronized call stack depth so that this can show neat positions and backtraces
|
38
|
-
def
|
38
|
+
def _add(severity, *args, &block)
|
39
39
|
messages = args.map { |arg| to_message(arg) }
|
40
40
|
messages << to_message(block.call) if block_given?
|
41
41
|
begin
|
@@ -49,7 +49,7 @@ class SmartLoggerWrapper
|
|
49
49
|
false
|
50
50
|
end.tap do |succeeded|
|
51
51
|
messages.each do |message|
|
52
|
-
logger.
|
52
|
+
logger.add(severity, nil, message)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|