multi_logger 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGES.md +9 -0
- data/README.md +15 -10
- data/lib/multi_logger.rb +13 -1
- data/lib/multi_logger/version.rb +1 -1
- metadata +10 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7781fb7ec45c05fd258ffd68a4fa97e5a892133f
|
4
|
+
data.tar.gz: 8b735244380af2fcd0b781ddafea50d05be2a183
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 436ffcf55924ee88d289f3b04f32ba698d35499cdb2fd1c9467c1938474eb20480f86dd9248b34ab4877383f072873b0140f453623c1e2287459a6c6148b7fce
|
7
|
+
data.tar.gz: e2501ae314f9c04e8e79f7cd74685e2b2993337c242e88317c935f635d893c2f209ab1694bb8b484bb56a9d7f5d988cef35af355d6311a4e435d9c77122989ea
|
data/CHANGES.md
ADDED
data/README.md
CHANGED
@@ -18,9 +18,17 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
To setup a logger, create
|
21
|
+
To setup a logger, create an initializer script such as `[Rails.root]/config/initializers/logger.rb` with:
|
22
22
|
|
23
|
-
|
23
|
+
MultiLogger.add_logger('mail')
|
24
|
+
|
25
|
+
This will create a log file located at `log/mail.log`.
|
26
|
+
|
27
|
+
Then In Rails, you can log by calling the following:
|
28
|
+
|
29
|
+
Rails.logger.mail.debug('42')
|
30
|
+
|
31
|
+
The `Rails.` reference can be omitted at the usual places in Rails (e.g. controllers and views).
|
24
32
|
|
25
33
|
Note that log_name must not collide with existing method names in Rails logger, so names such as 'debug' or 'info' can not be used. You should try calling `add_logger` in Rails console to test if it is ok or raises an error.
|
26
34
|
|
@@ -28,14 +36,11 @@ Note that log_name must not collide with existing method names in Rails logger,
|
|
28
36
|
|
29
37
|
You can assign formatter to loggers directly, or pass the formatter during setup:
|
30
38
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
formatter = CustomFormatter.new
|
39
|
+
formatter = Proc.new{|severity, time, progname, msg|
|
40
|
+
formatted_severity = sprintf("%-5s",severity.to_s)
|
41
|
+
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S")
|
42
|
+
"[#{formatted_severity} #{formatted_time} #{$$}] #{msg.to_s.strip}\n"
|
43
|
+
}
|
39
44
|
MultiLogger.add_logger('mail', formatter:formatter)
|
40
45
|
MultiLogger.add_logger('user', formatter:formatter)
|
41
46
|
|
data/lib/multi_logger.rb
CHANGED
@@ -9,7 +9,7 @@ module MultiLogger
|
|
9
9
|
if rails_logger_class.method_defined?(name)
|
10
10
|
raise "'#{name}' is reserved in #{rails_logger_class} and can not be used as a log accessor name."
|
11
11
|
else
|
12
|
-
logger = Logger.new(
|
12
|
+
logger = Logger.new(*extract_options(name, options))
|
13
13
|
rails_logger_class.class_eval do
|
14
14
|
define_method name.to_sym do
|
15
15
|
logger
|
@@ -33,6 +33,7 @@ module MultiLogger
|
|
33
33
|
if !path.end_with?('.log')
|
34
34
|
path += '.log'
|
35
35
|
end
|
36
|
+
path
|
36
37
|
end
|
37
38
|
|
38
39
|
def get_rails_logger_class
|
@@ -44,5 +45,16 @@ module MultiLogger
|
|
44
45
|
raise 'Rails logger not found'
|
45
46
|
end
|
46
47
|
end
|
48
|
+
|
49
|
+
def extract_options(name, options)
|
50
|
+
if options[:shift_age] && options[:shift_size]
|
51
|
+
[get_path(name, options[:path]), options[:shift_age], options[:shift_size]]
|
52
|
+
elsif options[:shift_age]
|
53
|
+
# options[:shift_age] => 'daily', 'weekly'
|
54
|
+
[get_path(name, options[:path]), options[:shift_age]]
|
55
|
+
else
|
56
|
+
[get_path(name, options[:path])]
|
57
|
+
end
|
58
|
+
end
|
47
59
|
end
|
48
60
|
end
|
data/lib/multi_logger/version.rb
CHANGED
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- lulalala
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: railties
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: Create multiple loggers in Rails.
|
@@ -35,6 +32,7 @@ extensions: []
|
|
35
32
|
extra_rdoc_files: []
|
36
33
|
files:
|
37
34
|
- .gitignore
|
35
|
+
- CHANGES.md
|
38
36
|
- Gemfile
|
39
37
|
- LICENSE.txt
|
40
38
|
- README.md
|
@@ -44,27 +42,26 @@ files:
|
|
44
42
|
- multi_logger.gemspec
|
45
43
|
homepage: https://github.com/lulalala/multi_logger
|
46
44
|
licenses: []
|
45
|
+
metadata: {}
|
47
46
|
post_install_message:
|
48
47
|
rdoc_options: []
|
49
48
|
require_paths:
|
50
49
|
- lib
|
51
50
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
51
|
requirements:
|
54
|
-
- -
|
52
|
+
- - '>='
|
55
53
|
- !ruby/object:Gem::Version
|
56
54
|
version: '0'
|
57
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
56
|
requirements:
|
60
|
-
- -
|
57
|
+
- - '>='
|
61
58
|
- !ruby/object:Gem::Version
|
62
59
|
version: '0'
|
63
60
|
requirements: []
|
64
61
|
rubyforge_project:
|
65
|
-
rubygems_version:
|
62
|
+
rubygems_version: 2.0.5
|
66
63
|
signing_key:
|
67
|
-
specification_version:
|
64
|
+
specification_version: 4
|
68
65
|
summary: Provide helper to define loggers and access them. Each logger will log into
|
69
66
|
a different file under the log folder.
|
70
67
|
test_files: []
|