rbs 3.0.0.dev.2 → 3.0.0.dev.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -1
  3. data/.github/workflows/ruby.yml +4 -0
  4. data/Gemfile.lock +11 -11
  5. data/Rakefile +2 -2
  6. data/Steepfile +1 -1
  7. data/core/array.rbs +573 -423
  8. data/core/basic_object.rbs +11 -39
  9. data/core/binding.rbs +1 -1
  10. data/core/builtin.rbs +8 -0
  11. data/core/class.rbs +37 -0
  12. data/core/comparable.rbs +7 -18
  13. data/core/complex.rbs +2 -2
  14. data/core/data.rbs +419 -0
  15. data/core/dir.rbs +52 -104
  16. data/core/encoding.rbs +22 -181
  17. data/core/enumerable.rbs +212 -175
  18. data/core/enumerator/product.rbs +96 -0
  19. data/core/enumerator.rbs +57 -8
  20. data/core/errors.rbs +8 -2
  21. data/core/exception.rbs +41 -0
  22. data/core/fiber.rbs +95 -12
  23. data/core/file.rbs +840 -275
  24. data/core/file_test.rbs +34 -19
  25. data/core/float.rbs +40 -96
  26. data/core/gc.rbs +15 -3
  27. data/core/hash.rbs +113 -175
  28. data/core/integer.rbs +85 -145
  29. data/core/io/buffer.rbs +187 -60
  30. data/core/io/wait.rbs +28 -16
  31. data/core/io.rbs +1859 -1389
  32. data/core/kernel.rbs +525 -961
  33. data/core/match_data.rbs +306 -142
  34. data/core/math.rbs +506 -234
  35. data/core/method.rbs +0 -24
  36. data/core/module.rbs +110 -17
  37. data/core/nil_class.rbs +2 -0
  38. data/core/numeric.rbs +76 -144
  39. data/core/object.rbs +88 -212
  40. data/core/proc.rbs +17 -5
  41. data/core/process.rbs +22 -5
  42. data/core/ractor.rbs +1 -1
  43. data/core/random.rbs +20 -3
  44. data/core/range.rbs +91 -89
  45. data/core/rational.rbs +2 -3
  46. data/core/rbs/unnamed/argf.rbs +177 -120
  47. data/core/rbs/unnamed/env_class.rbs +89 -163
  48. data/core/rbs/unnamed/random.rbs +36 -12
  49. data/core/refinement.rbs +8 -0
  50. data/core/regexp.rbs +462 -272
  51. data/core/ruby_vm.rbs +210 -0
  52. data/{stdlib/set/0 → core}/set.rbs +43 -47
  53. data/core/string.rbs +1403 -1332
  54. data/core/string_io.rbs +191 -107
  55. data/core/struct.rbs +67 -63
  56. data/core/symbol.rbs +187 -201
  57. data/core/thread.rbs +40 -35
  58. data/core/time.rbs +902 -826
  59. data/core/trace_point.rbs +55 -6
  60. data/core/unbound_method.rbs +48 -24
  61. data/docs/collection.md +4 -0
  62. data/docs/syntax.md +55 -0
  63. data/ext/rbs_extension/parser.c +5 -6
  64. data/lib/rbs/cli.rb +6 -1
  65. data/lib/rbs/collection/cleaner.rb +8 -1
  66. data/lib/rbs/collection/config/lockfile.rb +3 -1
  67. data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
  68. data/lib/rbs/collection/config.rb +1 -1
  69. data/lib/rbs/collection/sources/git.rb +9 -2
  70. data/lib/rbs/collection/sources/local.rb +79 -0
  71. data/lib/rbs/collection/sources.rb +8 -1
  72. data/lib/rbs/environment.rb +6 -5
  73. data/lib/rbs/environment_loader.rb +3 -2
  74. data/lib/rbs/errors.rb +18 -0
  75. data/lib/rbs/locator.rb +26 -7
  76. data/lib/rbs/sorter.rb +2 -2
  77. data/lib/rbs/version.rb +1 -1
  78. data/sig/collection/sources.rbs +32 -3
  79. data/sig/environment.rbs +2 -3
  80. data/sig/locator.rbs +14 -2
  81. data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
  82. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
  83. data/stdlib/cgi/0/core.rbs +16 -0
  84. data/stdlib/coverage/0/coverage.rbs +50 -8
  85. data/stdlib/csv/0/csv.rbs +1 -1
  86. data/stdlib/date/0/date.rbs +856 -726
  87. data/stdlib/date/0/date_time.rbs +83 -210
  88. data/stdlib/erb/0/erb.rbs +13 -36
  89. data/stdlib/etc/0/etc.rbs +127 -20
  90. data/stdlib/fileutils/0/fileutils.rbs +1290 -381
  91. data/stdlib/logger/0/logger.rbs +466 -316
  92. data/stdlib/net-http/0/net-http.rbs +2211 -534
  93. data/stdlib/nkf/0/nkf.rbs +5 -5
  94. data/stdlib/objspace/0/objspace.rbs +31 -14
  95. data/stdlib/openssl/0/openssl.rbs +11 -7
  96. data/stdlib/optparse/0/optparse.rbs +20 -17
  97. data/stdlib/pathname/0/pathname.rbs +21 -4
  98. data/stdlib/pstore/0/pstore.rbs +378 -154
  99. data/stdlib/pty/0/pty.rbs +24 -8
  100. data/stdlib/ripper/0/ripper.rbs +1650 -0
  101. data/stdlib/socket/0/addrinfo.rbs +9 -15
  102. data/stdlib/socket/0/socket.rbs +36 -3
  103. data/stdlib/strscan/0/string_scanner.rbs +7 -5
  104. data/stdlib/tempfile/0/tempfile.rbs +104 -44
  105. data/stdlib/time/0/time.rbs +2 -2
  106. data/stdlib/uri/0/file.rbs +5 -0
  107. data/stdlib/uri/0/generic.rbs +2 -2
  108. data/stdlib/yaml/0/yaml.rbs +2 -2
  109. data/stdlib/zlib/0/zlib.rbs +1 -1
  110. metadata +8 -6
  111. data/core/deprecated.rbs +0 -9
  112. data/sig/shims/ripper.rbs +0 -8
@@ -1,225 +1,352 @@
1
1
  # <!-- rdoc-file=lib/logger.rb -->
2
- # ## Description
2
+ # Class Logger provides a simple but sophisticated logging utility that you can
3
+ # use to create one or more [event
4
+ # logs](https://en.wikipedia.org/wiki/Logging_(software)#Event_logs) for your
5
+ # program. Each such log contains a chronological sequence of entries that
6
+ # provides a record of the program's activities.
3
7
  #
4
- # The Logger class provides a simple but sophisticated logging utility that you
5
- # can use to output messages.
8
+ # ## About the Examples
6
9
  #
7
- # The messages have associated levels, such as `INFO` or `ERROR` that indicate
8
- # their importance. You can then give the Logger a level, and only messages at
9
- # that level or higher will be printed.
10
+ # All examples on this page assume that Logger has been required:
10
11
  #
11
- # The levels are:
12
+ # require 'logger'
12
13
  #
13
- # `UNKNOWN`
14
- # : An unknown message that should always be logged.
15
- # `FATAL`
16
- # : An unhandleable error that results in a program crash.
17
- # `ERROR`
18
- # : A handleable error condition.
19
- # `WARN`
20
- # : A warning.
21
- # `INFO`
22
- # : Generic (useful) information about system operation.
23
- # `DEBUG`
24
- # : Low-level information for developers.
14
+ # ## Synopsis
25
15
  #
16
+ # Create a log with Logger.new:
26
17
  #
27
- # For instance, in a production system, you may have your Logger set to `INFO`
28
- # or even `WARN`. When you are developing the system, however, you probably want
29
- # to know about the program's internal state, and would set the Logger to
30
- # `DEBUG`.
18
+ # # Single log file.
19
+ # logger = Logger.new('t.log')
20
+ # # Size-based rotated logging: 3 10-megabyte files.
21
+ # logger = Logger.new('t.log', 3, 10485760)
22
+ # # Period-based rotated logging: daily (also allowed: 'weekly', 'monthly').
23
+ # logger = Logger.new('t.log', 'daily')
24
+ # # Log to an IO stream.
25
+ # logger = Logger.new($stdout)
31
26
  #
32
- # **Note**: Logger does not escape or sanitize any messages passed to it.
33
- # Developers should be aware of when potentially malicious data (user-input) is
34
- # passed to Logger, and manually escape the untrusted data:
27
+ # Add entries (level, message) with Logger#add:
35
28
  #
36
- # logger.info("User-input: #{input.dump}")
37
- # logger.info("User-input: %p" % input)
29
+ # logger.add(Logger::DEBUG, 'Maximal debugging info')
30
+ # logger.add(Logger::INFO, 'Non-error information')
31
+ # logger.add(Logger::WARN, 'Non-error warning')
32
+ # logger.add(Logger::ERROR, 'Non-fatal error')
33
+ # logger.add(Logger::FATAL, 'Fatal error')
34
+ # logger.add(Logger::UNKNOWN, 'Most severe')
38
35
  #
39
- # You can use #formatter= for escaping all data.
36
+ # Close the log with Logger#close:
40
37
  #
41
- # original_formatter = Logger::Formatter.new
42
- # logger.formatter = proc { |severity, datetime, progname, msg|
43
- # original_formatter.call(severity, datetime, progname, msg.dump)
44
- # }
45
- # logger.info(input)
38
+ # logger.close
46
39
  #
47
- # ### Example
40
+ # ## Entries
48
41
  #
49
- # This creates a Logger that outputs to the standard output stream, with a level
50
- # of `WARN`:
42
+ # You can add entries with method Logger#add:
51
43
  #
52
- # require 'logger'
44
+ # logger.add(Logger::DEBUG, 'Maximal debugging info')
45
+ # logger.add(Logger::INFO, 'Non-error information')
46
+ # logger.add(Logger::WARN, 'Non-error warning')
47
+ # logger.add(Logger::ERROR, 'Non-fatal error')
48
+ # logger.add(Logger::FATAL, 'Fatal error')
49
+ # logger.add(Logger::UNKNOWN, 'Most severe')
53
50
  #
54
- # logger = Logger.new(STDOUT)
55
- # logger.level = Logger::WARN
51
+ # These shorthand methods also add entries:
56
52
  #
57
- # logger.debug("Created logger")
58
- # logger.info("Program started")
59
- # logger.warn("Nothing to do!")
53
+ # logger.debug('Maximal debugging info')
54
+ # logger.info('Non-error information')
55
+ # logger.warn('Non-error warning')
56
+ # logger.error('Non-fatal error')
57
+ # logger.fatal('Fatal error')
58
+ # logger.unknown('Most severe')
60
59
  #
61
- # path = "a_non_existent_file"
60
+ # When you call any of these methods, the entry may or may not be written to the
61
+ # log, depending on the entry's severity and on the log level; see [Log
62
+ # Level](rdoc-ref:Logger@Log+Level)
62
63
  #
63
- # begin
64
- # File.foreach(path) do |line|
65
- # unless line =~ /^(\w+) = (.*)$/
66
- # logger.error("Line in wrong format: #{line.chomp}")
67
- # end
68
- # end
69
- # rescue => err
70
- # logger.fatal("Caught exception; exiting")
71
- # logger.fatal(err)
72
- # end
64
+ # An entry always has:
73
65
  #
74
- # Because the Logger's level is set to `WARN`, only the warning, error, and
75
- # fatal messages are recorded. The debug and info messages are silently
76
- # discarded.
66
+ # * A severity (the required argument to #add).
67
+ # * An automatically created timestamp.
77
68
  #
78
- # ### Features
79
69
  #
80
- # There are several interesting features that Logger provides, like auto-rolling
81
- # of log files, setting the format of log messages, and specifying a program
82
- # name in conjunction with the message. The next section shows you how to
83
- # achieve these things.
70
+ # And may also have:
84
71
  #
85
- # ## HOWTOs
72
+ # * A message.
73
+ # * A program name.
86
74
  #
87
- # ### How to create a logger
88
75
  #
89
- # The options below give you various choices, in more or less increasing
90
- # complexity.
76
+ # Example:
91
77
  #
92
- # 1. Create a logger which logs messages to STDERR/STDOUT.
78
+ # logger = Logger.new($stdout)
79
+ # logger.add(Logger::INFO, 'My message.', 'mung')
80
+ # # => I, [2022-05-07T17:21:46.536234 #20536] INFO -- mung: My message.
93
81
  #
94
- # logger = Logger.new(STDERR)
95
- # logger = Logger.new(STDOUT)
82
+ # The default format for an entry is:
96
83
  #
97
- # 2. Create a logger for the file which has the specified name.
84
+ # "%s, [%s #%d] %5s -- %s: %s\n"
98
85
  #
99
- # logger = Logger.new('logfile.log')
86
+ # where the values to be formatted are:
100
87
  #
101
- # 3. Create a logger for the specified file.
88
+ # * Severity (one letter).
89
+ # * Timestamp.
90
+ # * Process id.
91
+ # * Severity (word).
92
+ # * Program name.
93
+ # * Message.
102
94
  #
103
- # file = File.open('foo.log', File::WRONLY | File::APPEND)
104
- # # To create new logfile, add File::CREAT like:
105
- # # file = File.open('foo.log', File::WRONLY | File::APPEND | File::CREAT)
106
- # logger = Logger.new(file)
107
95
  #
108
- # 4. Create a logger which ages the logfile once it reaches a certain size.
109
- # Leave 10 "old" log files where each file is about 1,024,000 bytes.
96
+ # You can use a different entry format by:
110
97
  #
111
- # logger = Logger.new('foo.log', 10, 1024000)
98
+ # * Setting a custom format proc (affects following entries); see
99
+ # [formatter=](Logger.html#attribute-i-formatter).
100
+ # * Calling any of the methods above with a block (affects only the one
101
+ # entry). Doing so can have two benefits:
112
102
  #
113
- # 5. Create a logger which ages the logfile daily/weekly/monthly.
103
+ # * Context: the block can evaluate the entire program context and create
104
+ # a context-dependent message.
105
+ # * Performance: the block is not evaluated unless the log level permits
106
+ # the entry actually to be written:
114
107
  #
115
- # logger = Logger.new('foo.log', 'daily')
116
- # logger = Logger.new('foo.log', 'weekly')
117
- # logger = Logger.new('foo.log', 'monthly')
108
+ # logger.error { my_slow_message_generator }
118
109
  #
110
+ # Contrast this with the string form, where the string is always
111
+ # evaluated, regardless of the log level:
119
112
  #
120
- # ### How to log a message
113
+ # logger.error("#{my_slow_message_generator}")
121
114
  #
122
- # Notice the different methods (`fatal`, `error`, `info`) being used to log
123
- # messages of various levels? Other methods in this family are `warn` and
124
- # `debug`. `add` is used below to log a message of an arbitrary (perhaps
125
- # dynamic) level.
126
115
  #
127
- # 1. Message in a block.
128
116
  #
129
- # logger.fatal { "Argument 'foo' not given." }
117
+ # ### Severity
130
118
  #
131
- # 2. Message as a string.
119
+ # The severity of a log entry has two effects:
132
120
  #
133
- # logger.error "Argument #{@foo} mismatch."
121
+ # * Determines whether the entry is selected for inclusion in the log; see
122
+ # [Log Level](rdoc-ref:Logger@Log+Level).
123
+ # * Indicates to any log reader (whether a person or a program) the relative
124
+ # importance of the entry.
134
125
  #
135
- # 3. With progname.
136
126
  #
137
- # logger.info('initialize') { "Initializing..." }
127
+ # ### Timestamp
138
128
  #
139
- # 4. With severity.
129
+ # The timestamp for a log entry is generated automatically when the entry is
130
+ # created.
140
131
  #
141
- # logger.add(Logger::FATAL) { 'Fatal error!' }
132
+ # The logged timestamp is formatted by method
133
+ # [Time#strftime](rdoc-ref:Time#strftime) using this format string:
142
134
  #
135
+ # '%Y-%m-%dT%H:%M:%S.%6N'
143
136
  #
144
- # The block form allows you to create potentially complex log messages, but to
145
- # delay their evaluation until and unless the message is logged. For example,
146
- # if we have the following:
137
+ # Example:
147
138
  #
148
- # logger.debug { "This is a " + potentially + " expensive operation" }
139
+ # logger = Logger.new($stdout)
140
+ # logger.add(Logger::INFO)
141
+ # # => I, [2022-05-07T17:04:32.318331 #20536] INFO -- : nil
149
142
  #
150
- # If the logger's level is `INFO` or higher, no debug messages will be logged,
151
- # and the entire block will not even be evaluated. Compare to this:
143
+ # You can set a different format using method #datetime_format=.
152
144
  #
153
- # logger.debug("This is a " + potentially + " expensive operation")
145
+ # ### Message
154
146
  #
155
- # Here, the string concatenation is done every time, even if the log level is
156
- # not set to show the debug message.
147
+ # The message is an optional argument to an entry method:
157
148
  #
158
- # ### How to close a logger
149
+ # logger = Logger.new($stdout)
150
+ # logger.add(Logger::INFO, 'My message')
151
+ # # => I, [2022-05-07T18:15:37.647581 #20536] INFO -- : My message
159
152
  #
160
- # logger.close
153
+ # For the default entry formatter, `Logger::Formatter`, the message object may
154
+ # be:
155
+ #
156
+ # * A string: used as-is.
157
+ # * An Exception: `message.message` is used.
158
+ # * Anything else: `message.inspect` is used.
159
+ #
160
+ #
161
+ # **Note**: Logger::Formatter does not escape or sanitize the message passed to
162
+ # it. Developers should be aware that malicious data (user input) may be in the
163
+ # message, and should explicitly escape untrusted data.
164
+ #
165
+ # You can use a custom formatter to escape message data; see the example at
166
+ # [formatter=](Logger.html#attribute-i-formatter).
167
+ #
168
+ # ### Program Name
169
+ #
170
+ # The program name is an optional argument to an entry method:
171
+ #
172
+ # logger = Logger.new($stdout)
173
+ # logger.add(Logger::INFO, 'My message', 'mung')
174
+ # # => I, [2022-05-07T18:17:38.084716 #20536] INFO -- mung: My message
175
+ #
176
+ # The default program name for a new logger may be set in the call to Logger.new
177
+ # via optional keyword argument `progname`:
178
+ #
179
+ # logger = Logger.new('t.log', progname: 'mung')
180
+ #
181
+ # The default program name for an existing logger may be set by a call to method
182
+ # #progname=:
183
+ #
184
+ # logger.progname = 'mung'
185
+ #
186
+ # The current program name may be retrieved with method
187
+ # [progname](Logger.html#attribute-i-progname):
188
+ #
189
+ # logger.progname # => "mung"
190
+ #
191
+ # ## Log Level
192
+ #
193
+ # The log level setting determines whether an entry is actually written to the
194
+ # log, based on the entry's severity.
195
+ #
196
+ # These are the defined severities (least severe to most severe):
197
+ #
198
+ # logger = Logger.new($stdout)
199
+ # logger.add(Logger::DEBUG, 'Maximal debugging info')
200
+ # # => D, [2022-05-07T17:57:41.776220 #20536] DEBUG -- : Maximal debugging info
201
+ # logger.add(Logger::INFO, 'Non-error information')
202
+ # # => I, [2022-05-07T17:59:14.349167 #20536] INFO -- : Non-error information
203
+ # logger.add(Logger::WARN, 'Non-error warning')
204
+ # # => W, [2022-05-07T18:00:45.337538 #20536] WARN -- : Non-error warning
205
+ # logger.add(Logger::ERROR, 'Non-fatal error')
206
+ # # => E, [2022-05-07T18:02:41.592912 #20536] ERROR -- : Non-fatal error
207
+ # logger.add(Logger::FATAL, 'Fatal error')
208
+ # # => F, [2022-05-07T18:05:24.703931 #20536] FATAL -- : Fatal error
209
+ # logger.add(Logger::UNKNOWN, 'Most severe')
210
+ # # => A, [2022-05-07T18:07:54.657491 #20536] ANY -- : Most severe
211
+ #
212
+ # The default initial level setting is Logger::DEBUG, the lowest level, which
213
+ # means that all entries are to be written, regardless of severity:
214
+ #
215
+ # logger = Logger.new($stdout)
216
+ # logger.level # => 0
217
+ # logger.add(0, "My message")
218
+ # # => D, [2022-05-11T15:10:59.773668 #20536] DEBUG -- : My message
161
219
  #
162
- # ### Setting severity threshold
220
+ # You can specify a different setting in a new logger using keyword argument
221
+ # `level` with an appropriate value:
163
222
  #
164
- # 1. Original interface.
223
+ # logger = Logger.new($stdout, level: Logger::ERROR)
224
+ # logger = Logger.new($stdout, level: 'error')
225
+ # logger = Logger.new($stdout, level: :error)
226
+ # logger.level # => 3
165
227
  #
166
- # logger.sev_threshold = Logger::WARN
228
+ # With this level, entries with severity Logger::ERROR and higher are written,
229
+ # while those with lower severities are not written:
167
230
  #
168
- # 2. Log4r (somewhat) compatible interface.
231
+ # logger = Logger.new($stdout, level: Logger::ERROR)
232
+ # logger.add(3)
233
+ # # => E, [2022-05-11T15:17:20.933362 #20536] ERROR -- : nil
234
+ # logger.add(2) # Silent.
169
235
  #
170
- # logger.level = Logger::INFO
236
+ # You can set the log level for an existing logger with method #level=:
171
237
  #
172
- # # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
238
+ # logger.level = Logger::ERROR
173
239
  #
174
- # 3. Symbol or String (case insensitive)
240
+ # These shorthand methods also set the level:
175
241
  #
176
- # logger.level = :info
177
- # logger.level = 'INFO'
242
+ # logger.debug! # => 0
243
+ # logger.info! # => 1
244
+ # logger.warn! # => 2
245
+ # logger.error! # => 3
246
+ # logger.fatal! # => 4
178
247
  #
179
- # # :debug < :info < :warn < :error < :fatal < :unknown
248
+ # You can retrieve the log level with method
249
+ # [level](Logger.html#attribute-i-level):
180
250
  #
181
- # 4. Constructor
251
+ # logger.level = Logger::ERROR
252
+ # logger.level # => 3
182
253
  #
183
- # Logger.new(logdev, level: Logger::INFO)
184
- # Logger.new(logdev, level: :info)
185
- # Logger.new(logdev, level: 'INFO')
254
+ # These methods return whether a given level is to be written:
186
255
  #
256
+ # logger.level = Logger::ERROR
257
+ # logger.debug? # => false
258
+ # logger.info? # => false
259
+ # logger.warn? # => false
260
+ # logger.error? # => true
261
+ # logger.fatal? # => true
187
262
  #
188
- # ## Format
263
+ # ## Log File Rotation
189
264
  #
190
- # Log messages are rendered in the output stream in a certain format by default.
191
- # The default format and a sample are shown below:
265
+ # By default, a log file is a single file that grows indefinitely (until
266
+ # explicitly closed); there is no file rotation.
192
267
  #
193
- # Log format:
194
- # SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
268
+ # To keep log files to a manageable size, you can use *log* *file* *rotation*,
269
+ # which uses multiple log files:
195
270
  #
196
- # Log sample:
197
- # I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.
271
+ # * Each log file has entries for a non-overlapping time interval.
272
+ # * Only the most recent log file is open and active; the others are closed
273
+ # and inactive.
198
274
  #
199
- # You may change the date and time format via #datetime_format=.
200
275
  #
201
- # logger.datetime_format = '%Y-%m-%d %H:%M:%S'
202
- # # e.g. "2004-01-03 00:54:26"
276
+ # ### Size-Based Rotation
203
277
  #
204
- # or via the constructor.
278
+ # For size-based log file rotation, call Logger.new with:
205
279
  #
206
- # Logger.new(logdev, datetime_format: '%Y-%m-%d %H:%M:%S')
280
+ # * Argument `logdev` as a file path.
281
+ # * Argument `shift_age` with a positive integer: the number of log files to
282
+ # be in the rotation.
283
+ # * Argument `shift_size` as a positive integer: the maximum size (in bytes)
284
+ # of each log file; defaults to 1048576 (1 megabyte).
207
285
  #
208
- # Or, you may change the overall format via the #formatter= method.
209
286
  #
210
- # logger.formatter = proc do |severity, datetime, progname, msg|
211
- # "#{datetime}: #{msg}\n"
212
- # end
213
- # # e.g. "2005-09-22 08:51:08 +0900: hello world"
287
+ # Examples:
214
288
  #
215
- # or via the constructor.
289
+ # logger = Logger.new('t.log', 3) # Three 1-megabyte files.
290
+ # logger = Logger.new('t.log', 5, 10485760) # Five 10-megabyte files.
216
291
  #
217
- # Logger.new(logdev, formatter: proc {|severity, datetime, progname, msg|
218
- # "#{datetime}: #{msg}\n"
219
- # })
292
+ # For these examples, suppose:
220
293
  #
221
- # <!-- rdoc-file=lib/logger/errors.rb -->
222
- # not used after 1.2.7. just for compat.
294
+ # logger = Logger.new('t.log', 3)
295
+ #
296
+ # Logging begins in the new log file, `t.log`; the log file is "full" and ready
297
+ # for rotation when a new entry would cause its size to exceed `shift_size`.
298
+ #
299
+ # The first time `t.log` is full:
300
+ #
301
+ # * `t.log` is closed and renamed to `t.log.0`.
302
+ # * A new file `t.log` is opened.
303
+ #
304
+ #
305
+ # The second time `t.log` is full:
306
+ #
307
+ # * +t.log.0 is renamed as `t.log.1`.
308
+ # * `t.log` is closed and renamed to `t.log.0`.
309
+ # * A new file `t.log` is opened.
310
+ #
311
+ #
312
+ # Each subsequent time that `t.log` is full, the log files are rotated:
313
+ #
314
+ # * `t.log.1` is removed.
315
+ # * +t.log.0 is renamed as `t.log.1`.
316
+ # * `t.log` is closed and renamed to `t.log.0`.
317
+ # * A new file `t.log` is opened.
318
+ #
319
+ #
320
+ # ### Periodic Rotation
321
+ #
322
+ # For periodic rotation, call Logger.new with:
323
+ #
324
+ # * Argument `logdev` as a file path.
325
+ # * Argument `shift_age` as a string period indicator.
326
+ #
327
+ #
328
+ # Examples:
329
+ #
330
+ # logger = Logger.new('t.log', 'daily') # Rotate log files daily.
331
+ # logger = Logger.new('t.log', 'weekly') # Rotate log files weekly.
332
+ # logger = Logger.new('t.log', 'monthly') # Rotate log files monthly.
333
+ #
334
+ # Example:
335
+ #
336
+ # logger = Logger.new('t.log', 'daily')
337
+ #
338
+ # When the given period expires:
339
+ #
340
+ # * The base log file, `t.log` is closed and renamed with a date-based suffix
341
+ # such as `t.log.20220509`.
342
+ # * A new log file `t.log` is opened.
343
+ # * Nothing is removed.
344
+ #
345
+ #
346
+ # The default format for the suffix is `'%Y%m%d'`, which produces a suffix
347
+ # similar to the one above. You can set a different format using create-time
348
+ # option `shift_period_suffix`; see details and suggestions at
349
+ # [Time#strftime](rdoc-ref:Time#strftime).
223
350
  #
224
351
  class Logger
225
352
  interface _WriteCloser
@@ -237,51 +364,48 @@ class Logger
237
364
  # rdoc-file=lib/logger.rb
238
365
  # - <<(msg)
239
366
  # -->
240
- # Dump given message to the log device without any formatting. If no log device
241
- # exists, return `nil`.
367
+ # Writes the given `msg` to the log with no formatting; returns the number of
368
+ # characters written, or `nil` if no log device exists:
369
+ #
370
+ # logger = Logger.new($stdout)
371
+ # logger << 'My message.' # => 10
372
+ #
373
+ # Output:
374
+ #
375
+ # My message.
242
376
  #
243
377
  def <<: (untyped msg) -> (untyped | nil)
244
378
 
245
379
  # <!--
246
380
  # rdoc-file=lib/logger.rb
247
- # - Logger#add(severity, message = nil, progname = nil) { ... }
381
+ # - add(severity, message = nil, progname = nil) { || ... }
248
382
  # -->
249
- # ### Args
250
- #
251
- # `severity`
252
- # : Severity. Constants are defined in Logger namespace: `DEBUG`, `INFO`,
253
- # `WARN`, `ERROR`, `FATAL`, or `UNKNOWN`.
254
- # `message`
255
- # : The log message. A String or Exception.
256
- # `progname`
257
- # : Program name string. Can be omitted. Treated as a message if no
258
- # `message` and `block` are given.
259
- # `block`
260
- # : Can be omitted. Called to get a message string if `message` is nil.
383
+ # Creates a log entry, which may or may not be written to the log, depending on
384
+ # the entry's severity and on the log level. See [Log
385
+ # Level](rdoc-ref:Logger@Log+Level) and [Entries](rdoc-ref:Logger@Entries) for
386
+ # details.
261
387
  #
388
+ # Examples:
262
389
  #
263
- # ### Return
390
+ # logger = Logger.new($stdout, progname: 'mung')
391
+ # logger.add(Logger::INFO)
392
+ # logger.add(Logger::ERROR, 'No good')
393
+ # logger.add(Logger::ERROR, 'No good', 'gnum')
264
394
  #
265
- # When the given severity is not high enough (for this particular logger), log
266
- # no message, and return `true`.
395
+ # Output:
267
396
  #
268
- # ### Description
397
+ # I, [2022-05-12T16:25:31.469726 #36328] INFO -- mung: mung
398
+ # E, [2022-05-12T16:25:55.349414 #36328] ERROR -- mung: No good
399
+ # E, [2022-05-12T16:26:35.841134 #36328] ERROR -- gnum: No good
269
400
  #
270
- # Log a message if the given severity is high enough. This is the generic
271
- # logging method. Users will be more inclined to use #debug, #info, #warn,
272
- # #error, and #fatal.
401
+ # These convenience methods have implicit severity:
273
402
  #
274
- # **Message format**: `message` can be any object, but it has to be converted to
275
- # a String in order to log it. Generally, `inspect` is used if the given object
276
- # is not a String. A special case is an `Exception` object, which will be
277
- # printed in detail, including message, class, and backtrace. See #msg2str for
278
- # the implementation if required.
279
- #
280
- # ### Bugs
281
- #
282
- # * Logfile is not locked.
283
- # * Append open does not need to lock file.
284
- # * If the OS supports multi I/O, records possibly may be mixed.
403
+ # * #debug.
404
+ # * #info.
405
+ # * #warn.
406
+ # * #error.
407
+ # * #fatal.
408
+ # * #unknown.
285
409
  #
286
410
  def add: (Integer severity, ?untyped message, ?untyped progname) ?{ () -> untyped } -> true
287
411
 
@@ -289,7 +413,13 @@ class Logger
289
413
  # rdoc-file=lib/logger.rb
290
414
  # - close()
291
415
  # -->
292
- # Close the logging device.
416
+ # Closes the logger; returns `nil`:
417
+ #
418
+ # logger = Logger.new('t.log')
419
+ # logger.close # => nil
420
+ # logger.info('foo') # Prints "log writing failed. closed stream"
421
+ #
422
+ # Related: Logger#reopen.
293
423
  #
294
424
  def close: () -> untyped
295
425
 
@@ -297,7 +427,7 @@ class Logger
297
427
  # rdoc-file=lib/logger.rb
298
428
  # - datetime_format()
299
429
  # -->
300
- # Returns the date format being used. See #datetime_format=
430
+ # Returns the date-time format; see #datetime_format=.
301
431
  #
302
432
  def datetime_format: () -> String?
303
433
 
@@ -305,10 +435,13 @@ class Logger
305
435
  # rdoc-file=lib/logger.rb
306
436
  # - datetime_format=(datetime_format)
307
437
  # -->
308
- # Set date-time format.
438
+ # Sets the date-time format.
439
+ #
440
+ # Argument `datetime_format` should be either of these:
309
441
  #
310
- # `datetime_format`
311
- # : A string suitable for passing to `strftime`.
442
+ # * A string suitable for use as a format for method
443
+ # [Time#strftime](rdoc-ref:Time#strftime).
444
+ # * `nil`: the logger uses `'%Y-%m-%dT%H:%M:%S.%6N'`.
312
445
  #
313
446
  def datetime_format=: (String datetime_format) -> String
314
447
  | (nil datetime_format) -> nil
@@ -317,9 +450,7 @@ class Logger
317
450
  # rdoc-file=lib/logger.rb
318
451
  # - debug(progname = nil, &block)
319
452
  # -->
320
- # Log a `DEBUG` message.
321
- #
322
- # See #info for more information.
453
+ # Equivalent to calling #add with severity `Logger::DEBUG`.
323
454
  #
324
455
  def debug: (?untyped progname) ?{ () -> untyped } -> true
325
456
 
@@ -327,7 +458,8 @@ class Logger
327
458
  # rdoc-file=lib/logger.rb
328
459
  # - debug!()
329
460
  # -->
330
- # Sets the severity to DEBUG.
461
+ # Sets the log level to Logger::DEBUG. See [Log
462
+ # Level](rdoc-ref:Logger@Log+Level).
331
463
  #
332
464
  def debug!: () -> Integer
333
465
 
@@ -335,8 +467,8 @@ class Logger
335
467
  # rdoc-file=lib/logger.rb
336
468
  # - debug?()
337
469
  # -->
338
- # Returns `true` if and only if the current severity level allows for the
339
- # printing of `DEBUG` messages.
470
+ # Returns `true` if the log level allows entries with severity Logger::DEBUG to
471
+ # be written, `false` otherwise. See [Log Level](rdoc-ref:Logger@Log+Level).
340
472
  #
341
473
  def debug?: () -> bool
342
474
 
@@ -344,9 +476,7 @@ class Logger
344
476
  # rdoc-file=lib/logger.rb
345
477
  # - error(progname = nil, &block)
346
478
  # -->
347
- # Log an `ERROR` message.
348
- #
349
- # See #info for more information.
479
+ # Equivalent to calling #add with severity `Logger::ERROR`.
350
480
  #
351
481
  def error: (?untyped progname) ?{ () -> untyped } -> true
352
482
 
@@ -354,7 +484,8 @@ class Logger
354
484
  # rdoc-file=lib/logger.rb
355
485
  # - error!()
356
486
  # -->
357
- # Sets the severity to ERROR.
487
+ # Sets the log level to Logger::ERROR. See [Log
488
+ # Level](rdoc-ref:Logger@Log+Level).
358
489
  #
359
490
  def error!: () -> Integer
360
491
 
@@ -362,8 +493,8 @@ class Logger
362
493
  # rdoc-file=lib/logger.rb
363
494
  # - error?()
364
495
  # -->
365
- # Returns `true` if and only if the current severity level allows for the
366
- # printing of `ERROR` messages.
496
+ # Returns `true` if the log level allows entries with severity Logger::ERROR to
497
+ # be written, `false` otherwise. See [Log Level](rdoc-ref:Logger@Log+Level).
367
498
  #
368
499
  def error?: () -> bool
369
500
 
@@ -371,9 +502,7 @@ class Logger
371
502
  # rdoc-file=lib/logger.rb
372
503
  # - fatal(progname = nil, &block)
373
504
  # -->
374
- # Log a `FATAL` message.
375
- #
376
- # See #info for more information.
505
+ # Equivalent to calling #add with severity `Logger::FATAL`.
377
506
  #
378
507
  def fatal: (?untyped progname) ?{ () -> untyped } -> true
379
508
 
@@ -381,7 +510,8 @@ class Logger
381
510
  # rdoc-file=lib/logger.rb
382
511
  # - fatal!()
383
512
  # -->
384
- # Sets the severity to FATAL.
513
+ # Sets the log level to Logger::FATAL. See [Log
514
+ # Level](rdoc-ref:Logger@Log+Level).
385
515
  #
386
516
  def fatal!: () -> Integer
387
517
 
@@ -389,83 +519,85 @@ class Logger
389
519
  # rdoc-file=lib/logger.rb
390
520
  # - fatal?()
391
521
  # -->
392
- # Returns `true` if and only if the current severity level allows for the
393
- # printing of `FATAL` messages.
522
+ # Returns `true` if the log level allows entries with severity Logger::FATAL to
523
+ # be written, `false` otherwise. See [Log Level](rdoc-ref:Logger@Log+Level).
394
524
  #
395
525
  def fatal?: () -> bool
396
526
 
397
527
  # <!-- rdoc-file=lib/logger.rb -->
398
- # Logging formatter, as a `Proc` that will take four arguments and return the
399
- # formatted message. The arguments are:
528
+ # Sets or retrieves the logger entry formatter proc.
529
+ #
530
+ # When `formatter` is `nil`, the logger uses Logger::Formatter.
400
531
  #
401
- # `severity`
402
- # : The Severity of the log message.
403
- # `time`
404
- # : A Time instance representing when the message was logged.
405
- # `progname`
406
- # : The #progname configured, or passed to the logger method.
407
- # `msg`
408
- # : The *Object* the user passed to the log message; not necessarily a String.
532
+ # When `formatter` is a proc, a new entry is formatted by the proc, which is
533
+ # called with four arguments:
409
534
  #
535
+ # * `severity`: The severity of the entry.
536
+ # * `time`: A Time object representing the entry's timestamp.
537
+ # * `progname`: The program name for the entry.
538
+ # * `msg`: The message for the entry (string or string-convertible object).
410
539
  #
411
- # The block should return an Object that can be written to the logging device
412
- # via `write`. The default formatter is used when no formatter is set.
540
+ #
541
+ # The proc should return a string containing the formatted entry.
542
+ #
543
+ # This custom formatter uses [String#dump](rdoc-ref:String#dump) to escape the
544
+ # message string:
545
+ #
546
+ # logger = Logger.new($stdout, progname: 'mung')
547
+ # original_formatter = logger.formatter || Logger::Formatter.new
548
+ # logger.formatter = proc { |severity, time, progname, msg|
549
+ # original_formatter.call(severity, time, progname, msg.dump)
550
+ # }
551
+ # logger.add(Logger::INFO, "hello \n ''")
552
+ # logger.add(Logger::INFO, "\f\x00\xff\\\"")
553
+ #
554
+ # Output:
555
+ #
556
+ # I, [2022-05-13T13:16:29.637488 #8492] INFO -- mung: "hello \n ''"
557
+ # I, [2022-05-13T13:16:29.637610 #8492] INFO -- mung: "\f\x00\xFF\\\""
413
558
  #
414
559
  def formatter: () -> (_Formatter | nil)
415
560
 
416
561
  # <!-- rdoc-file=lib/logger.rb -->
417
- # Logging formatter, as a `Proc` that will take four arguments and return the
418
- # formatted message. The arguments are:
419
- #
420
- # `severity`
421
- # : The Severity of the log message.
422
- # `time`
423
- # : A Time instance representing when the message was logged.
424
- # `progname`
425
- # : The #progname configured, or passed to the logger method.
426
- # `msg`
427
- # : The *Object* the user passed to the log message; not necessarily a String.
562
+ # Sets or retrieves the logger entry formatter proc.
428
563
  #
564
+ # When `formatter` is `nil`, the logger uses Logger::Formatter.
429
565
  #
430
- # The block should return an Object that can be written to the logging device
431
- # via `write`. The default formatter is used when no formatter is set.
566
+ # When `formatter` is a proc, a new entry is formatted by the proc, which is
567
+ # called with four arguments:
432
568
  #
433
- def formatter=: (_Formatter) -> _Formatter
434
- | (nil) -> nil
435
-
436
- # <!--
437
- # rdoc-file=lib/logger.rb
438
- # - info(message)
439
- # - info(progname, &block)
440
- # -->
441
- # Log an `INFO` message.
569
+ # * `severity`: The severity of the entry.
570
+ # * `time`: A Time object representing the entry's timestamp.
571
+ # * `progname`: The program name for the entry.
572
+ # * `msg`: The message for the entry (string or string-convertible object).
442
573
  #
443
- # `message`
444
- # : The message to log; does not need to be a String.
445
- # `progname`
446
- # : In the block form, this is the #progname to use in the log message. The
447
- # default can be set with #progname=.
448
- # `block`
449
- # : Evaluates to the message to log. This is not evaluated unless the
450
- # logger's level is sufficient to log the message. This allows you to
451
- # create potentially expensive logging messages that are only called when
452
- # the logger is configured to show them.
453
574
  #
575
+ # The proc should return a string containing the formatted entry.
454
576
  #
455
- # ### Examples
577
+ # This custom formatter uses [String#dump](rdoc-ref:String#dump) to escape the
578
+ # message string:
456
579
  #
457
- # logger.info("MainApp") { "Received connection from #{ip}" }
458
- # # ...
459
- # logger.info "Waiting for input from user"
460
- # # ...
461
- # logger.info { "User typed #{input}" }
580
+ # logger = Logger.new($stdout, progname: 'mung')
581
+ # original_formatter = logger.formatter || Logger::Formatter.new
582
+ # logger.formatter = proc { |severity, time, progname, msg|
583
+ # original_formatter.call(severity, time, progname, msg.dump)
584
+ # }
585
+ # logger.add(Logger::INFO, "hello \n ''")
586
+ # logger.add(Logger::INFO, "\f\x00\xff\\\"")
462
587
  #
463
- # You'll probably stick to the second form above, unless you want to provide a
464
- # program name (which you can do with #progname= as well).
588
+ # Output:
465
589
  #
466
- # ### Return
590
+ # I, [2022-05-13T13:16:29.637488 #8492] INFO -- mung: "hello \n ''"
591
+ # I, [2022-05-13T13:16:29.637610 #8492] INFO -- mung: "\f\x00\xFF\\\""
467
592
  #
468
- # See #add.
593
+ def formatter=: (_Formatter) -> _Formatter
594
+ | (nil) -> nil
595
+
596
+ # <!--
597
+ # rdoc-file=lib/logger.rb
598
+ # - info(progname = nil, &block)
599
+ # -->
600
+ # Equivalent to calling #add with severity `Logger::INFO`.
469
601
  #
470
602
  def info: (?untyped progname) ?{ () -> untyped } -> true
471
603
 
@@ -473,7 +605,8 @@ class Logger
473
605
  # rdoc-file=lib/logger.rb
474
606
  # - info!()
475
607
  # -->
476
- # Sets the severity to INFO.
608
+ # Sets the log level to Logger::INFO. See [Log
609
+ # Level](rdoc-ref:Logger@Log+Level).
477
610
  #
478
611
  def info!: () -> Integer
479
612
 
@@ -481,8 +614,8 @@ class Logger
481
614
  # rdoc-file=lib/logger.rb
482
615
  # - info?()
483
616
  # -->
484
- # Returns `true` if and only if the current severity level allows for the
485
- # printing of `INFO` messages.
617
+ # Returns `true` if the log level allows entries with severity Logger::INFO to
618
+ # be written, `false` otherwise. See [Log Level](rdoc-ref:Logger@Log+Level).
486
619
  #
487
620
  def info?: () -> bool
488
621
 
@@ -495,10 +628,17 @@ class Logger
495
628
  # rdoc-file=lib/logger.rb
496
629
  # - level=(severity)
497
630
  # -->
498
- # Set logging severity threshold.
631
+ # Sets the log level; returns `severity`. See [Log
632
+ # Level](rdoc-ref:Logger@Log+Level).
633
+ #
634
+ # Argument `severity` may be an integer, a string, or a symbol:
635
+ #
636
+ # logger.level = Logger::ERROR # => 3
637
+ # logger.level = 3 # => 3
638
+ # logger.level = 'error' # => "error"
639
+ # logger.level = :error # => :error
499
640
  #
500
- # `severity`
501
- # : The Severity of the log message.
641
+ # Logger#sev_threshold= is an alias for Logger#level=.
502
642
  #
503
643
  def level=: (Integer | String | Symbol severity) -> Integer
504
644
 
@@ -521,20 +661,30 @@ class Logger
521
661
 
522
662
  # <!--
523
663
  # rdoc-file=lib/logger.rb
524
- # - Logger#reopen
525
- # - Logger#reopen(logdev)
664
+ # - reopen(logdev = nil)
526
665
  # -->
527
- # ### Args
666
+ # Sets the logger's output stream:
528
667
  #
529
- # `logdev`
530
- # : The log device. This is a filename (String) or IO object (typically
531
- # `STDOUT`, `STDERR`, or an open file). reopen the same filename if it is
532
- # `nil`, do nothing for IO. Default is `nil`.
668
+ # * If `logdev` is `nil`, reopens the current output stream.
669
+ # * If `logdev` is a filepath, opens the indicated file for append.
670
+ # * If `logdev` is an IO stream (usually `$stdout`, `$stderr`, or an open File
671
+ # object), opens the stream for append.
533
672
  #
534
673
  #
535
- # ### Description
674
+ # Example:
536
675
  #
537
- # Reopen a log device.
676
+ # logger = Logger.new('t.log')
677
+ # logger.add(Logger::ERROR, 'one')
678
+ # logger.close
679
+ # logger.add(Logger::ERROR, 'two') # Prints 'log writing failed. closed stream'
680
+ # logger.reopen
681
+ # logger.add(Logger::ERROR, 'three')
682
+ # logger.close
683
+ # File.readlines('t.log')
684
+ # # =>
685
+ # # ["# Logfile created on 2022-05-12 14:21:19 -0500 by logger.rb/v1.5.0\n",
686
+ # # "E, [2022-05-12T14:21:27.596726 #22428] ERROR -- : one\n",
687
+ # # "E, [2022-05-12T14:23:05.847241 #22428] ERROR -- : three\n"]
538
688
  #
539
689
  def reopen: () -> self
540
690
  | (logdev?) -> self
@@ -555,10 +705,7 @@ class Logger
555
705
  # rdoc-file=lib/logger.rb
556
706
  # - unknown(progname = nil, &block)
557
707
  # -->
558
- # Log an `UNKNOWN` message. This will be printed no matter what the logger's
559
- # level is.
560
- #
561
- # See #info for more information.
708
+ # Equivalent to calling #add with severity `Logger::UNKNOWN`.
562
709
  #
563
710
  def unknown: (?untyped progname) ?{ () -> untyped } -> true
564
711
 
@@ -566,9 +713,7 @@ class Logger
566
713
  # rdoc-file=lib/logger.rb
567
714
  # - warn(progname = nil, &block)
568
715
  # -->
569
- # Log a `WARN` message.
570
- #
571
- # See #info for more information.
716
+ # Equivalent to calling #add with severity `Logger::WARN`.
572
717
  #
573
718
  def warn: (?untyped progname) ?{ () -> untyped } -> true
574
719
 
@@ -576,7 +721,8 @@ class Logger
576
721
  # rdoc-file=lib/logger.rb
577
722
  # - warn!()
578
723
  # -->
579
- # Sets the severity to WARN.
724
+ # Sets the log level to Logger::WARN. See [Log
725
+ # Level](rdoc-ref:Logger@Log+Level).
580
726
  #
581
727
  def warn!: () -> Integer
582
728
 
@@ -584,8 +730,8 @@ class Logger
584
730
  # rdoc-file=lib/logger.rb
585
731
  # - warn?()
586
732
  # -->
587
- # Returns `true` if and only if the current severity level allows for the
588
- # printing of `WARN` messages.
733
+ # Returns `true` if the log level allows entries with severity Logger::WARN to
734
+ # be written, `false` otherwise. See [Log Level](rdoc-ref:Logger@Log+Level).
589
735
  #
590
736
  def warn?: () -> bool
591
737
 
@@ -607,44 +753,48 @@ class Logger
607
753
 
608
754
  # <!--
609
755
  # rdoc-file=lib/logger.rb
610
- # - Logger.new(logdev, shift_age = 0, shift_size = 1048576)
611
- # - Logger.new(logdev, shift_age = 'weekly')
612
- # - Logger.new(logdev, level: :info)
613
- # - Logger.new(logdev, progname: 'progname')
614
- # - Logger.new(logdev, formatter: formatter)
615
- # - Logger.new(logdev, datetime_format: '%Y-%m-%d %H:%M:%S')
756
+ # - Logger.new(logdev, shift_age = 0, shift_size = 1048576, **options)
616
757
  # -->
617
- # ### Args
618
- #
619
- # `logdev`
620
- # : The log device. This is a filename (String), IO object (typically
621
- # `STDOUT`, `STDERR`, or an open file), `nil` (it writes nothing) or
622
- # `File::NULL` (same as `nil`).
623
- # `shift_age`
624
- # : Number of old log files to keep, **or** frequency of rotation (`daily`,
625
- # `weekly` or `monthly`). Default value is 0, which disables log file
626
- # rotation.
627
- # `shift_size`
628
- # : Maximum logfile size in bytes (only applies when `shift_age` is a positive
629
- # Integer). Defaults to `1048576` (1MB).
630
- # `level`
631
- # : Logging severity threshold. Default values is Logger::DEBUG.
632
- # `progname`
633
- # : Program name to include in log messages. Default value is nil.
634
- # `formatter`
635
- # : Logging formatter. Default values is an instance of Logger::Formatter.
636
- # `datetime_format`
637
- # : Date and time format. Default value is '%Y-%m-%d %H:%M:%S'.
638
- # `binmode`
639
- # : Use binary mode on the log device. Default value is false.
640
- # `shift_period_suffix`
641
- # : The log file suffix format for `daily`, `weekly` or `monthly` rotation.
642
- # Default is '%Y%m%d'.
643
- #
644
- #
645
- # ### Description
646
- #
647
- # Create an instance.
758
+ # With the single argument `logdev`, returns a new logger with all default
759
+ # options:
760
+ #
761
+ # Logger.new('t.log') # => #<Logger:0x000001e685dc6ac8>
762
+ #
763
+ # Argument `logdev` must be one of:
764
+ #
765
+ # * A string filepath: entries are to be written to the file at that path; if
766
+ # the file at that path exists, new entries are appended.
767
+ # * An IO stream (typically +$stdout+, +$stderr+. or an open file): entries
768
+ # are to be written to the given stream.
769
+ # * `nil` or `File::NULL`: no entries are to be written.
770
+ #
771
+ #
772
+ # Examples:
773
+ #
774
+ # Logger.new('t.log')
775
+ # Logger.new($stdout)
776
+ #
777
+ # The keyword options are:
778
+ #
779
+ # * `level`: sets the log level; default value is Logger::DEBUG. See [Log
780
+ # Level](rdoc-ref:Logger@Log+Level):
781
+ #
782
+ # Logger.new('t.log', level: Logger::ERROR)
783
+ #
784
+ # * `progname`: sets the default program name; default is `nil`. See [Program
785
+ # Name](rdoc-ref:Logger@Program+Name):
786
+ #
787
+ # Logger.new('t.log', progname: 'mung')
788
+ #
789
+ # * `formatter`: sets the entry formatter; default is `nil`. See
790
+ # [formatter=](Logger.html#attribute-i-formatter).
791
+ # * `datetime_format`: sets the format for entry timestamp; default is `nil`.
792
+ # See #datetime_format=.
793
+ # * `binmode`: sets whether the logger writes in binary mode; default is
794
+ # `false`.
795
+ # * `shift_period_suffix`: sets the format for the filename suffix for
796
+ # periodic log file rotation; default is `'%Y%m%d'`. See [Periodic
797
+ # Rotation](rdoc-ref:Logger@Periodic+Rotation).
648
798
  #
649
799
  def initialize: (logdev logdev, ?Numeric | String shift_age, ?Integer shift_size, ?shift_period_suffix: String, ?binmode: boolish, ?datetime_format: String, ?formatter: _Formatter, ?progname: String, ?level: Integer | String | Symbol) -> void
650
800
  end