logger 1.6.6 → 1.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 511e403d0d06ae6ca38d5757723c429618f5baf2e1a99e4ba838c29912cf1802
4
- data.tar.gz: ba95f626decdf4a74fbf872032eefc8424edec77cdbd14cb25cc9aa0355c9b48
3
+ metadata.gz: c84ac2b70e090b47e48cc054906f75f21b26b3648dad0b363f54bba83f37e372
4
+ data.tar.gz: f7b0cbf4e55fd9c5831cb2500e21d27faa6bc02356ddc484d819a4ef806e4dee
5
5
  SHA512:
6
- metadata.gz: 01dbd6bb8fda92a1bdddc7a1d471e6a481168ef5f02e403e515650e99c3f08d8df2252d0e68a3767f0a60379d0081bfe07727af8e792af446bde934f9e2e3aca
7
- data.tar.gz: 0ad9c452d95b51894574a88fff50c68afb7047f335e3f645b3df0584a41a8ef539212c9914428b5790822b9a848a7dbdd63bccdd76843fecaf8fb2f0bb474828
6
+ metadata.gz: 1ffa55991e59e4dadd824e1bcf19b0deee701fc9512ba4dc97f15d45f7450bff12422266bac8b9d041222cb386bd5b70ffbb2379107a2c76cd5a4cdcf418a9cf
7
+ data.tar.gz: 03e58b69f2e3f0eae398506fc1aa417d70fe17c190efa2c4c2ceb558b90bcadee62e088929a774f3d01242c9e72486f365b9555a78419c8553140a3517f2dad3
data/.document ADDED
@@ -0,0 +1,4 @@
1
+ BSDL
2
+ COPYING
3
+ README.md
4
+ lib/
data/.rdoc_options ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ main_page: README.md
3
+ title: Documentation for Logger
@@ -11,22 +11,17 @@ class Logger
11
11
  attr_reader :filename
12
12
  include MonitorMixin
13
13
 
14
- def initialize(log = nil, shift_age: nil, shift_size: nil, shift_period_suffix: nil, binmode: false, reraise_write_errors: [])
14
+ def initialize(
15
+ log = nil, shift_age: nil, shift_size: nil, shift_period_suffix: nil,
16
+ binmode: false, reraise_write_errors: [], skip_header: false
17
+ )
15
18
  @dev = @filename = @shift_age = @shift_size = @shift_period_suffix = nil
16
19
  @binmode = binmode
17
20
  @reraise_write_errors = reraise_write_errors
21
+ @skip_header = skip_header
18
22
  mon_initialize
19
23
  set_dev(log)
20
- if @filename
21
- @shift_age = shift_age || 7
22
- @shift_size = shift_size || 1048576
23
- @shift_period_suffix = shift_period_suffix || '%Y%m%d'
24
-
25
- unless @shift_age.is_a?(Integer)
26
- base_time = @dev.respond_to?(:stat) ? @dev.stat.mtime : Time.now
27
- @next_rotate_time = next_rotate_time(base_time, @shift_age)
28
- end
29
- end
24
+ set_file(shift_age, shift_size, shift_period_suffix) if @filename
30
25
  end
31
26
 
32
27
  def write(message)
@@ -50,9 +45,10 @@ class Logger
50
45
  end
51
46
  end
52
47
 
53
- def reopen(log = nil)
48
+ def reopen(log = nil, shift_age: nil, shift_size: nil, shift_period_suffix: nil, binmode: nil)
54
49
  # reopen the same filename if no argument, do nothing for IO
55
50
  log ||= @filename if @filename
51
+ @binmode = binmode unless binmode.nil?
56
52
  if log
57
53
  synchronize do
58
54
  if @filename and @dev
@@ -60,6 +56,7 @@ class Logger
60
56
  @filename = nil
61
57
  end
62
58
  set_dev(log)
59
+ set_file(shift_age, shift_size, shift_period_suffix) if @filename
63
60
  end
64
61
  end
65
62
  self
@@ -92,17 +89,27 @@ class Logger
92
89
  end
93
90
  end
94
91
 
92
+ def set_file(shift_age, shift_size, shift_period_suffix)
93
+ @shift_age = shift_age || @shift_age || 7
94
+ @shift_size = shift_size || @shift_size || 1048576
95
+ @shift_period_suffix = shift_period_suffix || @shift_period_suffix || '%Y%m%d'
96
+
97
+ unless @shift_age.is_a?(Integer)
98
+ base_time = @dev.respond_to?(:stat) ? @dev.stat.mtime : Time.now
99
+ @next_rotate_time = next_rotate_time(base_time, @shift_age)
100
+ end
101
+ end
102
+
95
103
  if MODE_TO_OPEN == MODE
96
- def fixup_mode(dev, filename)
104
+ def fixup_mode(dev)
97
105
  dev
98
106
  end
99
107
  else
100
- def fixup_mode(dev, filename)
108
+ def fixup_mode(dev)
101
109
  return dev if @binmode
102
- filename = filename.respond_to?(:to_path) ? filename.to_path : filename
103
110
  dev.autoclose = false
104
111
  old_dev = dev
105
- dev = File.new(dev.fileno, mode: MODE, path: filename)
112
+ dev = File.new(dev.fileno, mode: MODE, path: dev.path)
106
113
  old_dev.close
107
114
  PathAttr.set_path(dev, filename) if defined?(PathAttr)
108
115
  dev
@@ -115,7 +122,7 @@ class Logger
115
122
  rescue Errno::ENOENT
116
123
  create_logfile(filename)
117
124
  else
118
- dev = fixup_mode(dev, filename)
125
+ dev = fixup_mode(dev)
119
126
  dev.sync = true
120
127
  dev.binmode if @binmode
121
128
  dev
@@ -126,10 +133,10 @@ class Logger
126
133
  begin
127
134
  logdev = File.open(filename, MODE_TO_CREATE)
128
135
  logdev.flock(File::LOCK_EX)
129
- logdev = fixup_mode(logdev, filename)
136
+ logdev = fixup_mode(logdev)
130
137
  logdev.sync = true
131
138
  logdev.binmode if @binmode
132
- add_log_header(logdev)
139
+ add_log_header(logdev) unless @skip_header
133
140
  logdev.flock(File::LOCK_UN)
134
141
  logdev
135
142
  rescue Errno::EEXIST
@@ -181,6 +188,7 @@ class Logger
181
188
  @dev = open_logfile(@filename)
182
189
  end
183
190
  end
191
+ true
184
192
  rescue Errno::ENOENT
185
193
  # @filename file would not exist right after #rename and before #create_logfile
186
194
  if retry_limit <= 0
@@ -202,10 +210,7 @@ class Logger
202
210
  File.rename("#{@filename}.#{i}", "#{@filename}.#{i+1}")
203
211
  end
204
212
  end
205
- @dev.close rescue nil
206
- File.rename("#{@filename}", "#{@filename}.0")
207
- @dev = create_logfile(@filename)
208
- return true
213
+ shift_log_file("#{@filename}.0")
209
214
  end
210
215
 
211
216
  def shift_log_period(period_end)
@@ -221,9 +226,27 @@ class Logger
221
226
  break unless FileTest.exist?(age_file)
222
227
  end
223
228
  end
229
+ shift_log_file(age_file)
230
+ end
231
+
232
+ def shift_log_file(shifted)
233
+ stat = @dev.stat
224
234
  @dev.close rescue nil
225
- File.rename("#{@filename}", age_file)
235
+ File.rename(@filename, shifted)
226
236
  @dev = create_logfile(@filename)
237
+ mode, uid, gid = stat.mode, stat.uid, stat.gid
238
+ begin
239
+ @dev.chmod(mode) if mode
240
+ mode = nil
241
+ @dev.chown(uid, gid)
242
+ rescue Errno::EPERM
243
+ if mode
244
+ # failed to chmod, probably nothing can do more.
245
+ elsif uid
246
+ uid = nil
247
+ retry # to change gid only
248
+ end
249
+ end
227
250
  return true
228
251
  end
229
252
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Logger
4
- VERSION = "1.6.6"
4
+ VERSION = "1.7.0"
5
5
  end
data/lib/logger.rb CHANGED
@@ -543,10 +543,20 @@ class Logger
543
543
  # - A string filepath: entries are to be written
544
544
  # to the file at that path; if the file at that path exists,
545
545
  # new entries are appended.
546
- # - An IO stream (typically +$stdout+, +$stderr+. or an open file):
547
- # entries are to be written to the given stream.
546
+ # - An IO stream (typically <tt>$stdout</tt>, <tt>$stderr</tt>. or
547
+ # an open file): entries are to be written to the given stream.
548
548
  # - +nil+ or +File::NULL+: no entries are to be written.
549
549
  #
550
+ # Argument +shift_age+ must be one of:
551
+ #
552
+ # - The number of log files to be in the rotation.
553
+ # See {Size-Based Rotation}[rdoc-ref:Logger@Size-Based+Rotation].
554
+ # - A string period indicator.
555
+ # See {Periodic Rotation}[rdoc-ref:Logger@Periodic+Rotation].
556
+ #
557
+ # Argument +shift_size+ is the maximum size (in bytes) of each log file.
558
+ # See {Size-Based Rotation}[rdoc-ref:Logger@Size-Based+Rotation].
559
+ #
550
560
  # Examples:
551
561
  #
552
562
  # Logger.new('t.log')
@@ -566,22 +576,29 @@ class Logger
566
576
  #
567
577
  # - +formatter+: sets the entry formatter; default is +nil+.
568
578
  # See {formatter=}[Logger.html#attribute-i-formatter].
579
+ #
569
580
  # - +datetime_format+: sets the format for entry timestamp;
570
581
  # default is +nil+.
571
582
  # See #datetime_format=.
583
+ #
572
584
  # - +binmode+: sets whether the logger writes in binary mode;
573
585
  # default is +false+.
586
+ #
574
587
  # - +shift_period_suffix+: sets the format for the filename suffix
575
588
  # for periodic log file rotation; default is <tt>'%Y%m%d'</tt>.
576
589
  # See {Periodic Rotation}[rdoc-ref:Logger@Periodic+Rotation].
590
+ #
577
591
  # - +reraise_write_errors+: An array of exception classes, which will
578
592
  # be reraised if there is an error when writing to the log device.
579
593
  # The default is to swallow all exceptions raised.
594
+ # - +skip_header+: If +true+, prevents the logger from writing a header
595
+ # when creating a new log file. The default is +false+, meaning
596
+ # the header will be written as usual.
580
597
  #
581
598
  def initialize(logdev, shift_age = 0, shift_size = 1048576, level: DEBUG,
582
599
  progname: nil, formatter: nil, datetime_format: nil,
583
600
  binmode: false, shift_period_suffix: '%Y%m%d',
584
- reraise_write_errors: [])
601
+ reraise_write_errors: [], skip_header: false)
585
602
  self.level = level
586
603
  self.progname = progname
587
604
  @default_formatter = Formatter.new
@@ -594,7 +611,8 @@ class Logger
594
611
  shift_size: shift_size,
595
612
  shift_period_suffix: shift_period_suffix,
596
613
  binmode: binmode,
597
- reraise_write_errors: reraise_write_errors)
614
+ reraise_write_errors: reraise_write_errors,
615
+ skip_header: skip_header)
598
616
  end
599
617
  end
600
618
 
@@ -621,8 +639,9 @@ class Logger
621
639
  # # "E, [2022-05-12T14:21:27.596726 #22428] ERROR -- : one\n",
622
640
  # # "E, [2022-05-12T14:23:05.847241 #22428] ERROR -- : three\n"]
623
641
  #
624
- def reopen(logdev = nil)
625
- @logdev&.reopen(logdev)
642
+ def reopen(logdev = nil, shift_age = nil, shift_size = nil, shift_period_suffix: nil, binmode: nil)
643
+ @logdev&.reopen(logdev, shift_age: shift_age, shift_size: shift_size,
644
+ shift_period_suffix: shift_period_suffix, binmode: binmode)
626
645
  self
627
646
  end
628
647
 
@@ -748,6 +767,15 @@ private
748
767
 
749
768
  # Guarantee the existence of this ivar even when subclasses don't call the superclass constructor.
750
769
  def level_override
770
+ unless defined?(@level_override)
771
+ bad = self.class.instance_method(:initialize)
772
+ file, line = bad.source_location
773
+ Kernel.warn <<~";;;", uplevel: 2
774
+ Logger not initialized properly
775
+ #{file}:#{line}: info: #{bad.owner}\##{bad.name}: \
776
+ does not call super probably
777
+ ;;;
778
+ end
751
779
  @level_override ||= {}
752
780
  end
753
781
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.6
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-02-13 00:00:00.000000000 Z
12
+ date: 2025-03-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Provides a simple logging utility for outputting messages.
15
15
  email:
@@ -19,17 +19,11 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - ".github/dependabot.yml"
23
- - ".github/workflows/push_gem.yml"
24
- - ".github/workflows/test.yml"
25
- - ".gitignore"
22
+ - ".document"
23
+ - ".rdoc_options"
26
24
  - BSDL
27
25
  - COPYING
28
- - Gemfile
29
26
  - README.md
30
- - Rakefile
31
- - bin/console
32
- - bin/setup
33
27
  - lib/logger.rb
34
28
  - lib/logger/errors.rb
35
29
  - lib/logger/formatter.rb
@@ -37,7 +31,6 @@ files:
37
31
  - lib/logger/period.rb
38
32
  - lib/logger/severity.rb
39
33
  - lib/logger/version.rb
40
- - logger.gemspec
41
34
  homepage: https://github.com/ruby/logger
42
35
  licenses:
43
36
  - Ruby
@@ -1,6 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: 'github-actions'
4
- directory: '/'
5
- schedule:
6
- interval: 'weekly'
@@ -1,46 +0,0 @@
1
- name: Publish gem to rubygems.org
2
-
3
- on:
4
- push:
5
- tags:
6
- - 'v*'
7
-
8
- permissions:
9
- contents: read
10
-
11
- jobs:
12
- push:
13
- if: github.repository == 'ruby/logger'
14
- runs-on: ubuntu-latest
15
-
16
- environment:
17
- name: rubygems.org
18
- url: https://rubygems.org/gems/logger
19
-
20
- permissions:
21
- contents: write
22
- id-token: write
23
-
24
- steps:
25
- - name: Harden Runner
26
- uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
27
- with:
28
- egress-policy: audit
29
-
30
- - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
31
-
32
- - name: Set up Ruby
33
- uses: ruby/setup-ruby@a6e6f86333f0a2523ece813039b8b4be04560854 # v1.190.0
34
- with:
35
- bundler-cache: true
36
- ruby-version: ruby
37
-
38
- - name: Publish to RubyGems
39
- uses: rubygems/release-gem@a25424ba2ba8b387abc8ef40807c2c85b96cbe32 # v1.1.1
40
-
41
- - name: Create GitHub release
42
- run: |
43
- tag_name="$(git describe --tags --abbrev=0)"
44
- gh release create "${tag_name}" --verify-tag --generate-notes
45
- env:
46
- GITHUB_TOKEN: ${{ secrets.MATZBOT_GITHUB_WORKFLOW_TOKEN }}
@@ -1,36 +0,0 @@
1
- name: test
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- ruby-versions:
7
- uses: ruby/actions/.github/workflows/ruby_versions.yml@master
8
- with:
9
- engine: cruby-truffleruby
10
- min_version: 2.5
11
-
12
- test:
13
- needs: ruby-versions
14
- name: build (${{ matrix.ruby }} / ${{ matrix.os }})
15
- strategy:
16
- matrix:
17
- ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
18
- os: [ ubuntu-latest, macos-latest, windows-latest ]
19
- exclude:
20
- - ruby: 2.5
21
- os: macos-latest
22
- - ruby: truffleruby
23
- os: windows-latest
24
- - ruby: truffleruby-head
25
- os: windows-latest
26
- runs-on: ${{ matrix.os }}
27
- steps:
28
- - uses: actions/checkout@v4
29
- - name: Set up Ruby
30
- uses: ruby/setup-ruby@v1
31
- with:
32
- ruby-version: ${{ matrix.ruby }}
33
- - name: Install dependencies
34
- run: bundle install
35
- - name: Run test
36
- run: rake test
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- Gemfile.lock
10
- /html/
11
- /vendor/
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem "bundler"
7
- gem "rake"
8
- gem "test-unit"
9
- gem "test-unit-ruby-core"
10
- end
data/Rakefile DELETED
@@ -1,30 +0,0 @@
1
- begin
2
- require "bundler/gem_tasks"
3
- rescue LoadError
4
- end
5
-
6
- require "rake/testtask"
7
- Rake::TestTask.new(:test) do |t|
8
- t.libs << "test/lib"
9
- t.ruby_opts << "-rhelper"
10
- t.test_files = FileList["test/**/test_*.rb"]
11
- end
12
-
13
- require "rdoc/task"
14
- RDoc::Task.new do |doc|
15
- doc.main = "README.md"
16
- doc.title = "Logger -- Ruby Standard Logger"
17
- doc.rdoc_files = FileList.new %w[README.md lib BSDL COPYING]
18
- doc.rdoc_dir = "html"
19
- end
20
-
21
- task "gh-pages" => :rdoc do
22
- %x[git checkout gh-pages]
23
- require "fileutils"
24
- FileUtils.rm_rf "/tmp/html"
25
- FileUtils.mv "html", "/tmp"
26
- FileUtils.rm_rf "*"
27
- FileUtils.cp_r Dir.glob("/tmp/html/*"), "."
28
- end
29
-
30
- task :default => :test
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "logger"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/logger.gemspec DELETED
@@ -1,28 +0,0 @@
1
- begin
2
- require_relative "lib/logger/version"
3
- rescue LoadError # Fallback to load version file in ruby core repository
4
- require_relative "version"
5
- end
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = "logger"
9
- spec.version = Logger::VERSION
10
- spec.authors = ["Naotoshi Seo", "SHIBATA Hiroshi"]
11
- spec.email = ["sonots@gmail.com", "hsbt@ruby-lang.org"]
12
-
13
- spec.summary = %q{Provides a simple logging utility for outputting messages.}
14
- spec.description = %q{Provides a simple logging utility for outputting messages.}
15
- spec.homepage = "https://github.com/ruby/logger"
16
- spec.licenses = ["Ruby", "BSD-2-Clause"]
17
-
18
- # Specify which files should be added to the gem when it is released.
19
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
- `git ls-files -z 2>#{IO::NULL}`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
- end
23
- spec.require_paths = ["lib"]
24
-
25
- spec.required_ruby_version = ">= 2.5.0"
26
-
27
- spec.metadata["changelog_uri"] = spec.homepage + "/releases"
28
- end