rbs 0.4.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +7 -1
- data/.gitignore +1 -1
- data/CHANGELOG.md +35 -0
- data/Gemfile +14 -0
- data/README.md +86 -47
- data/Rakefile +53 -21
- data/bin/rbs-prof +9 -0
- data/bin/run_in_md.rb +49 -0
- data/docs/stdlib.md +0 -2
- data/docs/syntax.md +6 -3
- data/goodcheck.yml +65 -0
- data/lib/rbs.rb +3 -0
- data/lib/rbs/ast/comment.rb +6 -0
- data/lib/rbs/ast/declarations.rb +106 -13
- data/lib/rbs/ast/members.rb +41 -17
- data/lib/rbs/cli.rb +317 -121
- data/lib/rbs/constant.rb +4 -4
- data/lib/rbs/constant_table.rb +51 -45
- data/lib/rbs/definition.rb +175 -59
- data/lib/rbs/definition_builder.rb +814 -604
- data/lib/rbs/environment.rb +352 -210
- data/lib/rbs/environment_walker.rb +14 -23
- data/lib/rbs/errors.rb +184 -3
- data/lib/rbs/factory.rb +14 -0
- data/lib/rbs/location.rb +15 -0
- data/lib/rbs/parser.y +100 -34
- data/lib/rbs/prototype/rb.rb +101 -113
- data/lib/rbs/prototype/rbi.rb +5 -3
- data/lib/rbs/prototype/runtime.rb +11 -7
- data/lib/rbs/substitution.rb +12 -1
- data/lib/rbs/test.rb +82 -3
- data/lib/rbs/test/errors.rb +5 -1
- data/lib/rbs/test/hook.rb +133 -259
- data/lib/rbs/test/observer.rb +17 -0
- data/lib/rbs/test/setup.rb +35 -19
- data/lib/rbs/test/setup_helper.rb +29 -0
- data/lib/rbs/test/spy.rb +0 -321
- data/lib/rbs/test/tester.rb +116 -0
- data/lib/rbs/test/type_check.rb +43 -7
- data/lib/rbs/type_name_resolver.rb +58 -0
- data/lib/rbs/types.rb +94 -2
- data/lib/rbs/validator.rb +55 -0
- data/lib/rbs/variance_calculator.rb +12 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +127 -91
- data/rbs.gemspec +0 -10
- data/schema/decls.json +36 -10
- data/schema/members.json +3 -0
- data/stdlib/benchmark/benchmark.rbs +151 -151
- data/stdlib/builtin/enumerable.rbs +3 -3
- data/stdlib/builtin/file.rbs +0 -3
- data/stdlib/builtin/io.rbs +4 -4
- data/stdlib/builtin/proc.rbs +1 -2
- data/stdlib/builtin/thread.rbs +2 -2
- data/stdlib/csv/csv.rbs +4 -6
- data/stdlib/fiber/fiber.rbs +1 -1
- data/stdlib/json/json.rbs +7 -1
- data/stdlib/logger/formatter.rbs +23 -0
- data/stdlib/logger/log_device.rbs +39 -0
- data/stdlib/logger/logger.rbs +507 -0
- data/stdlib/logger/period.rbs +7 -0
- data/stdlib/logger/severity.rbs +8 -0
- data/stdlib/mutex_m/mutex_m.rbs +77 -0
- data/stdlib/pathname/pathname.rbs +6 -6
- data/stdlib/prime/integer-extension.rbs +1 -1
- data/stdlib/prime/prime.rbs +44 -44
- data/stdlib/pty/pty.rbs +159 -0
- data/stdlib/tmpdir/tmpdir.rbs +1 -1
- metadata +19 -130
- data/lib/rbs/test/test_helper.rb +0 -183
data/stdlib/builtin/io.rbs
CHANGED
@@ -480,7 +480,7 @@ class IO < Object
|
|
480
480
|
|
481
481
|
def sysseek: (Integer amount, ?Integer whence) -> Integer
|
482
482
|
|
483
|
-
def syswrite: (
|
483
|
+
def syswrite: (_ToS arg0) -> Integer
|
484
484
|
|
485
485
|
# Returns the current offset (in bytes) of *ios* .
|
486
486
|
#
|
@@ -508,11 +508,11 @@ class IO < Object
|
|
508
508
|
|
509
509
|
def ungetc: (String arg0) -> NilClass
|
510
510
|
|
511
|
-
def write: (
|
511
|
+
def write: (*_ToS arg0) -> Integer
|
512
512
|
|
513
513
|
def self.binread: (String name, ?Integer length, ?Integer offset) -> String
|
514
514
|
|
515
|
-
def self.binwrite: (String name,
|
515
|
+
def self.binwrite: (String name, _ToS arg0, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> Integer
|
516
516
|
|
517
517
|
def self.copy_stream: (String | IO src, String | IO dst, ?Integer copy_length, ?Integer src_offset) -> Integer
|
518
518
|
|
@@ -528,7 +528,7 @@ class IO < Object
|
|
528
528
|
|
529
529
|
def self.try_convert: (untyped arg0) -> IO?
|
530
530
|
|
531
|
-
def self.write: (String name,
|
531
|
+
def self.write: (String name, _ToS arg0, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> Integer
|
532
532
|
|
533
533
|
def self.for_fd: (Integer fd, ?Integer mode, ?Integer opt) -> self
|
534
534
|
|
data/stdlib/builtin/proc.rbs
CHANGED
@@ -269,8 +269,7 @@ class Proc < Object
|
|
269
269
|
# See also Object\#hash.
|
270
270
|
def hash: () -> Integer
|
271
271
|
|
272
|
-
def initialize: () -> void
|
273
|
-
| () { (*untyped) -> untyped } -> void
|
272
|
+
def initialize: () { (*untyped) -> untyped } -> void
|
274
273
|
|
275
274
|
# Returns `true` for a [Proc](Proc.downloaded.ruby_doc) object for which
|
276
275
|
# argument handling is rigid. Such procs are typically generated by
|
data/stdlib/builtin/thread.rbs
CHANGED
@@ -898,7 +898,7 @@ class Thread::ConditionVariable < Object
|
|
898
898
|
#
|
899
899
|
# If `timeout` is given, this method returns after `timeout` seconds
|
900
900
|
# passed, even if no other thread doesn't signal.
|
901
|
-
def wait: (Mutex mutex, ?Integer timeout) -> self
|
901
|
+
def wait: (Thread::Mutex mutex, ?Integer timeout) -> self
|
902
902
|
end
|
903
903
|
|
904
904
|
# [Mutex](Mutex) implements a simple semaphore that
|
@@ -1078,7 +1078,7 @@ class Thread::SizedQueue < Thread::Queue
|
|
1078
1078
|
# Alias for: [push](SizedQueue.downloaded.ruby_doc#method-i-push)
|
1079
1079
|
alias enq push
|
1080
1080
|
|
1081
|
-
def initialize: (Integer max) ->
|
1081
|
+
def initialize: (Integer max) -> void
|
1082
1082
|
|
1083
1083
|
# Returns the maximum size of the queue.
|
1084
1084
|
def max: () -> Integer
|
data/stdlib/csv/csv.rbs
CHANGED
@@ -159,7 +159,7 @@
|
|
159
159
|
# with it.
|
160
160
|
#
|
161
161
|
class CSV < Object
|
162
|
-
include Enumerable
|
162
|
+
include Enumerable[untyped, untyped]
|
163
163
|
|
164
164
|
# This method is intended as the primary interface for reading CSV files. You
|
165
165
|
# pass a `path` and any `options` you wish to set for the read. Each row of file
|
@@ -407,7 +407,7 @@ CSV::VERSION: String
|
|
407
407
|
# processing is activated.
|
408
408
|
#
|
409
409
|
class CSV::Row < Object
|
410
|
-
include Enumerable
|
410
|
+
include Enumerable[untyped, untyped]
|
411
411
|
|
412
412
|
# If a two-element Array is provided, it is assumed to be a header and field and
|
413
413
|
# the pair is appended. A Hash works the same way with the key being the header
|
@@ -544,8 +544,6 @@ class CSV::Row < Object
|
|
544
544
|
|
545
545
|
def size: (*untyped args) { (*untyped) -> untyped } -> untyped
|
546
546
|
|
547
|
-
alias to_ary to_a
|
548
|
-
|
549
547
|
# Returns the row as a CSV String. Headers are not used. Equivalent to:
|
550
548
|
#
|
551
549
|
# csv_row.fields.to_csv( options )
|
@@ -564,7 +562,7 @@ class CSV::Row < Object
|
|
564
562
|
alias values_at fields
|
565
563
|
end
|
566
564
|
|
567
|
-
class CSV::FieldInfo < Struct
|
565
|
+
class CSV::FieldInfo < Struct[untyped]
|
568
566
|
end
|
569
567
|
|
570
568
|
# The error thrown when the parser encounters illegal CSV formatting.
|
@@ -580,7 +578,7 @@ end
|
|
580
578
|
# processing is activated.
|
581
579
|
#
|
582
580
|
class CSV::Table[out Elem] < Object
|
583
|
-
include Enumerable
|
581
|
+
include Enumerable[untyped, untyped]
|
584
582
|
|
585
583
|
# Constructs a new CSV::Table from `array_of_rows`, which are expected to be
|
586
584
|
# CSV::Row objects. All rows are assumed to have the same headers.
|
data/stdlib/fiber/fiber.rbs
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
# 1000000
|
55
55
|
# FiberError: dead fiber called
|
56
56
|
#
|
57
|
-
|
57
|
+
class Fiber
|
58
58
|
# Returns the current fiber. You need to `require 'fiber'` before using this
|
59
59
|
# method. If you are not running in the context of a fiber this method will
|
60
60
|
# return the root fiber.
|
data/stdlib/json/json.rbs
CHANGED
@@ -42,6 +42,9 @@ end
|
|
42
42
|
class JSON::Ext::Generator::State
|
43
43
|
end
|
44
44
|
|
45
|
+
class JSON::Ext::Parser
|
46
|
+
end
|
47
|
+
|
45
48
|
module JSON::Pure
|
46
49
|
end
|
47
50
|
|
@@ -51,6 +54,9 @@ end
|
|
51
54
|
class JSON::Pure::Generator::State
|
52
55
|
end
|
53
56
|
|
57
|
+
class JSON::Pure::Parser
|
58
|
+
end
|
59
|
+
|
54
60
|
type json_generator = singleton(::JSON::Ext::Generator) | singleton(::JSON::Pure::Generator)
|
55
61
|
type json_parser = singleton(::JSON::Ext::Parser) | singleton(::JSON::Pure::Parser)
|
56
62
|
type json_state = singleton(JSON::Ext::Generator::State) | singleton(JSON::Pure::Generator::State)
|
@@ -326,7 +332,7 @@ JSON::SAFE_STATE_PROTOTYPE: json_state
|
|
326
332
|
#
|
327
333
|
JSON::VERSION: String
|
328
334
|
|
329
|
-
JSON::VERSION_ARRAY: Array
|
335
|
+
JSON::VERSION_ARRAY: Array[Integer]
|
330
336
|
|
331
337
|
JSON::VERSION_BUILD: Integer
|
332
338
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Logger
|
2
|
+
class Formatter
|
3
|
+
public
|
4
|
+
|
5
|
+
attr_accessor datetime_format: String?
|
6
|
+
|
7
|
+
def call: (String severity, Time time, untyped progname, untyped msg) -> String
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def format_datetime: (Time time) -> untyped
|
12
|
+
|
13
|
+
def initialize: () -> void
|
14
|
+
|
15
|
+
def msg2str: (String | Exception | untyped msg) -> String
|
16
|
+
end
|
17
|
+
|
18
|
+
interface _Formatter
|
19
|
+
def call: (String severity, Time time, untyped progname, untyped msg) -> _ToS
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Logger::Formatter::Format: String
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Logger
|
2
|
+
class LogDevice
|
3
|
+
# TODO: Write type signature for MonitorMixin
|
4
|
+
# include MonitorMixin
|
5
|
+
|
6
|
+
include Period
|
7
|
+
|
8
|
+
attr_reader dev: _WriteCloser
|
9
|
+
attr_reader filename: String?
|
10
|
+
|
11
|
+
public
|
12
|
+
|
13
|
+
def close: () -> nil
|
14
|
+
|
15
|
+
def reopen: (?logdev log) -> self
|
16
|
+
|
17
|
+
def write: (untyped message) -> untyped
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def add_log_header: (IO file) -> untyped
|
22
|
+
|
23
|
+
def check_shift_log: () -> untyped
|
24
|
+
|
25
|
+
def create_logfile: (String filename) -> File
|
26
|
+
|
27
|
+
def initialize: (?untyped logdev, ?binmode: bool, ?shift_period_suffix: String, ?shift_size: Integer, ?shift_age: Numeric | String) -> void
|
28
|
+
|
29
|
+
def lock_shift_log: () { () -> untyped } -> untyped
|
30
|
+
|
31
|
+
def open_logfile: (String filename) -> File
|
32
|
+
|
33
|
+
def set_dev: (logdev log) -> untyped
|
34
|
+
|
35
|
+
def shift_log_age: () -> true
|
36
|
+
|
37
|
+
def shift_log_period: (Time period_end) -> true
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,507 @@
|
|
1
|
+
# ## Description
|
2
|
+
#
|
3
|
+
# The Logger class provides a simple but sophisticated logging utility that you
|
4
|
+
# can use to output messages.
|
5
|
+
#
|
6
|
+
# The messages have associated levels, such as `INFO` or `ERROR` that indicate
|
7
|
+
# their importance. You can then give the Logger a level, and only messages at
|
8
|
+
# that level or higher will be printed.
|
9
|
+
#
|
10
|
+
# The levels are:
|
11
|
+
#
|
12
|
+
# `UNKNOWN`
|
13
|
+
# : An unknown message that should always be logged.
|
14
|
+
# `FATAL`
|
15
|
+
# : An unhandleable error that results in a program crash.
|
16
|
+
# `ERROR`
|
17
|
+
# : A handleable error condition.
|
18
|
+
# `WARN`
|
19
|
+
# : A warning.
|
20
|
+
# `INFO`
|
21
|
+
# : Generic (useful) information about system operation.
|
22
|
+
# `DEBUG`
|
23
|
+
# : Low-level information for developers.
|
24
|
+
#
|
25
|
+
#
|
26
|
+
# For instance, in a production system, you may have your Logger set to `INFO`
|
27
|
+
# or even `WARN`. When you are developing the system, however, you probably want
|
28
|
+
# to know about the program's internal state, and would set the Logger to
|
29
|
+
# `DEBUG`.
|
30
|
+
#
|
31
|
+
# **Note**: Logger does not escape or sanitize any messages passed to it.
|
32
|
+
# Developers should be aware of when potentially malicious data (user-input) is
|
33
|
+
# passed to Logger, and manually escape the untrusted data:
|
34
|
+
#
|
35
|
+
# logger.info("User-input: #{input.dump}")
|
36
|
+
# logger.info("User-input: %p" % input)
|
37
|
+
#
|
38
|
+
# You can use #formatter= for escaping all data.
|
39
|
+
#
|
40
|
+
# original_formatter = Logger::Formatter.new
|
41
|
+
# logger.formatter = proc { |severity, datetime, progname, msg|
|
42
|
+
# original_formatter.call(severity, datetime, progname, msg.dump)
|
43
|
+
# }
|
44
|
+
# logger.info(input)
|
45
|
+
#
|
46
|
+
# ### Example
|
47
|
+
#
|
48
|
+
# This creates a Logger that outputs to the standard output stream, with a level
|
49
|
+
# of `WARN`:
|
50
|
+
#
|
51
|
+
# require 'logger'
|
52
|
+
#
|
53
|
+
# logger = Logger.new(STDOUT)
|
54
|
+
# logger.level = Logger::WARN
|
55
|
+
#
|
56
|
+
# logger.debug("Created logger")
|
57
|
+
# logger.info("Program started")
|
58
|
+
# logger.warn("Nothing to do!")
|
59
|
+
#
|
60
|
+
# path = "a_non_existent_file"
|
61
|
+
#
|
62
|
+
# begin
|
63
|
+
# File.foreach(path) do |line|
|
64
|
+
# unless line =~ /^(\w+) = (.*)$/
|
65
|
+
# logger.error("Line in wrong format: #{line.chomp}")
|
66
|
+
# end
|
67
|
+
# end
|
68
|
+
# rescue => err
|
69
|
+
# logger.fatal("Caught exception; exiting")
|
70
|
+
# logger.fatal(err)
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# Because the Logger's level is set to `WARN`, only the warning, error, and
|
74
|
+
# fatal messages are recorded. The debug and info messages are silently
|
75
|
+
# discarded.
|
76
|
+
#
|
77
|
+
# ### Features
|
78
|
+
#
|
79
|
+
# There are several interesting features that Logger provides, like auto-rolling
|
80
|
+
# of log files, setting the format of log messages, and specifying a program
|
81
|
+
# name in conjunction with the message. The next section shows you how to
|
82
|
+
# achieve these things.
|
83
|
+
#
|
84
|
+
# ## HOWTOs
|
85
|
+
#
|
86
|
+
# ### How to create a logger
|
87
|
+
#
|
88
|
+
# The options below give you various choices, in more or less increasing
|
89
|
+
# complexity.
|
90
|
+
#
|
91
|
+
# 1. Create a logger which logs messages to STDERR/STDOUT.
|
92
|
+
#
|
93
|
+
# logger = Logger.new(STDERR)
|
94
|
+
# logger = Logger.new(STDOUT)
|
95
|
+
#
|
96
|
+
# 2. Create a logger for the file which has the specified name.
|
97
|
+
#
|
98
|
+
# logger = Logger.new('logfile.log')
|
99
|
+
#
|
100
|
+
# 3. Create a logger for the specified file.
|
101
|
+
#
|
102
|
+
# file = File.open('foo.log', File::WRONLY | File::APPEND)
|
103
|
+
# # To create new logfile, add File::CREAT like:
|
104
|
+
# # file = File.open('foo.log', File::WRONLY | File::APPEND | File::CREAT)
|
105
|
+
# logger = Logger.new(file)
|
106
|
+
#
|
107
|
+
# 4. Create a logger which ages the logfile once it reaches a certain size.
|
108
|
+
# Leave 10 "old" log files where each file is about 1,024,000 bytes.
|
109
|
+
#
|
110
|
+
# logger = Logger.new('foo.log', 10, 1024000)
|
111
|
+
#
|
112
|
+
# 5. Create a logger which ages the logfile daily/weekly/monthly.
|
113
|
+
#
|
114
|
+
# logger = Logger.new('foo.log', 'daily')
|
115
|
+
# logger = Logger.new('foo.log', 'weekly')
|
116
|
+
# logger = Logger.new('foo.log', 'monthly')
|
117
|
+
#
|
118
|
+
#
|
119
|
+
# ### How to log a message
|
120
|
+
#
|
121
|
+
# Notice the different methods (`fatal`, `error`, `info`) being used to log
|
122
|
+
# messages of various levels? Other methods in this family are `warn` and
|
123
|
+
# `debug`. `add` is used below to log a message of an arbitrary (perhaps
|
124
|
+
# dynamic) level.
|
125
|
+
#
|
126
|
+
# 1. Message in a block.
|
127
|
+
#
|
128
|
+
# logger.fatal { "Argument 'foo' not given." }
|
129
|
+
#
|
130
|
+
# 2. Message as a string.
|
131
|
+
#
|
132
|
+
# logger.error "Argument #{@foo} mismatch."
|
133
|
+
#
|
134
|
+
# 3. With progname.
|
135
|
+
#
|
136
|
+
# logger.info('initialize') { "Initializing..." }
|
137
|
+
#
|
138
|
+
# 4. With severity.
|
139
|
+
#
|
140
|
+
# logger.add(Logger::FATAL) { 'Fatal error!' }
|
141
|
+
#
|
142
|
+
#
|
143
|
+
# The block form allows you to create potentially complex log messages, but to
|
144
|
+
# delay their evaluation until and unless the message is logged. For example,
|
145
|
+
# if we have the following:
|
146
|
+
#
|
147
|
+
# logger.debug { "This is a " + potentially + " expensive operation" }
|
148
|
+
#
|
149
|
+
# If the logger's level is `INFO` or higher, no debug messages will be logged,
|
150
|
+
# and the entire block will not even be evaluated. Compare to this:
|
151
|
+
#
|
152
|
+
# logger.debug("This is a " + potentially + " expensive operation")
|
153
|
+
#
|
154
|
+
# Here, the string concatenation is done every time, even if the log level is
|
155
|
+
# not set to show the debug message.
|
156
|
+
#
|
157
|
+
# ### How to close a logger
|
158
|
+
#
|
159
|
+
# logger.close
|
160
|
+
#
|
161
|
+
# ### Setting severity threshold
|
162
|
+
#
|
163
|
+
# 1. Original interface.
|
164
|
+
#
|
165
|
+
# logger.sev_threshold = Logger::WARN
|
166
|
+
#
|
167
|
+
# 2. Log4r (somewhat) compatible interface.
|
168
|
+
#
|
169
|
+
# logger.level = Logger::INFO
|
170
|
+
#
|
171
|
+
# # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
|
172
|
+
#
|
173
|
+
# 3. Symbol or String (case insensitive)
|
174
|
+
#
|
175
|
+
# logger.level = :info
|
176
|
+
# logger.level = 'INFO'
|
177
|
+
#
|
178
|
+
# # :debug < :info < :warn < :error < :fatal < :unknown
|
179
|
+
#
|
180
|
+
# 4. Constructor
|
181
|
+
#
|
182
|
+
# Logger.new(logdev, level: Logger::INFO)
|
183
|
+
# Logger.new(logdev, level: :info)
|
184
|
+
# Logger.new(logdev, level: 'INFO')
|
185
|
+
#
|
186
|
+
#
|
187
|
+
# ## Format
|
188
|
+
#
|
189
|
+
# Log messages are rendered in the output stream in a certain format by default.
|
190
|
+
# The default format and a sample are shown below:
|
191
|
+
#
|
192
|
+
# Log format:
|
193
|
+
# SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
|
194
|
+
#
|
195
|
+
# Log sample:
|
196
|
+
# I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.
|
197
|
+
#
|
198
|
+
# You may change the date and time format via #datetime_format=.
|
199
|
+
#
|
200
|
+
# logger.datetime_format = '%Y-%m-%d %H:%M:%S'
|
201
|
+
# # e.g. "2004-01-03 00:54:26"
|
202
|
+
#
|
203
|
+
# or via the constructor.
|
204
|
+
#
|
205
|
+
# Logger.new(logdev, datetime_format: '%Y-%m-%d %H:%M:%S')
|
206
|
+
#
|
207
|
+
# Or, you may change the overall format via the #formatter= method.
|
208
|
+
#
|
209
|
+
# logger.formatter = proc do |severity, datetime, progname, msg|
|
210
|
+
# "#{datetime}: #{msg}\n"
|
211
|
+
# end
|
212
|
+
# # e.g. "2005-09-22 08:51:08 +0900: hello world"
|
213
|
+
#
|
214
|
+
# or via the constructor.
|
215
|
+
#
|
216
|
+
# Logger.new(logdev, formatter: proc {|severity, datetime, progname, msg|
|
217
|
+
# "#{datetime}: #{msg}\n"
|
218
|
+
# })
|
219
|
+
#
|
220
|
+
class Logger
|
221
|
+
interface _WriteCloser
|
222
|
+
def write: (_ToS) -> untyped
|
223
|
+
|
224
|
+
def close: () -> untyped
|
225
|
+
end
|
226
|
+
type logdev = _WriteCloser | String
|
227
|
+
|
228
|
+
include Logger::Severity
|
229
|
+
|
230
|
+
public
|
231
|
+
|
232
|
+
# Dump given message to the log device without any formatting. If no log device
|
233
|
+
# exists, return `nil`.
|
234
|
+
#
|
235
|
+
def <<: (untyped msg) -> (untyped | nil)
|
236
|
+
|
237
|
+
# ### Args
|
238
|
+
#
|
239
|
+
# `severity`
|
240
|
+
# : Severity. Constants are defined in Logger namespace: `DEBUG`, `INFO`,
|
241
|
+
# `WARN`, `ERROR`, `FATAL`, or `UNKNOWN`.
|
242
|
+
# `message`
|
243
|
+
# : The log message. A String or Exception.
|
244
|
+
# `progname`
|
245
|
+
# : Program name string. Can be omitted. Treated as a message if no
|
246
|
+
# `message` and `block` are given.
|
247
|
+
# `block`
|
248
|
+
# : Can be omitted. Called to get a message string if `message` is nil.
|
249
|
+
#
|
250
|
+
#
|
251
|
+
# ### Return
|
252
|
+
#
|
253
|
+
# When the given severity is not high enough (for this particular logger), log
|
254
|
+
# no message, and return `true`.
|
255
|
+
#
|
256
|
+
# ### Description
|
257
|
+
#
|
258
|
+
# Log a message if the given severity is high enough. This is the generic
|
259
|
+
# logging method. Users will be more inclined to use #debug, #info, #warn,
|
260
|
+
# #error, and #fatal.
|
261
|
+
#
|
262
|
+
# **Message format**: `message` can be any object, but it has to be converted to
|
263
|
+
# a String in order to log it. Generally, `inspect` is used if the given object
|
264
|
+
# is not a String. A special case is an `Exception` object, which will be
|
265
|
+
# printed in detail, including message, class, and backtrace. See #msg2str for
|
266
|
+
# the implementation if required.
|
267
|
+
#
|
268
|
+
# ### Bugs
|
269
|
+
#
|
270
|
+
# * Logfile is not locked.
|
271
|
+
# * Append open does not need to lock file.
|
272
|
+
# * If the OS supports multi I/O, records possibly may be mixed.
|
273
|
+
#
|
274
|
+
def add: (Integer severity, ?untyped message, ?untyped progname) ?{ () -> untyped } -> true
|
275
|
+
|
276
|
+
# Close the logging device.
|
277
|
+
#
|
278
|
+
def close: () -> untyped
|
279
|
+
|
280
|
+
# Returns the date format being used. See #datetime_format=
|
281
|
+
#
|
282
|
+
def datetime_format: () -> String?
|
283
|
+
|
284
|
+
# Set date-time format.
|
285
|
+
#
|
286
|
+
# `datetime_format`
|
287
|
+
# : A string suitable for passing to `strftime`.
|
288
|
+
#
|
289
|
+
def datetime_format=: (String datetime_format) -> String
|
290
|
+
| (nil datetime_format) -> nil
|
291
|
+
|
292
|
+
# Log a `DEBUG` message.
|
293
|
+
#
|
294
|
+
# See #info for more information.
|
295
|
+
#
|
296
|
+
def debug: (?untyped progname) ?{ () -> untyped } -> true
|
297
|
+
|
298
|
+
# Sets the severity to DEBUG.
|
299
|
+
#
|
300
|
+
def debug!: () -> Integer
|
301
|
+
|
302
|
+
# Returns `true` iff the current severity level allows for the printing of
|
303
|
+
# `DEBUG` messages.
|
304
|
+
#
|
305
|
+
def debug?: () -> bool
|
306
|
+
|
307
|
+
# Log an `ERROR` message.
|
308
|
+
#
|
309
|
+
# See #info for more information.
|
310
|
+
#
|
311
|
+
def error: (?untyped progname) ?{ () -> untyped } -> true
|
312
|
+
|
313
|
+
# Sets the severity to ERROR.
|
314
|
+
#
|
315
|
+
def error!: () -> Integer
|
316
|
+
|
317
|
+
# Returns `true` iff the current severity level allows for the printing of
|
318
|
+
# `ERROR` messages.
|
319
|
+
#
|
320
|
+
def error?: () -> bool
|
321
|
+
|
322
|
+
# Log a `FATAL` message.
|
323
|
+
#
|
324
|
+
# See #info for more information.
|
325
|
+
#
|
326
|
+
def fatal: (?untyped progname) ?{ () -> untyped } -> true
|
327
|
+
|
328
|
+
# Sets the severity to FATAL.
|
329
|
+
#
|
330
|
+
def fatal!: () -> Integer
|
331
|
+
|
332
|
+
# Returns `true` iff the current severity level allows for the printing of
|
333
|
+
# `FATAL` messages.
|
334
|
+
#
|
335
|
+
def fatal?: () -> bool
|
336
|
+
|
337
|
+
# Logging formatter, as a `Proc` that will take four arguments and return the
|
338
|
+
# formatted message. The arguments are:
|
339
|
+
#
|
340
|
+
# `severity`
|
341
|
+
# : The Severity of the log message.
|
342
|
+
# `time`
|
343
|
+
# : A Time instance representing when the message was logged.
|
344
|
+
# `progname`
|
345
|
+
# : The #progname configured, or passed to the logger method.
|
346
|
+
# `msg`
|
347
|
+
# : The *Object* the user passed to the log message; not necessarily a String.
|
348
|
+
#
|
349
|
+
#
|
350
|
+
# The block should return an Object that can be written to the logging device
|
351
|
+
# via `write`. The default formatter is used when no formatter is set.
|
352
|
+
#
|
353
|
+
def formatter: () -> (_Formatter | nil)
|
354
|
+
|
355
|
+
def formatter=: (_Formatter) -> _Formatter
|
356
|
+
| (nil) -> nil
|
357
|
+
|
358
|
+
# Log an `INFO` message.
|
359
|
+
#
|
360
|
+
# `message`
|
361
|
+
# : The message to log; does not need to be a String.
|
362
|
+
# `progname`
|
363
|
+
# : In the block form, this is the #progname to use in the log message. The
|
364
|
+
# default can be set with #progname=.
|
365
|
+
# `block`
|
366
|
+
# : Evaluates to the message to log. This is not evaluated unless the
|
367
|
+
# logger's level is sufficient to log the message. This allows you to
|
368
|
+
# create potentially expensive logging messages that are only called when
|
369
|
+
# the logger is configured to show them.
|
370
|
+
#
|
371
|
+
#
|
372
|
+
# ### Examples
|
373
|
+
#
|
374
|
+
# logger.info("MainApp") { "Received connection from #{ip}" }
|
375
|
+
# # ...
|
376
|
+
# logger.info "Waiting for input from user"
|
377
|
+
# # ...
|
378
|
+
# logger.info { "User typed #{input}" }
|
379
|
+
#
|
380
|
+
# You'll probably stick to the second form above, unless you want to provide a
|
381
|
+
# program name (which you can do with #progname= as well).
|
382
|
+
#
|
383
|
+
# ### Return
|
384
|
+
#
|
385
|
+
# See #add.
|
386
|
+
#
|
387
|
+
def info: (?untyped progname) ?{ () -> untyped } -> true
|
388
|
+
|
389
|
+
# Sets the severity to INFO.
|
390
|
+
#
|
391
|
+
def info!: () -> Integer
|
392
|
+
|
393
|
+
# Returns `true` iff the current severity level allows for the printing of
|
394
|
+
# `INFO` messages.
|
395
|
+
#
|
396
|
+
def info?: () -> bool
|
397
|
+
|
398
|
+
# Logging severity threshold (e.g. `Logger::INFO`).
|
399
|
+
#
|
400
|
+
def level: () -> Integer
|
401
|
+
|
402
|
+
# Set logging severity threshold.
|
403
|
+
#
|
404
|
+
# `severity`
|
405
|
+
# : The Severity of the log message.
|
406
|
+
#
|
407
|
+
#
|
408
|
+
def level=: (Integer | String severity) -> Integer
|
409
|
+
|
410
|
+
alias log add
|
411
|
+
|
412
|
+
# Program name to include in log messages.
|
413
|
+
#
|
414
|
+
def progname: () -> untyped
|
415
|
+
|
416
|
+
def progname=: (untyped) -> untyped
|
417
|
+
|
418
|
+
# ### Args
|
419
|
+
#
|
420
|
+
# `logdev`
|
421
|
+
# : The log device. This is a filename (String) or IO object (typically
|
422
|
+
# `STDOUT`, `STDERR`, or an open file). reopen the same filename if it is
|
423
|
+
# `nil`, do nothing for IO. Default is `nil`.
|
424
|
+
#
|
425
|
+
#
|
426
|
+
# ### Description
|
427
|
+
#
|
428
|
+
# Reopen a log device.
|
429
|
+
#
|
430
|
+
def reopen: () -> self
|
431
|
+
| (logdev?) -> self
|
432
|
+
|
433
|
+
# Logging severity threshold (e.g. `Logger::INFO`).
|
434
|
+
#
|
435
|
+
alias sev_threshold level
|
436
|
+
|
437
|
+
alias sev_threshold= level=
|
438
|
+
|
439
|
+
# Log an `UNKNOWN` message. This will be printed no matter what the logger's
|
440
|
+
# level is.
|
441
|
+
#
|
442
|
+
# See #info for more information.
|
443
|
+
#
|
444
|
+
def unknown: (?untyped progname) ?{ () -> untyped } -> true
|
445
|
+
|
446
|
+
# Log a `WARN` message.
|
447
|
+
#
|
448
|
+
# See #info for more information.
|
449
|
+
#
|
450
|
+
def warn: (?untyped progname) ?{ () -> untyped } -> true
|
451
|
+
|
452
|
+
# Sets the severity to WARN.
|
453
|
+
#
|
454
|
+
def warn!: () -> Integer
|
455
|
+
|
456
|
+
# Returns `true` iff the current severity level allows for the printing of
|
457
|
+
# `WARN` messages.
|
458
|
+
#
|
459
|
+
def warn?: () -> bool
|
460
|
+
|
461
|
+
private
|
462
|
+
|
463
|
+
def format_message: (String severity, Time datetime, untyped progname, untyped msg) -> _ToS
|
464
|
+
|
465
|
+
def format_severity: (Integer severity) -> String
|
466
|
+
|
467
|
+
# ### Args
|
468
|
+
#
|
469
|
+
# `logdev`
|
470
|
+
# : The log device. This is a filename (String) or IO object (typically
|
471
|
+
# `STDOUT`, `STDERR`, or an open file).
|
472
|
+
# `shift_age`
|
473
|
+
# : Number of old log files to keep, **or** frequency of rotation (`daily`,
|
474
|
+
# `weekly` or `monthly`). Default value is 0, which disables log file
|
475
|
+
# rotation.
|
476
|
+
# `shift_size`
|
477
|
+
# : Maximum logfile size in bytes (only applies when `shift_age` is a positive
|
478
|
+
# Integer). Defaults to `1048576` (1MB).
|
479
|
+
# `level`
|
480
|
+
# : Logging severity threshold. Default values is Logger::DEBUG.
|
481
|
+
# `progname`
|
482
|
+
# : Program name to include in log messages. Default value is nil.
|
483
|
+
# `formatter`
|
484
|
+
# : Logging formatter. Default values is an instance of Logger::Formatter.
|
485
|
+
# `datetime_format`
|
486
|
+
# : Date and time format. Default value is '%Y-%m-%d %H:%M:%S'.
|
487
|
+
# `binmode`
|
488
|
+
# : Use binary mode on the log device. Default value is false.
|
489
|
+
# `shift_period_suffix`
|
490
|
+
# : The log file suffix format for `daily`, `weekly` or `monthly` rotation.
|
491
|
+
# Default is '%Y%m%d'.
|
492
|
+
#
|
493
|
+
#
|
494
|
+
# ### Description
|
495
|
+
#
|
496
|
+
# Create an instance.
|
497
|
+
#
|
498
|
+
def initialize: (logdev logdev, ?Numeric | String shift_age, ?Integer shift_size, ?shift_period_suffix: String, ?binmode: bool, ?datetime_format: String, ?formatter: _Formatter, ?progname: String, ?level: Integer) -> void
|
499
|
+
end
|
500
|
+
|
501
|
+
Logger::ProgName: String
|
502
|
+
|
503
|
+
# Severity label for logging (max 5 chars).
|
504
|
+
#
|
505
|
+
Logger::SEV_LABEL: Array[String]
|
506
|
+
|
507
|
+
Logger::VERSION: String
|