yologga 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +43 -0
- data/CONTRIBUTING.md +40 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +8 -0
- data/bin/console +7 -0
- data/lib/yologga.rb +101 -0
- data/lib/yologga/gzip.rb +14 -0
- data/lib/yologga/logs_lifetime.rb +24 -0
- data/lib/yologga/patch/ruby_2_3.rb +73 -0
- data/lib/yologga/patch/ruby_2_4.rb +89 -0
- data/lib/yologga/patch/ruby_2_5.rb +13 -0
- data/lib/yologga/version.rb +5 -0
- data/yologga.gemspec +27 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8d1935f0cbadf7d09217450c1d40688017c76a35
|
4
|
+
data.tar.gz: c1b572a957e544963cf3feb8a2de592f76551912
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7fc182f3b9be3fc86ae3d2e1f26a54e4c7a9e6a7dfd1fd8d41baf1e924ba07fe4fb7ec04cba526498549102c3b8ec18b0d20a8d40199160510aceec5234156b9
|
7
|
+
data.tar.gz: 92ebc2f8ab65732399254a161388aaf2ba133dc72d0295b8318cd55c0f7c26ae1ef70b53bdf9ba8c36c54b3b5ce15c05adbda22f1cb1fa896831bc7be430bb45
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
rvm:
|
4
|
+
- 2.2
|
5
|
+
- 2.3
|
6
|
+
- 2.4
|
7
|
+
- 2.5
|
8
|
+
before_install: gem install bundler
|
9
|
+
env: SUITE="rspec"
|
10
|
+
script: bundle exec $SUITE
|
11
|
+
matrix:
|
12
|
+
fast_finish: true
|
13
|
+
include:
|
14
|
+
- rvm: 2.5
|
15
|
+
env: SUITE="rubocop"
|
16
|
+
allow_failures:
|
17
|
+
- rvm: ruby-head
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [0.2.0] - 2018-03-12
|
8
|
+
### Added
|
9
|
+
- Ruby 2.3, 2.4, 2.5 support
|
10
|
+
|
11
|
+
## [0.1.0] - 2018-03-05
|
12
|
+
### Added
|
13
|
+
- Initial release
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
## CONTRIBUTOR COVENANT CODE OF CONDUCT
|
2
|
+
|
3
|
+
### Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
### Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
- Using welcoming and inclusive language
|
12
|
+
- Being respectful of differing viewpoints and experiences
|
13
|
+
- Gracefully accepting constructive criticism
|
14
|
+
- Focusing on what is best for the community
|
15
|
+
- Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
- The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
- Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
- Public or private harassment
|
22
|
+
- Publishing others’ private information, such as a physical or electronic address, without explicit permission
|
23
|
+
- Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
### Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
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, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
### Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
### Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at info@umbrellio.biz. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project’s leadership.
|
40
|
+
|
41
|
+
### Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), version 1.4, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct.html](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html)
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
## CONTRIBUTING RULES
|
2
|
+
|
3
|
+
Here are some ways you can contribute:
|
4
|
+
|
5
|
+
- by using alpha, beta, and prerelease versions;
|
6
|
+
- by reporting bugs;
|
7
|
+
- by suggesting new features;
|
8
|
+
- by writing or editing documentation;
|
9
|
+
- by writing specifications;
|
10
|
+
- by writing code (no patch is too small: fix typos, add comments, clean up inconsistent whitespace);
|
11
|
+
- by refactoring code;
|
12
|
+
- by closing issues;
|
13
|
+
- by reviewing patches.
|
14
|
+
|
15
|
+
### Submitting an Issue
|
16
|
+
|
17
|
+
We use the GitHub issue tracker to track bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. When submitting a bug report, please include a Gist that includes a stack trace and any details that may be necessary to reproduce the bug, including your gem version, Ruby version, and operating system. Ideally, a bug report should include a pull request with failing specs.
|
18
|
+
|
19
|
+
### Reporting Issues
|
20
|
+
|
21
|
+
A well formatted issue is appreciated, and goes a long way in helping us help you.
|
22
|
+
|
23
|
+
- Make sure you have a GitHub account;
|
24
|
+
- Submit a Github issue by:
|
25
|
+
- Clearly describing the issue
|
26
|
+
- Provide a descriptive summary;
|
27
|
+
- Explain the expected behavior;
|
28
|
+
- Explain the actual behavior;
|
29
|
+
- Provide steps to reproduce the actual behavior;
|
30
|
+
- Any relevant stack traces;
|
31
|
+
- If you provide code, make sure it is formatted with the triple backticks (`).
|
32
|
+
|
33
|
+
### Submitting a Pull Request
|
34
|
+
|
35
|
+
- Fork the repository;
|
36
|
+
- Create a topic branch;
|
37
|
+
- Implement your feature or bug fix;
|
38
|
+
- Add specs for your unimplemented feature or bug fix;
|
39
|
+
- Add, commit, and push your changes;
|
40
|
+
- Submit a pull request.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Dmitry Gubitskiy
|
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,59 @@
|
|
1
|
+
# Yologga
|
2
|
+
|
3
|
+
Logger class patch for hourly log rotation support
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/umbrellio/yologga.svg?branch=master)](https://travis-ci.org/umbrellio/yologga)
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
Ruby 2.3, 2.4 or 2.5
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
- `gem install logga` and `require "yologga"`
|
14
|
+
- Or add it to your Gemfile and `bundle`
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Requiring the gem automatically adds an `hourly` rotation period support to Ruby's standard
|
19
|
+
Logger class. You can initialize it like this:
|
20
|
+
|
21
|
+
```
|
22
|
+
Logger.new('some_log_file', 'hourly')
|
23
|
+
```
|
24
|
+
|
25
|
+
Keep in mind that loggers created before the gem is required will not
|
26
|
+
support the hourly rotation period. Specifically, in case of a Rails app,
|
27
|
+
require this before Rails initializes; a good place to do that is in `application.rb`
|
28
|
+
right after requiring `boot`
|
29
|
+
|
30
|
+
### Setting default rotation period
|
31
|
+
|
32
|
+
`Yologga.default_rotation_period = some_period` will make it so newly created
|
33
|
+
loggers have a rotation period of `some_period` unless you provide an explicit
|
34
|
+
period in the constructor
|
35
|
+
|
36
|
+
### Setting autogzip on
|
37
|
+
|
38
|
+
`Yologga.gzip = true`
|
39
|
+
adds gzipping for rotated logs (disabled by default)
|
40
|
+
|
41
|
+
### Setting logs LogsLifetime
|
42
|
+
|
43
|
+
`Yologga.logs_lifetime = 1.week `
|
44
|
+
or
|
45
|
+
`Yologga.logs_lifetime = 604800`
|
46
|
+
|
47
|
+
removes logs older than chosen period
|
48
|
+
|
49
|
+
## License
|
50
|
+
Released under MIT License
|
51
|
+
|
52
|
+
## Authors
|
53
|
+
Created by Dmitry Gubitskiy
|
54
|
+
Evgeniy Lukovsky
|
55
|
+
|
56
|
+
<a href="https://github.com/umbrellio/">
|
57
|
+
<img style="float: left;" src="https://umbrellio.github.io/Umbrellio/supported_by_umbrellio.svg"
|
58
|
+
alt="Supported by Umbrellio" width="439" height="72">
|
59
|
+
</a>
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/lib/yologga.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
require "yologga/version"
|
5
|
+
require "yologga/gzip"
|
6
|
+
require "yologga/logs_lifetime"
|
7
|
+
|
8
|
+
pattern = File.join(File.dirname(__FILE__), "yologga", "patch", "*.rb")
|
9
|
+
Dir[pattern].each { |file| require_relative(file) }
|
10
|
+
|
11
|
+
module Yologga
|
12
|
+
class << self
|
13
|
+
attr_reader :gzip, :logs_lifetime
|
14
|
+
|
15
|
+
def add_hourly_rotation_period_support!
|
16
|
+
if hourly_mixin
|
17
|
+
Logger::LogDevice.prepend(hourly_mixin)
|
18
|
+
else
|
19
|
+
warn unsupported_warning
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_rotation_period=(period)
|
24
|
+
raise unsupported_warning if period == "hourly" && !hourly_mixin
|
25
|
+
|
26
|
+
mixin = Module.new do
|
27
|
+
define_method(:initialize) do |logdev, shift_age = period, *args|
|
28
|
+
super(logdev, shift_age, *args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Logger.prepend(mixin)
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# :call-seq:
|
37
|
+
# gzip=(enabled)
|
38
|
+
#
|
39
|
+
# === Args
|
40
|
+
#
|
41
|
+
# +enabled+:: Boolean true of false
|
42
|
+
#
|
43
|
+
# === Examples
|
44
|
+
#
|
45
|
+
# Yologga.gzip = false
|
46
|
+
# Yologga.gzip = true
|
47
|
+
#
|
48
|
+
# === Return
|
49
|
+
#
|
50
|
+
# supplied value or raises an Error
|
51
|
+
#
|
52
|
+
def gzip=(enabled)
|
53
|
+
raise unable_to_find_gzip if enabled && !system("gzip --help &> /dev/null")
|
54
|
+
@gzip = enabled
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# :call-seq:
|
59
|
+
# logs_lifetime=(logs_lifetime)
|
60
|
+
#
|
61
|
+
# === Args
|
62
|
+
#
|
63
|
+
# +logs_lifetime+:: ActiveSupport::Duration representing logs lifetime
|
64
|
+
#
|
65
|
+
# === Examples
|
66
|
+
#
|
67
|
+
# Yologga.logs_lifetime = 9.hours
|
68
|
+
# Yologga.logs_lifetime = 30.days
|
69
|
+
#
|
70
|
+
# === Return
|
71
|
+
#
|
72
|
+
# supplied value
|
73
|
+
#
|
74
|
+
def logs_lifetime=(logs_lifetime)
|
75
|
+
@logs_lifetime = logs_lifetime
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def hourly_mixin
|
81
|
+
return @mixin if defined?(@mixin)
|
82
|
+
|
83
|
+
mixin_name = "Yologga::Patch::Ruby_#{RUBY_VERSION.split('.').first(2).join('_')}"
|
84
|
+
@mixin = begin
|
85
|
+
Module.const_get(mixin_name)
|
86
|
+
rescue NameError
|
87
|
+
nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def unable_to_find_gzip
|
92
|
+
"Unable to find gzip in PATH environment variable."
|
93
|
+
end
|
94
|
+
|
95
|
+
def unsupported_warning
|
96
|
+
"Hourly log rotation period is not supported for Ruby #{RUBY_VERSION}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
Yologga.add_hourly_rotation_period_support!
|
data/lib/yologga/gzip.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
class Yologga::LogsLifetime
|
6
|
+
attr_accessor :pathname
|
7
|
+
|
8
|
+
def initialize(filename)
|
9
|
+
self.pathname = Pathname.new(filename)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
return unless Yologga.logs_lifetime
|
14
|
+
entries = Dir.glob(pathname.dirname.join("#{pathname.basename}*")).map { |f| Pathname.new(f) }
|
15
|
+
entries.each do |entry|
|
16
|
+
next unless entry.file?
|
17
|
+
old_enough = entry.mtime < (Time.now - Yologga.logs_lifetime)
|
18
|
+
|
19
|
+
if entry.basename.to_s =~ /\.log\.\d+\z/ && old_enough
|
20
|
+
entry.delete
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
|
5
|
+
module Yologga
|
6
|
+
module Patch
|
7
|
+
# rubocop:disable Naming/ClassAndModuleCamelCase
|
8
|
+
module Ruby_2_3
|
9
|
+
# rubocop:enable Naming/ClassAndModuleCamelCase
|
10
|
+
SiD = Logger::Period::SiD
|
11
|
+
|
12
|
+
def shift_log_period(period_end)
|
13
|
+
format = @shift_age == "hourly" ? "%Y%m%d%H" : "%Y%m%d"
|
14
|
+
postfix = period_end.strftime(format)
|
15
|
+
age_file = "#{@filename}.#{postfix}"
|
16
|
+
if FileTest.exist?(age_file)
|
17
|
+
# try to avoid filename crash caused by Timestamp change.
|
18
|
+
idx = 0
|
19
|
+
# .99 can be overridden; avoid too much file search with 'loop do'
|
20
|
+
while idx < 100
|
21
|
+
idx += 1
|
22
|
+
age_file = "#{@filename}.#{postfix}.#{idx}"
|
23
|
+
break unless FileTest.exist?(age_file)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@dev.close rescue nil
|
27
|
+
File.rename(@filename.to_s, age_file)
|
28
|
+
@dev = create_logfile(@filename)
|
29
|
+
Yologga::Gzip.new(age_file).call if Yologga.gzip
|
30
|
+
Yologga::LogsLifetime.new(@filename).call
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def next_rotate_time(now, shift_age)
|
35
|
+
case shift_age
|
36
|
+
when "hourly"
|
37
|
+
t = Time.mktime(now.year, now.month, now.mday, now.hour) + SiD / 24
|
38
|
+
when "daily"
|
39
|
+
t = Time.mktime(now.year, now.month, now.mday) + SiD
|
40
|
+
when "weekly"
|
41
|
+
t = Time.mktime(now.year, now.month, now.mday) + SiD * (7 - now.wday)
|
42
|
+
when "monthly"
|
43
|
+
t = Time.mktime(now.year, now.month, 1) + SiD * 32
|
44
|
+
return Time.mktime(t.year, t.month, 1)
|
45
|
+
else
|
46
|
+
return now
|
47
|
+
end
|
48
|
+
if t.min.nonzero? or t.sec.nonzero?
|
49
|
+
min = t.min
|
50
|
+
t = Time.mktime(t.year, t.month, t.mday, t.hour)
|
51
|
+
t += (SiD / 24) if min > 30
|
52
|
+
end
|
53
|
+
t
|
54
|
+
end
|
55
|
+
|
56
|
+
def previous_period_end(now, shift_age)
|
57
|
+
case shift_age
|
58
|
+
when "hourly"
|
59
|
+
t = Time.mktime(now.year, now.month, now.mday, now.hour) - 1
|
60
|
+
when "daily"
|
61
|
+
t = Time.mktime(now.year, now.month, now.mday) - 1
|
62
|
+
when "weekly"
|
63
|
+
t = Time.mktime(now.year, now.month, now.mday) - (SiD * now.wday + 1)
|
64
|
+
when "monthly"
|
65
|
+
t = Time.mktime(now.year, now.month, 1) - 1
|
66
|
+
else
|
67
|
+
return now
|
68
|
+
end
|
69
|
+
Time.mktime(t.year, t.month, t.mday, t.hour, 59, 59)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
|
5
|
+
module Yologga
|
6
|
+
module Patch
|
7
|
+
# rubocop:disable Naming/ClassAndModuleCamelCase
|
8
|
+
module Ruby_2_4
|
9
|
+
# rubocop:enable Naming/ClassAndModuleCamelCase
|
10
|
+
SiD = Logger::Period::SiD
|
11
|
+
|
12
|
+
def initialize(log = nil, shift_age: nil, shift_size: nil, shift_period_suffix: nil)
|
13
|
+
@dev = @filename = @shift_age = @shift_size = @shift_period_suffix = nil
|
14
|
+
mon_initialize
|
15
|
+
set_dev(log)
|
16
|
+
if @filename
|
17
|
+
@shift_age = shift_age || 7
|
18
|
+
@shift_size = shift_size || 1048576
|
19
|
+
suffix = shift_age == "hourly" ? "%Y%m%d%H" : (shift_period_suffix || "%Y%m%d")
|
20
|
+
@shift_period_suffix = suffix
|
21
|
+
|
22
|
+
unless @shift_age.is_a?(Integer)
|
23
|
+
base_time = @dev.respond_to?(:stat) ? @dev.stat.mtime : Time.now
|
24
|
+
@next_rotate_time = next_rotate_time(base_time, @shift_age)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def shift_log_period(period_end)
|
30
|
+
suffix = period_end.strftime(@shift_period_suffix)
|
31
|
+
age_file = "#{@filename}.#{suffix}"
|
32
|
+
if FileTest.exist?(age_file)
|
33
|
+
# try to avoid filename crash caused by Timestamp change.
|
34
|
+
idx = 0
|
35
|
+
# .99 can be overridden; avoid too much file search with 'loop do'
|
36
|
+
while idx < 100
|
37
|
+
idx += 1
|
38
|
+
age_file = "#{@filename}.#{suffix}.#{idx}"
|
39
|
+
break unless FileTest.exist?(age_file)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@dev.close rescue nil
|
43
|
+
File.rename(@filename.to_s, age_file)
|
44
|
+
@dev = create_logfile(@filename)
|
45
|
+
Yologga::Gzip.new(age_file).call if Yologga.gzip
|
46
|
+
Yologga::LogsLifetime.new(@filename).call
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
def next_rotate_time(now, shift_age)
|
51
|
+
case shift_age
|
52
|
+
when "hourly"
|
53
|
+
t = Time.mktime(now.year, now.month, now.mday, now.hour) + SiD / 24
|
54
|
+
when "daily"
|
55
|
+
t = Time.mktime(now.year, now.month, now.mday) + SiD
|
56
|
+
when "weekly"
|
57
|
+
t = Time.mktime(now.year, now.month, now.mday) + SiD * (7 - now.wday)
|
58
|
+
when "monthly"
|
59
|
+
t = Time.mktime(now.year, now.month, 1) + SiD * 32
|
60
|
+
return Time.mktime(t.year, t.month, 1)
|
61
|
+
else
|
62
|
+
return now
|
63
|
+
end
|
64
|
+
if t.min.nonzero? or t.sec.nonzero?
|
65
|
+
min = t.min
|
66
|
+
t = Time.mktime(t.year, t.month, t.mday, t.hour)
|
67
|
+
t += (SiD / 24) if min > 30
|
68
|
+
end
|
69
|
+
t
|
70
|
+
end
|
71
|
+
|
72
|
+
def previous_period_end(now, shift_age)
|
73
|
+
case shift_age
|
74
|
+
when "hourly"
|
75
|
+
t = Time.mktime(now.year, now.month, now.mday, now.hour) - 1
|
76
|
+
when "daily"
|
77
|
+
t = Time.mktime(now.year, now.month, now.mday) - 1
|
78
|
+
when "weekly"
|
79
|
+
t = Time.mktime(now.year, now.month, now.mday) - (SiD * now.wday + 1)
|
80
|
+
when "monthly"
|
81
|
+
t = Time.mktime(now.year, now.month, 1) - 1
|
82
|
+
else
|
83
|
+
return now
|
84
|
+
end
|
85
|
+
Time.mktime(t.year, t.month, t.mday, t.hour, 59, 59)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yologga/patch/ruby_2_4"
|
4
|
+
|
5
|
+
module Yologga
|
6
|
+
module Patch
|
7
|
+
# rubocop:disable Naming/ClassAndModuleCamelCase
|
8
|
+
module Ruby_2_5
|
9
|
+
# rubocop:enable Naming/ClassAndModuleCamelCase
|
10
|
+
include Ruby_2_4
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/yologga.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "yologga/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "yologga"
|
9
|
+
spec.version = Yologga::VERSION
|
10
|
+
spec.authors = ["Dmitry Gubitskiy", "Evgeniy Lukovsky"]
|
11
|
+
spec.email = ["d.gubitskiy@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = "Ruby Logger patch for hourly log rotation.\
|
14
|
+
Formerly known as hourly_logger_rotator.".strip
|
15
|
+
spec.homepage = "https://github.com/umbrellio/hourly_logger_rotator"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "pry"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rubocop-config-umbrellio"
|
26
|
+
spec.add_development_dependency "timecop"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yologga
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitry Gubitskiy
|
8
|
+
- Evgeniy Lukovsky
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-07-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: pry
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rubocop-config-umbrellio
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: timecop
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description:
|
99
|
+
email:
|
100
|
+
- d.gubitskiy@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".rubocop.yml"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CHANGELOG.md
|
110
|
+
- CODE_OF_CONDUCT.md
|
111
|
+
- CONTRIBUTING.md
|
112
|
+
- Gemfile
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- bin/console
|
117
|
+
- lib/yologga.rb
|
118
|
+
- lib/yologga/gzip.rb
|
119
|
+
- lib/yologga/logs_lifetime.rb
|
120
|
+
- lib/yologga/patch/ruby_2_3.rb
|
121
|
+
- lib/yologga/patch/ruby_2_4.rb
|
122
|
+
- lib/yologga/patch/ruby_2_5.rb
|
123
|
+
- lib/yologga/version.rb
|
124
|
+
- yologga.gemspec
|
125
|
+
homepage: https://github.com/umbrellio/hourly_logger_rotator
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.6.13
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Ruby Logger patch for hourly log rotation. Formerly known as hourly_logger_rotator.
|
149
|
+
test_files: []
|
150
|
+
has_rdoc:
|