chrono_logger 0.0.5 → 1.0.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 +4 -4
- data/README.md +29 -4
- data/lib/chrono_logger.rb +4 -4
- 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: 9e088e9bf45178e23ef873d64e92e168bc026f41
|
4
|
+
data.tar.gz: 8fcc295b88f5edac15e16f1af825aa2b9d9e64db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3af87c076d10eae81b2a574204c516280fc1b35020c3123a0e9846c2d9e88c928fa8f460c9d872a2f2684aedd339a5c5f81de3a9ef85b68439dea32f6c816e7
|
7
|
+
data.tar.gz: ad7dcd2fd514cc53ef23947477ed67a020112e130326d893642fdfdbd65e41df6e9b8ac0c96f030534fcebb08f82f5a53faae804519e446d24b3fdcf9ce58902
|
data/README.md
CHANGED
@@ -33,8 +33,8 @@ File.exist?('/log/production.log.20150127')
|
|
33
33
|
Current my projects uses `::Logger` with cronolog. So
|
34
34
|
|
35
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
|
36
|
+
- Remove mutexes in ruby world because os already does when some environments (ex: ext4 file system)
|
37
|
+
- Support time based rotation without renaming file because file renaming sometime makes problem
|
38
38
|
|
39
39
|
## Installation
|
40
40
|
|
@@ -56,7 +56,7 @@ Or install it yourself as:
|
|
56
56
|
|
57
57
|
Same interfaces ruby's stdlib `Logger` except for `new` method.
|
58
58
|
|
59
|
-
```
|
59
|
+
```ruby
|
60
60
|
require 'chrono_logger'
|
61
61
|
|
62
62
|
# specify path with `Time#strftime` format
|
@@ -68,9 +68,29 @@ logger.info("Enjoy")
|
|
68
68
|
logger.debug("programming!")
|
69
69
|
```
|
70
70
|
|
71
|
+
With Rails:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# in config/environments/{development,production}.rb
|
75
|
+
|
76
|
+
config.logger = ChronoLogger.new("#{config.paths['log'].first}.%Y%m%d")
|
77
|
+
```
|
78
|
+
|
79
|
+
## Migrating from `::Logger` with cronolog
|
80
|
+
|
81
|
+
You only change `Logger.new` into `ChronoLogger.new`:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
# for instance your setup is like the following
|
85
|
+
Logger.new(IO.popen("/usr/sbin/cronolog production.%Y%m%d", "w"))
|
86
|
+
|
87
|
+
# turns into
|
88
|
+
ChronoLogger.new('production.%Y%m%d')
|
89
|
+
```
|
90
|
+
|
71
91
|
## Limitation
|
72
92
|
|
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.
|
93
|
+
- High performance logging only daily based time formatting path for example `'%Y%m%d'`. You can create pull request if you need other time period.
|
74
94
|
|
75
95
|
## Contributing
|
76
96
|
|
@@ -83,3 +103,8 @@ logger.debug("programming!")
|
|
83
103
|
## License
|
84
104
|
|
85
105
|
MIT. See [LICENSE.txt](LICENSE.txt) for more details.
|
106
|
+
|
107
|
+
## Resources
|
108
|
+
|
109
|
+
- [ChronoLogger logging is 1.5x faster than ruby's stdlib Logger](https://coderwall.com/p/vjjszq/chronologger-logging-is-1-5x-faster-than-ruby-s-stdlib-logger)
|
110
|
+
|
data/lib/chrono_logger.rb
CHANGED
@@ -69,7 +69,7 @@ class ChronoLogger < Logger
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def write(message)
|
72
|
-
|
72
|
+
check_and_shift_log if @pattern
|
73
73
|
@dev.write(message)
|
74
74
|
rescue
|
75
75
|
warn("log writing failed. #{$!}")
|
@@ -101,12 +101,12 @@ class ChronoLogger < Logger
|
|
101
101
|
logdev
|
102
102
|
end
|
103
103
|
|
104
|
-
def
|
104
|
+
def check_and_shift_log
|
105
105
|
if next_period?(Time.now)
|
106
106
|
now = Time.now
|
107
107
|
new_filename = now.strftime(@pattern)
|
108
108
|
next_start_period = next_start_period(now, @period)
|
109
|
-
|
109
|
+
shift_log(new_filename)
|
110
110
|
@filename = new_filename
|
111
111
|
@next_start_period = next_start_period
|
112
112
|
end
|
@@ -120,7 +120,7 @@ class ChronoLogger < Logger
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
-
def
|
123
|
+
def shift_log(filename)
|
124
124
|
begin
|
125
125
|
@mutex.synchronize do
|
126
126
|
tmp_dev = @dev
|
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: 1.0.0
|
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-
|
11
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|