chrono_logger 0.0.4 → 0.0.5
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 +4 -4
- data/README.md +37 -0
- data/lib/chrono_logger.rb +24 -1
- data/lib/chrono_logger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08bc980d1aec36c6dd84be8aa0964a89f026357a
|
4
|
+
data.tar.gz: 36c8767249f645a1cf6a491dd03a29e0e47a95bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 364f9de5b3a3694e4e54d4dfa2a27511c6a0d18bbcb5186f69bf538503cd950fdd46ef35681f950ec8b158977103b3fa2f4496851f1b3939e75846d0a5a40ba9
|
7
|
+
data.tar.gz: db43d8701920d88b5fa46e1b9ed3aeae4b6fa97f5b82aace8fc99431c0f64decb645a4a2953029d16ec146bab507c358423971c73acca6d2c232bc6407eb2495
|
data/README.md
CHANGED
@@ -4,10 +4,38 @@
|
|
4
4
|
[](https://travis-ci.org/ma2gedev/chrono_logger)
|
5
5
|
[](https://codeclimate.com/github/ma2gedev/chrono_logger)
|
6
6
|
[](https://coveralls.io/r/ma2gedev/chrono_logger)
|
7
|
+
[](http://inch-ci.org/github/ma2gedev/chrono_logger)
|
7
8
|
[](https://coderwall.com/ma2gedev)
|
8
9
|
|
9
10
|
A lock-free logger with timebased file rotation.
|
10
11
|
|
12
|
+
Ruby's stdlib `Logger` wraps `IO#write` in mutexes. `ChronoLogger` removes these mutexes.
|
13
|
+
|
14
|
+
`ChronoLogger` provides time based file rotation such as:
|
15
|
+
|
16
|
+
```
|
17
|
+
logger = ChronoLogger.new('/log/production.log.%Y%m%d')
|
18
|
+
Time.now.strftime('%F')
|
19
|
+
# => "2015-01-26"
|
20
|
+
File.exist?('/log/production.log.20150126')
|
21
|
+
# => true
|
22
|
+
|
23
|
+
# one day later
|
24
|
+
Time.now.strftime('%F')
|
25
|
+
# => "2015-01-27"
|
26
|
+
logger.write('hi next day')
|
27
|
+
File.exist?('/log/production.log.20150127')
|
28
|
+
# => true
|
29
|
+
```
|
30
|
+
|
31
|
+
## Motivation
|
32
|
+
|
33
|
+
Current my projects uses `::Logger` with cronolog. So
|
34
|
+
|
35
|
+
- Reduce dependency such as cronolog
|
36
|
+
- Remove mutexes in ruby world because os already does
|
37
|
+
- Support time based rotation without renaming file because file renaming is complex
|
38
|
+
|
11
39
|
## Installation
|
12
40
|
|
13
41
|
Add this line to your application's Gemfile:
|
@@ -31,6 +59,7 @@ Same interfaces ruby's stdlib `Logger` except for `new` method.
|
|
31
59
|
```
|
32
60
|
require 'chrono_logger'
|
33
61
|
|
62
|
+
# specify path with `Time#strftime` format
|
34
63
|
logger = ChronoLogger.new('development.%Y%m%d')
|
35
64
|
|
36
65
|
logger.error("Enjoy")
|
@@ -39,6 +68,10 @@ logger.info("Enjoy")
|
|
39
68
|
logger.debug("programming!")
|
40
69
|
```
|
41
70
|
|
71
|
+
## Limitation
|
72
|
+
|
73
|
+
- High performance only daily based time formatting path for example `'%Y%m%d'`. You can create pull request if you need other time period.
|
74
|
+
|
42
75
|
## Contributing
|
43
76
|
|
44
77
|
1. Fork it ( https://github.com/ma2gedev/chrono_logger/fork )
|
@@ -46,3 +79,7 @@ logger.debug("programming!")
|
|
46
79
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
80
|
4. Push to the branch (`git push origin my-new-feature`)
|
48
81
|
5. Create a new Pull Request
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
MIT. See [LICENSE.txt](LICENSE.txt) for more details.
|
data/lib/chrono_logger.rb
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
require "chrono_logger/version"
|
2
2
|
require 'logger'
|
3
3
|
|
4
|
+
# A lock-free logger with timebased file rotation.
|
4
5
|
class ChronoLogger < Logger
|
6
|
+
|
7
|
+
# @param logdev [String, IO] `Time#strftime` formatted filename (String) or IO object (typically STDOUT, STDERR, or an open file).
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# ChronoLogger.new('/log/production.log.%Y%m%d')
|
11
|
+
# Time.now.strftime('%F') => "2015-01-29"
|
12
|
+
# File.exist?('/log/production.log.20150129') => true
|
13
|
+
#
|
5
14
|
def initialize(logdev)
|
6
15
|
@progname = nil
|
7
16
|
@level = DEBUG
|
8
|
-
@default_formatter = Formatter.new
|
17
|
+
@default_formatter = ::Logger::Formatter.new
|
9
18
|
@formatter = nil
|
10
19
|
@logdev = nil
|
11
20
|
if logdev
|
@@ -126,4 +135,18 @@ class ChronoLogger < Logger
|
|
126
135
|
end
|
127
136
|
end
|
128
137
|
end
|
138
|
+
|
139
|
+
# EXPERIMENTAL: this formatter faster than default `Logger::Formatter`
|
140
|
+
class Formatter < ::Logger::Formatter
|
141
|
+
DATETIME_SPRINTF_FORMAT = "%04d-%02d-%02dT%02d:%02d:%02d.%06d ".freeze
|
142
|
+
|
143
|
+
# same as `Logger::Formatter#format_datetime`'s default behaviour
|
144
|
+
def format_datetime(t)
|
145
|
+
DATETIME_SPRINTF_FORMAT % [t.year, t.month, t.day, t.hour, t.min, t.sec, t.tv_usec]
|
146
|
+
end
|
147
|
+
|
148
|
+
def datetime_format=(datetime_format)
|
149
|
+
raise 'do not support'
|
150
|
+
end
|
151
|
+
end
|
129
152
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chrono_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takayuki Matsubara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|