m_logger 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +29 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +24 -0
- data/Gemfile +18 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +12 -0
- data/lib/m_logger/log_device.rb +35 -0
- data/lib/m_logger/version.rb +7 -0
- data/lib/m_logger.rb +41 -0
- data/sig/m_logger.rbs +7 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5ab935220e9964b456211ac44530ec4ed0b1acc3a9056fc9d4f511bd3369cc89
|
4
|
+
data.tar.gz: 0baa8caea36c18c9dcfbbe0994dfeeca14d6f55c449b1fd2001d754e912141a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad55e1f2e8a2e36973ecc991c746b2843ed374829b4a3c3e5c1594303ab4b563fd6f4df242fdf76b59fa1f07709b2c2c0f241fad89010519d96530443b287e38
|
7
|
+
data.tar.gz: b483f89c0539e4e7753908b9fbc1f6fd7bd9b1c505f88f2a8cb89b03d2a8fe12ae352fe96319f9541431ffae79854addacb1bbdbfc9d5b00b83b2ae0aafa9fe5
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Layout/FirstHashElementIndentation:
|
16
|
+
EnforcedStyle: consistent
|
17
|
+
|
18
|
+
Layout/ArgumentAlignment:
|
19
|
+
EnforcedStyle: with_fixed_indentation
|
20
|
+
|
21
|
+
Layout/MultilineMethodCallBraceLayout:
|
22
|
+
EnforcedStyle: new_line
|
23
|
+
|
24
|
+
Style/Documentation:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Metrics/BlockLength:
|
28
|
+
Exclude:
|
29
|
+
- spec/**/*.rb
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
# Contributor Code of Conduct
|
3
|
+
|
4
|
+
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
5
|
+
|
6
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
|
7
|
+
|
8
|
+
Examples of unacceptable behavior by participants include:
|
9
|
+
|
10
|
+
* The use of sexualized language or imagery
|
11
|
+
* Personal attacks
|
12
|
+
* Trolling or insulting/derogatory comments
|
13
|
+
* Public or private harassment
|
14
|
+
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
|
15
|
+
* Other unethical or unprofessional conduct
|
16
|
+
|
17
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
|
18
|
+
|
19
|
+
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
|
20
|
+
|
21
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
22
|
+
|
23
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.2.0, available at https://www.contributor-covenant.org/version/1/2/0/code-of-conduct.html
|
24
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in m_logger.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
|
14
|
+
gem "timecop"
|
15
|
+
|
16
|
+
gem "pry-byebug"
|
17
|
+
|
18
|
+
gem "parallel"
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 DeNA
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# MLogger
|
2
|
+
|
3
|
+
MLogger is a simple logger featuring an alternative log rotation strategy, specially designed to handle high traffic loads and transient environments.
|
4
|
+
|
5
|
+
To use MLogger, initiate a new logger with `MLogger.new('log/production.log', shift_period_suffix: '%Y%m%d_%H')`.
|
6
|
+
|
7
|
+
## Log Rotation Strategy
|
8
|
+
|
9
|
+
Here's how ordinary log rotation strategy works:
|
10
|
+
|
11
|
+
1. Logs are consistently written to the same file (e.g., `production.log`).
|
12
|
+
2. The file is renamed once a specified time or size limit is reached (e.g., `production.log` becomes `production.log.20230701`).
|
13
|
+
|
14
|
+
In contrast, MLogger employs a different log rotation strategy:
|
15
|
+
|
16
|
+
1. Each log message is written to a time-stamped file (e.g., `production.log.20230701_11`).
|
17
|
+
2. Upon reaching a time threshold, logging is switched to a new file with the updated timestamp (e.g., `production.log.20230701_12`).
|
18
|
+
|
19
|
+
Key advantages of using MLogger include:
|
20
|
+
|
21
|
+
1. Support for hourly and shorter shift periods, accommodating heavy traffic loads.
|
22
|
+
2. Log lines always exist within the appropriately time-stamped path, even in cases where there are no logs or when there is an overflow of logs beyond shift periods.
|
23
|
+
|
24
|
+
## Additional Features
|
25
|
+
|
26
|
+
1. For systems expecting an IO-like interface, you can utilize `MLogger::LoggerDevice` (`MLogger::LoggerDevice#write`).
|
27
|
+
2. To facilitate line-based operations, MLogger skips writing a log header (e.g., `# Logfile created on %s by %s`).
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
Install the gem and add to the application's Gemfile by executing:
|
32
|
+
|
33
|
+
$ bundle add m_logger
|
34
|
+
|
35
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
36
|
+
|
37
|
+
$ gem install m_logger
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# Log to File
|
43
|
+
hourly_logger = MLogger.new('log/my_log', shift_period_suffix: '%Y%m%d_%H') # hourly rotate
|
44
|
+
hourly_logger.debug('fuga')
|
45
|
+
|
46
|
+
daily_logger = MLogger.new('log/my_log', shift_period_suffix: '%Y%m%d') # daily rotate
|
47
|
+
daily_logger.debug('fuga')
|
48
|
+
|
49
|
+
# Log in Rack::Middleware
|
50
|
+
logger_device = MLogger::Device.new('log/rack_ltsv', shift_period_suffix: '%Y%m%d_%H')
|
51
|
+
Rails.configuration.middleware.insert(0, Rack::LtsvLogger, logger_device)
|
52
|
+
|
53
|
+
# Log to Stdout (You don't have to change logger class.)
|
54
|
+
logger = MLogger.new(STDOUT)
|
55
|
+
logger.info('hoge')
|
56
|
+
```
|
57
|
+
|
58
|
+
## Development
|
59
|
+
|
60
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
61
|
+
|
62
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/DeNA/m_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/DeNA/m_logger/blob/master/CODE_OF_CONDUCT.md).
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
71
|
+
|
72
|
+
## Code of Conduct
|
73
|
+
|
74
|
+
Everyone interacting in the MLogger project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/DeNA/m_logger/blob/master/CODE_OF_CONDUCT.md).
|
75
|
+
|
76
|
+
## Special Thanks
|
77
|
+
|
78
|
+
External log file specification originates from Mobage and Sakasho series in DeNA.
|
79
|
+
Thanks for those who have contributed to these products.
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
|
5
|
+
class MLogger
|
6
|
+
class LogDevice < ::Logger::LogDevice
|
7
|
+
def initialize(log = nil, *args, shift_period_suffix: nil, **kwargs)
|
8
|
+
# When the output is file, save original name, and append shift_period_suffix.
|
9
|
+
is_file = log && !(log.respond_to?(:write) && log.respond_to?(:close))
|
10
|
+
if is_file
|
11
|
+
@original_filename = log
|
12
|
+
log = m_logger_filename(shift_period_suffix)
|
13
|
+
end
|
14
|
+
|
15
|
+
super(log, *args, shift_period_suffix: shift_period_suffix, **kwargs)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def check_shift_log
|
21
|
+
# Switch to a new file, when the time has come.
|
22
|
+
return unless @filename && @filename < (f = m_logger_filename(@shift_period_suffix))
|
23
|
+
|
24
|
+
reopen(f)
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_log_header(_file)
|
28
|
+
# skip writing log header
|
29
|
+
end
|
30
|
+
|
31
|
+
def m_logger_filename(suffix)
|
32
|
+
"#{@original_filename}.#{Time.now.strftime(suffix)}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/m_logger.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
|
5
|
+
require_relative "m_logger/version"
|
6
|
+
require_relative "m_logger/log_device"
|
7
|
+
|
8
|
+
class MLogger < ::Logger
|
9
|
+
# rubocop:disable Lint/MissingSuper,Metrics/MethodLength,Metrics/ParameterLists
|
10
|
+
def initialize(logdev, shift_age = 0, shift_size = 1_048_576, level: DEBUG,
|
11
|
+
progname: nil, formatter: nil, datetime_format: nil,
|
12
|
+
binmode: false, shift_period_suffix: "%Y%m%d")
|
13
|
+
|
14
|
+
self.level = level
|
15
|
+
self.progname = progname
|
16
|
+
@default_formatter = Formatter.new
|
17
|
+
self.datetime_format = datetime_format
|
18
|
+
self.formatter = formatter
|
19
|
+
@logdev = nil
|
20
|
+
@level_override = {}
|
21
|
+
|
22
|
+
return unless logdev && logdev != File::NULL
|
23
|
+
|
24
|
+
# Only this part is different from original ::Logger
|
25
|
+
@logdev = if RUBY_VERSION >= "2.7.0"
|
26
|
+
MLogger::LogDevice.new(logdev,
|
27
|
+
shift_age: shift_age,
|
28
|
+
shift_size: shift_size,
|
29
|
+
shift_period_suffix: shift_period_suffix,
|
30
|
+
binmode: binmode
|
31
|
+
)
|
32
|
+
else
|
33
|
+
MLogger::LogDevice.new(logdev,
|
34
|
+
shift_age: shift_age,
|
35
|
+
shift_size: shift_size,
|
36
|
+
shift_period_suffix: shift_period_suffix
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
# rubocop:enable Lint/MissingSuper,Metrics/MethodLength,Metrics/ParameterLists
|
41
|
+
end
|
data/sig/m_logger.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: m_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takumasa Ochi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple Logger with Alternative Log Rotation Strategy
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".rspec"
|
20
|
+
- ".rubocop.yml"
|
21
|
+
- CHANGELOG.md
|
22
|
+
- CODE_OF_CONDUCT.md
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/m_logger.rb
|
28
|
+
- lib/m_logger/log_device.rb
|
29
|
+
- lib/m_logger/version.rb
|
30
|
+
- sig/m_logger.rbs
|
31
|
+
homepage: https://github.com/DeNA/m_logger
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata:
|
35
|
+
homepage_uri: https://github.com/DeNA/m_logger
|
36
|
+
source_code_uri: https://github.com/DeNA/m_logger
|
37
|
+
changelog_uri: https://github.com/DeNA/m_logger/blob/master/CHANGELOG.md
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.6.0
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.4.13
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Simple Logger with Alternative Log Rotation Strategy
|
57
|
+
test_files: []
|