rbs 2.8.4 → 3.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (434) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +12 -4
  3. data/.github/workflows/comments.yml +11 -11
  4. data/.github/workflows/dependabot.yml +30 -0
  5. data/.github/workflows/ruby.yml +40 -49
  6. data/.github/workflows/typecheck.yml +36 -0
  7. data/.github/workflows/windows.yml +28 -0
  8. data/.gitignore +1 -0
  9. data/.rubocop.yml +42 -2
  10. data/CHANGELOG.md +845 -1
  11. data/README.md +64 -4
  12. data/Rakefile +198 -18
  13. data/Steepfile +11 -11
  14. data/config.yml +311 -0
  15. data/core/array.rbs +2189 -1914
  16. data/core/basic_object.rbs +59 -84
  17. data/core/binding.rbs +7 -69
  18. data/core/builtin.rbs +210 -11
  19. data/core/class.rbs +37 -0
  20. data/core/comparable.rbs +23 -25
  21. data/core/complex.rbs +449 -227
  22. data/core/constants.rbs +29 -21
  23. data/core/data.rbs +415 -0
  24. data/core/dir.rbs +698 -415
  25. data/core/encoding.rbs +468 -843
  26. data/core/enumerable.rbs +495 -455
  27. data/core/enumerator/product.rbs +92 -0
  28. data/core/enumerator.rbs +106 -9
  29. data/core/env.rbs +1 -1
  30. data/core/errno.rbs +506 -605
  31. data/core/errors.rbs +15 -17
  32. data/core/exception.rbs +361 -145
  33. data/core/false_class.rbs +39 -26
  34. data/core/fiber.rbs +121 -14
  35. data/core/file.rbs +1262 -320
  36. data/core/file_test.rbs +62 -45
  37. data/core/float.rbs +187 -208
  38. data/core/gc.rbs +446 -196
  39. data/core/global_variables.rbs +29 -29
  40. data/core/hash.rbs +242 -349
  41. data/core/integer.rbs +246 -308
  42. data/core/io/buffer.rbs +373 -122
  43. data/core/io/wait.rbs +29 -17
  44. data/core/io.rbs +1881 -1518
  45. data/core/kernel.rbs +2116 -1538
  46. data/core/marshal.rbs +24 -14
  47. data/core/match_data.rbs +413 -166
  48. data/core/math.rbs +531 -291
  49. data/core/method.rbs +101 -32
  50. data/core/module.rbs +228 -64
  51. data/core/nil_class.rbs +106 -47
  52. data/core/numeric.rbs +206 -292
  53. data/core/object.rbs +73 -1168
  54. data/core/object_space/weak_key_map.rbs +166 -0
  55. data/core/object_space.rbs +5 -3
  56. data/core/proc.rbs +280 -39
  57. data/core/process.rbs +1318 -658
  58. data/core/ractor.rbs +200 -134
  59. data/core/random.rbs +21 -4
  60. data/core/range.rbs +309 -153
  61. data/core/rational.rbs +4 -12
  62. data/core/rb_config.rbs +64 -43
  63. data/core/rbs/unnamed/argf.rbs +411 -147
  64. data/core/rbs/unnamed/env_class.rbs +137 -253
  65. data/core/rbs/unnamed/random.rbs +49 -26
  66. data/core/refinement.rbs +16 -1
  67. data/core/regexp.rbs +1568 -862
  68. data/core/ruby_vm.rbs +719 -7
  69. data/core/rubygems/config_file.rbs +3 -0
  70. data/core/rubygems/errors.rbs +69 -6
  71. data/core/rubygems/rubygems.rbs +71 -17
  72. data/core/rubygems/version.rbs +11 -7
  73. data/{stdlib/set/0 → core}/set.rbs +80 -91
  74. data/core/signal.rbs +14 -8
  75. data/core/string.rbs +1732 -1607
  76. data/core/struct.rbs +467 -95
  77. data/core/symbol.rbs +215 -245
  78. data/core/thread.rbs +133 -89
  79. data/core/thread_group.rbs +9 -9
  80. data/core/time.rbs +1141 -841
  81. data/core/trace_point.rbs +181 -121
  82. data/core/true_class.rbs +58 -32
  83. data/core/unbound_method.rbs +103 -30
  84. data/core/warning.rbs +50 -5
  85. data/docs/CONTRIBUTING.md +1 -1
  86. data/docs/architecture.md +110 -0
  87. data/docs/collection.md +59 -5
  88. data/docs/data_and_struct.md +86 -0
  89. data/docs/gem.md +57 -0
  90. data/docs/rbs_by_example.md +16 -35
  91. data/docs/repo.md +1 -1
  92. data/docs/sigs.md +7 -7
  93. data/docs/stdlib.md +63 -5
  94. data/docs/syntax.md +255 -61
  95. data/docs/tools.md +1 -0
  96. data/ext/rbs_extension/extconf.rb +10 -0
  97. data/ext/rbs_extension/lexer.c +1741 -1548
  98. data/ext/rbs_extension/lexer.h +11 -1
  99. data/ext/rbs_extension/lexer.re +12 -6
  100. data/ext/rbs_extension/lexstate.c +26 -3
  101. data/ext/rbs_extension/location.c +119 -111
  102. data/ext/rbs_extension/location.h +32 -7
  103. data/ext/rbs_extension/main.c +3 -0
  104. data/ext/rbs_extension/parser.c +883 -481
  105. data/ext/rbs_extension/parserstate.c +65 -25
  106. data/ext/rbs_extension/parserstate.h +13 -3
  107. data/ext/rbs_extension/rbs_extension.h +1 -10
  108. data/ext/rbs_extension/unescape.c +7 -47
  109. data/goodcheck.yml +2 -2
  110. data/{ext/rbs_extension → include/rbs}/constants.h +26 -15
  111. data/include/rbs/ruby_objs.h +72 -0
  112. data/include/rbs.h +7 -0
  113. data/lib/rbs/annotate/annotations.rb +3 -3
  114. data/lib/rbs/annotate/formatter.rb +13 -3
  115. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  116. data/lib/rbs/annotate/rdoc_source.rb +12 -3
  117. data/lib/rbs/ast/declarations.rb +85 -2
  118. data/lib/rbs/ast/directives.rb +39 -0
  119. data/lib/rbs/ast/members.rb +49 -15
  120. data/lib/rbs/ast/type_param.rb +104 -15
  121. data/lib/rbs/ast/visitor.rb +137 -0
  122. data/lib/rbs/buffer.rb +5 -0
  123. data/lib/rbs/cli/colored_io.rb +48 -0
  124. data/lib/rbs/cli/diff.rb +83 -0
  125. data/lib/rbs/cli/validate.rb +356 -0
  126. data/lib/rbs/cli.rb +253 -143
  127. data/lib/rbs/collection/cleaner.rb +8 -1
  128. data/lib/rbs/collection/config/lockfile.rb +92 -0
  129. data/lib/rbs/collection/config/lockfile_generator.rb +154 -65
  130. data/lib/rbs/collection/config.rb +19 -46
  131. data/lib/rbs/collection/installer.rb +12 -13
  132. data/lib/rbs/collection/sources/base.rb +2 -2
  133. data/lib/rbs/collection/sources/git.rb +146 -69
  134. data/lib/rbs/collection/sources/local.rb +81 -0
  135. data/lib/rbs/collection/sources/rubygems.rb +10 -12
  136. data/lib/rbs/collection/sources/stdlib.rb +14 -13
  137. data/lib/rbs/collection/sources.rb +15 -2
  138. data/lib/rbs/collection.rb +2 -1
  139. data/lib/rbs/definition.rb +13 -16
  140. data/lib/rbs/definition_builder/ancestor_builder.rb +100 -24
  141. data/lib/rbs/definition_builder/method_builder.rb +4 -4
  142. data/lib/rbs/definition_builder.rb +489 -584
  143. data/lib/rbs/diff.rb +125 -0
  144. data/lib/rbs/environment/use_map.rb +77 -0
  145. data/lib/rbs/environment.rb +406 -105
  146. data/lib/rbs/environment_loader.rb +48 -44
  147. data/lib/rbs/environment_walker.rb +1 -1
  148. data/lib/rbs/errors.rb +175 -56
  149. data/lib/rbs/file_finder.rb +28 -0
  150. data/lib/rbs/location_aux.rb +8 -7
  151. data/lib/rbs/locator.rb +37 -15
  152. data/lib/rbs/method_type.rb +23 -0
  153. data/lib/rbs/namespace.rb +1 -0
  154. data/lib/rbs/parser/lex_result.rb +15 -0
  155. data/lib/rbs/parser/token.rb +23 -0
  156. data/lib/rbs/parser_aux.rb +22 -13
  157. data/lib/rbs/prototype/helpers.rb +48 -22
  158. data/lib/rbs/prototype/node_usage.rb +99 -0
  159. data/lib/rbs/prototype/rb.rb +125 -31
  160. data/lib/rbs/prototype/rbi.rb +49 -36
  161. data/lib/rbs/prototype/runtime/helpers.rb +59 -0
  162. data/lib/rbs/prototype/runtime/reflection.rb +19 -0
  163. data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
  164. data/lib/rbs/prototype/runtime.rb +273 -159
  165. data/lib/rbs/resolver/constant_resolver.rb +24 -8
  166. data/lib/rbs/resolver/type_name_resolver.rb +41 -7
  167. data/lib/rbs/sorter.rb +153 -123
  168. data/lib/rbs/substitution.rb +19 -0
  169. data/lib/rbs/subtractor.rb +201 -0
  170. data/lib/rbs/test/errors.rb +24 -11
  171. data/lib/rbs/test/guaranteed.rb +30 -0
  172. data/lib/rbs/test/hook.rb +45 -40
  173. data/lib/rbs/test/setup.rb +1 -1
  174. data/lib/rbs/test/tester.rb +1 -1
  175. data/lib/rbs/test/type_check.rb +120 -23
  176. data/lib/rbs/test.rb +6 -3
  177. data/lib/rbs/type_alias_dependency.rb +13 -3
  178. data/lib/rbs/type_alias_regularity.rb +21 -14
  179. data/lib/rbs/type_name.rb +18 -13
  180. data/lib/rbs/types.rb +352 -18
  181. data/lib/rbs/unit_test/convertibles.rb +176 -0
  182. data/lib/rbs/unit_test/spy.rb +136 -0
  183. data/lib/rbs/unit_test/type_assertions.rb +341 -0
  184. data/lib/rbs/unit_test/with_aliases.rb +143 -0
  185. data/lib/rbs/unit_test.rb +6 -0
  186. data/lib/rbs/validator.rb +55 -30
  187. data/lib/rbs/variance_calculator.rb +26 -23
  188. data/lib/rbs/vendorer.rb +3 -3
  189. data/lib/rbs/version.rb +1 -1
  190. data/lib/rbs/writer.rb +69 -22
  191. data/lib/rbs.rb +7 -2
  192. data/lib/rdoc/discover.rb +1 -1
  193. data/lib/rdoc_plugin/parser.rb +5 -5
  194. data/rbs.gemspec +12 -2
  195. data/schema/decls.json +1 -1
  196. data/schema/members.json +15 -10
  197. data/sig/ancestor_builder.rbs +4 -0
  198. data/sig/ancestor_graph.rbs +22 -2
  199. data/sig/annotate/formatter.rbs +2 -2
  200. data/sig/annotate/rdoc_annotater.rbs +1 -1
  201. data/sig/cli/colored_io.rbs +15 -0
  202. data/sig/cli/diff.rbs +21 -0
  203. data/sig/cli/validate.rbs +43 -0
  204. data/sig/cli.rbs +4 -0
  205. data/sig/collection/config/lockfile.rbs +74 -0
  206. data/sig/collection/config/lockfile_generator.rbs +66 -0
  207. data/sig/collection/config.rbs +5 -48
  208. data/sig/collection/installer.rbs +1 -1
  209. data/sig/collection/sources.rbs +105 -33
  210. data/sig/constant.rbs +1 -1
  211. data/sig/declarations.rbs +42 -3
  212. data/sig/definition.rbs +26 -10
  213. data/sig/definition_builder.rbs +103 -81
  214. data/sig/diff.rbs +28 -0
  215. data/sig/directives.rbs +61 -0
  216. data/sig/environment.rbs +175 -29
  217. data/sig/environment_loader.rbs +20 -18
  218. data/sig/errors.rbs +123 -2
  219. data/sig/file_finder.rbs +28 -0
  220. data/sig/location.rbs +0 -3
  221. data/sig/locator.rbs +14 -2
  222. data/sig/manifest.yaml +0 -1
  223. data/sig/members.rbs +32 -9
  224. data/sig/method_types.rbs +10 -4
  225. data/sig/namespace.rbs +2 -3
  226. data/sig/parser.rbs +55 -16
  227. data/sig/prototype/helpers.rbs +4 -0
  228. data/sig/prototype/node_usage.rbs +20 -0
  229. data/sig/prototype/rb.rbs +10 -2
  230. data/sig/prototype/rbi.rbs +2 -0
  231. data/sig/prototype/runtime.rbs +182 -0
  232. data/sig/rbs.rbs +1 -1
  233. data/sig/rdoc/rbs.rbs +4 -0
  234. data/sig/repository.rbs +7 -5
  235. data/sig/resolver/constant_resolver.rbs +3 -4
  236. data/sig/resolver/context.rbs +1 -1
  237. data/sig/resolver/type_name_resolver.rbs +5 -1
  238. data/sig/shims/bundler.rbs +38 -0
  239. data/sig/shims/rubygems.rbs +19 -0
  240. data/sig/sorter.rbs +23 -5
  241. data/sig/substitution.rbs +6 -0
  242. data/sig/subtractor.rbs +37 -0
  243. data/sig/test/errors.rbs +52 -0
  244. data/sig/test/guranteed.rbs +9 -0
  245. data/sig/test/type_check.rbs +19 -0
  246. data/sig/test.rbs +82 -0
  247. data/sig/type_alias_dependency.rbs +31 -0
  248. data/sig/type_alias_regularity.rbs +12 -6
  249. data/sig/type_param.rbs +45 -9
  250. data/sig/typename.rbs +8 -5
  251. data/sig/types.rbs +119 -12
  252. data/sig/unit_test/convertibles.rbs +154 -0
  253. data/sig/unit_test/spy.rbs +28 -0
  254. data/sig/unit_test/type_assertions.rbs +194 -0
  255. data/sig/unit_test/with_aliases.rbs +136 -0
  256. data/sig/use_map.rbs +35 -0
  257. data/sig/validator.rbs +12 -5
  258. data/sig/variance_calculator.rbs +3 -1
  259. data/sig/vendorer.rbs +1 -1
  260. data/sig/visitor.rbs +47 -0
  261. data/sig/writer.rbs +6 -2
  262. data/src/constants.c +153 -0
  263. data/src/ruby_objs.c +793 -0
  264. data/stdlib/base64/0/base64.rbs +298 -45
  265. data/stdlib/benchmark/0/benchmark.rbs +12 -3
  266. data/stdlib/bigdecimal/0/big_decimal.rbs +62 -198
  267. data/stdlib/cgi/0/core.rbs +68 -15
  268. data/stdlib/cgi/0/manifest.yaml +1 -0
  269. data/stdlib/coverage/0/coverage.rbs +50 -11
  270. data/stdlib/csv/0/csv.rbs +90 -119
  271. data/stdlib/csv/0/manifest.yaml +1 -0
  272. data/stdlib/date/0/date.rbs +806 -735
  273. data/stdlib/date/0/date_time.rbs +70 -211
  274. data/stdlib/dbm/0/dbm.rbs +0 -2
  275. data/stdlib/delegate/0/delegator.rbs +184 -0
  276. data/stdlib/delegate/0/kernel.rbs +47 -0
  277. data/stdlib/delegate/0/simple_delegator.rbs +96 -0
  278. data/stdlib/did_you_mean/0/did_you_mean.rbs +3 -8
  279. data/stdlib/digest/0/digest.rbs +48 -35
  280. data/stdlib/erb/0/erb.rbs +15 -39
  281. data/stdlib/etc/0/etc.rbs +174 -54
  282. data/stdlib/fileutils/0/fileutils.rbs +1234 -385
  283. data/stdlib/forwardable/0/forwardable.rbs +4 -4
  284. data/stdlib/io-console/0/io-console.rbs +82 -17
  285. data/stdlib/ipaddr/0/ipaddr.rbs +11 -6
  286. data/stdlib/json/0/json.rbs +434 -151
  287. data/stdlib/kconv/0/kconv.rbs +166 -0
  288. data/stdlib/logger/0/formatter.rbs +0 -2
  289. data/stdlib/logger/0/log_device.rbs +1 -3
  290. data/stdlib/logger/0/logger.rbs +465 -328
  291. data/stdlib/minitest/0/kernel.rbs +2 -2
  292. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +4 -1
  293. data/stdlib/minitest/0/minitest/assertion.rbs +1 -0
  294. data/stdlib/minitest/0/minitest/assertions.rbs +58 -13
  295. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +7 -0
  296. data/stdlib/minitest/0/minitest/bench_spec.rbs +8 -8
  297. data/stdlib/minitest/0/minitest/benchmark.rbs +17 -16
  298. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  299. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  300. data/stdlib/minitest/0/minitest/mock.rbs +9 -5
  301. data/stdlib/minitest/0/minitest/parallel/executor.rbs +4 -0
  302. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +0 -1
  303. data/stdlib/minitest/0/minitest/pride_io.rbs +8 -0
  304. data/stdlib/minitest/0/minitest/pride_lol.rbs +2 -0
  305. data/stdlib/minitest/0/minitest/progress_reporter.rbs +1 -1
  306. data/stdlib/minitest/0/minitest/reportable.rbs +2 -0
  307. data/stdlib/minitest/0/minitest/runnable.rbs +33 -1
  308. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +1 -1
  309. data/stdlib/minitest/0/minitest/spec/dsl.rbs +10 -6
  310. data/stdlib/minitest/0/minitest/spec.rbs +1 -1
  311. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +5 -0
  312. data/stdlib/minitest/0/minitest/summary_reporter.rbs +0 -7
  313. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +7 -7
  314. data/stdlib/minitest/0/minitest/test.rbs +7 -14
  315. data/stdlib/minitest/0/minitest/unexpected_error.rbs +2 -0
  316. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  317. data/stdlib/minitest/0/minitest/unit.rbs +1 -2
  318. data/stdlib/minitest/0/minitest.rbs +41 -892
  319. data/stdlib/monitor/0/monitor.rbs +91 -10
  320. data/stdlib/mutex_m/0/mutex_m.rbs +0 -2
  321. data/stdlib/net-http/0/manifest.yaml +1 -1
  322. data/stdlib/net-http/0/net-http.rbs +3858 -964
  323. data/stdlib/net-protocol/0/manifest.yaml +2 -0
  324. data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
  325. data/stdlib/net-smtp/0/manifest.yaml +2 -0
  326. data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
  327. data/stdlib/nkf/0/nkf.rbs +35 -5
  328. data/stdlib/objspace/0/objspace.rbs +40 -18
  329. data/stdlib/observable/0/observable.rbs +217 -0
  330. data/stdlib/open-uri/0/manifest.yaml +4 -0
  331. data/stdlib/open-uri/0/open-uri.rbs +393 -0
  332. data/stdlib/open3/0/open3.rbs +147 -0
  333. data/stdlib/openssl/0/manifest.yaml +1 -0
  334. data/stdlib/openssl/0/openssl.rbs +681 -316
  335. data/stdlib/optparse/0/optparse.rbs +100 -65
  336. data/stdlib/pathname/0/pathname.rbs +24 -15
  337. data/stdlib/pp/0/manifest.yaml +2 -0
  338. data/stdlib/pp/0/pp.rbs +300 -0
  339. data/stdlib/prettyprint/0/prettyprint.rbs +2 -6
  340. data/stdlib/pstore/0/pstore.rbs +370 -156
  341. data/stdlib/psych/0/core_ext.rbs +12 -0
  342. data/stdlib/{yaml → psych}/0/dbm.rbs +3 -3
  343. data/stdlib/psych/0/manifest.yaml +3 -0
  344. data/stdlib/psych/0/psych.rbs +402 -0
  345. data/stdlib/{yaml → psych}/0/store.rbs +2 -2
  346. data/stdlib/pty/0/pty.rbs +63 -11
  347. data/stdlib/rdoc/0/code_object.rbs +51 -0
  348. data/stdlib/rdoc/0/comment.rbs +59 -0
  349. data/stdlib/rdoc/0/context.rbs +153 -0
  350. data/stdlib/rdoc/0/markup.rbs +117 -0
  351. data/stdlib/rdoc/0/parser.rbs +56 -0
  352. data/stdlib/rdoc/0/rdoc.rbs +13 -380
  353. data/stdlib/rdoc/0/ri.rbs +17 -0
  354. data/stdlib/rdoc/0/store.rbs +48 -0
  355. data/stdlib/rdoc/0/top_level.rbs +97 -0
  356. data/stdlib/resolv/0/resolv.rbs +16 -79
  357. data/stdlib/ripper/0/ripper.rbs +1648 -0
  358. data/stdlib/securerandom/0/securerandom.rbs +7 -2
  359. data/stdlib/shellwords/0/shellwords.rbs +11 -12
  360. data/stdlib/singleton/0/singleton.rbs +0 -3
  361. data/stdlib/socket/0/addrinfo.rbs +13 -18
  362. data/stdlib/socket/0/basic_socket.rbs +5 -10
  363. data/stdlib/socket/0/ip_socket.rbs +0 -2
  364. data/stdlib/socket/0/socket.rbs +77 -46
  365. data/stdlib/socket/0/tcp_server.rbs +0 -5
  366. data/stdlib/socket/0/tcp_socket.rbs +36 -3
  367. data/stdlib/socket/0/udp_socket.rbs +4 -5
  368. data/stdlib/socket/0/unix_server.rbs +0 -5
  369. data/stdlib/socket/0/unix_socket.rbs +2 -4
  370. data/{core/string_io.rbs → stdlib/stringio/0/stringio.rbs} +188 -107
  371. data/stdlib/strscan/0/string_scanner.rbs +1269 -425
  372. data/stdlib/tempfile/0/tempfile.rbs +224 -61
  373. data/stdlib/time/0/time.rbs +48 -35
  374. data/stdlib/timeout/0/timeout.rbs +17 -8
  375. data/stdlib/tmpdir/0/tmpdir.rbs +10 -3
  376. data/stdlib/tsort/0/tsort.rbs +0 -4
  377. data/stdlib/uri/0/common.rbs +271 -144
  378. data/stdlib/uri/0/file.rbs +5 -0
  379. data/stdlib/uri/0/ftp.rbs +1 -1
  380. data/stdlib/uri/0/generic.rbs +26 -22
  381. data/stdlib/uri/0/http.rbs +4 -4
  382. data/stdlib/uri/0/ldap.rbs +1 -1
  383. data/stdlib/uri/0/mailto.rbs +84 -0
  384. data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
  385. data/stdlib/yaml/0/manifest.yaml +1 -2
  386. data/stdlib/yaml/0/yaml.rbs +1 -199
  387. data/stdlib/zlib/0/buf_error.rbs +10 -0
  388. data/stdlib/zlib/0/data_error.rbs +10 -0
  389. data/stdlib/zlib/0/deflate.rbs +210 -0
  390. data/stdlib/zlib/0/error.rbs +20 -0
  391. data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
  392. data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
  393. data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
  394. data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
  395. data/stdlib/zlib/0/gzip_file.rbs +156 -0
  396. data/stdlib/zlib/0/gzip_reader.rbs +293 -0
  397. data/stdlib/zlib/0/gzip_writer.rbs +166 -0
  398. data/stdlib/zlib/0/inflate.rbs +180 -0
  399. data/stdlib/zlib/0/mem_error.rbs +10 -0
  400. data/stdlib/zlib/0/need_dict.rbs +13 -0
  401. data/stdlib/zlib/0/stream_end.rbs +11 -0
  402. data/stdlib/zlib/0/stream_error.rbs +11 -0
  403. data/stdlib/zlib/0/version_error.rbs +11 -0
  404. data/stdlib/zlib/0/zlib.rbs +1 -3
  405. data/stdlib/zlib/0/zstream.rbs +200 -0
  406. data/templates/include/rbs/constants.h.erb +20 -0
  407. data/templates/include/rbs/ruby_objs.h.erb +10 -0
  408. data/templates/src/constants.c.erb +36 -0
  409. data/templates/src/ruby_objs.c.erb +27 -0
  410. data/templates/template.rb +122 -0
  411. metadata +136 -36
  412. data/Gemfile +0 -33
  413. data/Gemfile.lock +0 -118
  414. data/core/deprecated.rbs +0 -9
  415. data/ext/rbs_extension/constants.c +0 -135
  416. data/ext/rbs_extension/ruby_objs.c +0 -525
  417. data/ext/rbs_extension/ruby_objs.h +0 -43
  418. data/lib/rbs/constant_table.rb +0 -167
  419. data/lib/rbs/parser_compat/lexer_error.rb +0 -6
  420. data/lib/rbs/parser_compat/located_value.rb +0 -7
  421. data/lib/rbs/parser_compat/semantics_error.rb +0 -6
  422. data/lib/rbs/parser_compat/syntax_error.rb +0 -6
  423. data/lib/rbs/test/spy.rb +0 -6
  424. data/lib/rbs/type_name_resolver.rb +0 -67
  425. data/sig/constant_table.rbs +0 -30
  426. data/sig/shims/abstract_syntax_tree.rbs +0 -25
  427. data/sig/shims/pp.rbs +0 -3
  428. data/sig/shims/ripper.rbs +0 -8
  429. data/sig/shims.rbs +0 -69
  430. data/sig/type_name_resolver.rbs +0 -26
  431. data/stdlib/minitest/0/manifest.yaml +0 -2
  432. data/stdlib/prime/0/integer-extension.rbs +0 -41
  433. data/stdlib/prime/0/manifest.yaml +0 -2
  434. data/stdlib/prime/0/prime.rbs +0 -372
@@ -1,225 +1,337 @@
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
69
+ # And may also have:
79
70
  #
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.
71
+ # * A message.
72
+ # * A program name.
84
73
  #
85
- # ## HOWTOs
74
+ # Example:
86
75
  #
87
- # ### How to create a logger
76
+ # logger = Logger.new($stdout)
77
+ # logger.add(Logger::INFO, 'My message.', 'mung')
78
+ # # => I, [2022-05-07T17:21:46.536234 #20536] INFO -- mung: My message.
88
79
  #
89
- # The options below give you various choices, in more or less increasing
90
- # complexity.
80
+ # The default format for an entry is:
91
81
  #
92
- # 1. Create a logger which logs messages to STDERR/STDOUT.
82
+ # "%s, [%s #%d] %5s -- %s: %s\n"
93
83
  #
94
- # logger = Logger.new(STDERR)
95
- # logger = Logger.new(STDOUT)
84
+ # where the values to be formatted are:
96
85
  #
97
- # 2. Create a logger for the file which has the specified name.
86
+ # * Severity (one letter).
87
+ # * Timestamp.
88
+ # * Process id.
89
+ # * Severity (word).
90
+ # * Program name.
91
+ # * Message.
98
92
  #
99
- # logger = Logger.new('logfile.log')
93
+ # You can use a different entry format by:
100
94
  #
101
- # 3. Create a logger for the specified file.
95
+ # * Setting a custom format proc (affects following entries); see
96
+ # [formatter=](Logger.html#attribute-i-formatter).
97
+ # * Calling any of the methods above with a block (affects only the one
98
+ # entry). Doing so can have two benefits:
102
99
  #
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)
100
+ # * Context: the block can evaluate the entire program context and create
101
+ # a context-dependent message.
102
+ # * Performance: the block is not evaluated unless the log level permits
103
+ # the entry actually to be written:
107
104
  #
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.
105
+ # logger.error { my_slow_message_generator }
110
106
  #
111
- # logger = Logger.new('foo.log', 10, 1024000)
107
+ # Contrast this with the string form, where the string is always
108
+ # evaluated, regardless of the log level:
112
109
  #
113
- # 5. Create a logger which ages the logfile daily/weekly/monthly.
110
+ # logger.error("#{my_slow_message_generator}")
114
111
  #
115
- # logger = Logger.new('foo.log', 'daily')
116
- # logger = Logger.new('foo.log', 'weekly')
117
- # logger = Logger.new('foo.log', 'monthly')
112
+ # ### Severity
118
113
  #
114
+ # The severity of a log entry has two effects:
119
115
  #
120
- # ### How to log a message
116
+ # * Determines whether the entry is selected for inclusion in the log; see
117
+ # [Log Level](rdoc-ref:Logger@Log+Level).
118
+ # * Indicates to any log reader (whether a person or a program) the relative
119
+ # importance of the entry.
121
120
  #
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.
121
+ # ### Timestamp
126
122
  #
127
- # 1. Message in a block.
123
+ # The timestamp for a log entry is generated automatically when the entry is
124
+ # created.
128
125
  #
129
- # logger.fatal { "Argument 'foo' not given." }
126
+ # The logged timestamp is formatted by method
127
+ # [Time#strftime](rdoc-ref:Time#strftime) using this format string:
130
128
  #
131
- # 2. Message as a string.
129
+ # '%Y-%m-%dT%H:%M:%S.%6N'
132
130
  #
133
- # logger.error "Argument #{@foo} mismatch."
131
+ # Example:
134
132
  #
135
- # 3. With progname.
133
+ # logger = Logger.new($stdout)
134
+ # logger.add(Logger::INFO)
135
+ # # => I, [2022-05-07T17:04:32.318331 #20536] INFO -- : nil
136
136
  #
137
- # logger.info('initialize') { "Initializing..." }
137
+ # You can set a different format using method #datetime_format=.
138
138
  #
139
- # 4. With severity.
139
+ # ### Message
140
140
  #
141
- # logger.add(Logger::FATAL) { 'Fatal error!' }
141
+ # The message is an optional argument to an entry method:
142
142
  #
143
+ # logger = Logger.new($stdout)
144
+ # logger.add(Logger::INFO, 'My message')
145
+ # # => I, [2022-05-07T18:15:37.647581 #20536] INFO -- : My message
143
146
  #
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:
147
+ # For the default entry formatter, `Logger::Formatter`, the message object may
148
+ # be:
147
149
  #
148
- # logger.debug { "This is a " + potentially + " expensive operation" }
150
+ # * A string: used as-is.
151
+ # * An Exception: `message.message` is used.
152
+ # * Anything else: `message.inspect` is used.
149
153
  #
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:
154
+ # **Note**: Logger::Formatter does not escape or sanitize the message passed to
155
+ # it. Developers should be aware that malicious data (user input) may be in the
156
+ # message, and should explicitly escape untrusted data.
152
157
  #
153
- # logger.debug("This is a " + potentially + " expensive operation")
158
+ # You can use a custom formatter to escape message data; see the example at
159
+ # [formatter=](Logger.html#attribute-i-formatter).
154
160
  #
155
- # Here, the string concatenation is done every time, even if the log level is
156
- # not set to show the debug message.
161
+ # ### Program Name
157
162
  #
158
- # ### How to close a logger
163
+ # The program name is an optional argument to an entry method:
159
164
  #
160
- # logger.close
165
+ # logger = Logger.new($stdout)
166
+ # logger.add(Logger::INFO, 'My message', 'mung')
167
+ # # => I, [2022-05-07T18:17:38.084716 #20536] INFO -- mung: My message
168
+ #
169
+ # The default program name for a new logger may be set in the call to Logger.new
170
+ # via optional keyword argument `progname`:
171
+ #
172
+ # logger = Logger.new('t.log', progname: 'mung')
173
+ #
174
+ # The default program name for an existing logger may be set by a call to method
175
+ # #progname=:
176
+ #
177
+ # logger.progname = 'mung'
178
+ #
179
+ # The current program name may be retrieved with method
180
+ # [progname](Logger.html#attribute-i-progname):
181
+ #
182
+ # logger.progname # => "mung"
183
+ #
184
+ # ## Log Level
185
+ #
186
+ # The log level setting determines whether an entry is actually written to the
187
+ # log, based on the entry's severity.
188
+ #
189
+ # These are the defined severities (least severe to most severe):
190
+ #
191
+ # logger = Logger.new($stdout)
192
+ # logger.add(Logger::DEBUG, 'Maximal debugging info')
193
+ # # => D, [2022-05-07T17:57:41.776220 #20536] DEBUG -- : Maximal debugging info
194
+ # logger.add(Logger::INFO, 'Non-error information')
195
+ # # => I, [2022-05-07T17:59:14.349167 #20536] INFO -- : Non-error information
196
+ # logger.add(Logger::WARN, 'Non-error warning')
197
+ # # => W, [2022-05-07T18:00:45.337538 #20536] WARN -- : Non-error warning
198
+ # logger.add(Logger::ERROR, 'Non-fatal error')
199
+ # # => E, [2022-05-07T18:02:41.592912 #20536] ERROR -- : Non-fatal error
200
+ # logger.add(Logger::FATAL, 'Fatal error')
201
+ # # => F, [2022-05-07T18:05:24.703931 #20536] FATAL -- : Fatal error
202
+ # logger.add(Logger::UNKNOWN, 'Most severe')
203
+ # # => A, [2022-05-07T18:07:54.657491 #20536] ANY -- : Most severe
204
+ #
205
+ # The default initial level setting is Logger::DEBUG, the lowest level, which
206
+ # means that all entries are to be written, regardless of severity:
207
+ #
208
+ # logger = Logger.new($stdout)
209
+ # logger.level # => 0
210
+ # logger.add(0, "My message")
211
+ # # => D, [2022-05-11T15:10:59.773668 #20536] DEBUG -- : My message
212
+ #
213
+ # You can specify a different setting in a new logger using keyword argument
214
+ # `level` with an appropriate value:
215
+ #
216
+ # logger = Logger.new($stdout, level: Logger::ERROR)
217
+ # logger = Logger.new($stdout, level: 'error')
218
+ # logger = Logger.new($stdout, level: :error)
219
+ # logger.level # => 3
220
+ #
221
+ # With this level, entries with severity Logger::ERROR and higher are written,
222
+ # while those with lower severities are not written:
223
+ #
224
+ # logger = Logger.new($stdout, level: Logger::ERROR)
225
+ # logger.add(3)
226
+ # # => E, [2022-05-11T15:17:20.933362 #20536] ERROR -- : nil
227
+ # logger.add(2) # Silent.
228
+ #
229
+ # You can set the log level for an existing logger with method #level=:
230
+ #
231
+ # logger.level = Logger::ERROR
232
+ #
233
+ # These shorthand methods also set the level:
161
234
  #
162
- # ### Setting severity threshold
235
+ # logger.debug! # => 0
236
+ # logger.info! # => 1
237
+ # logger.warn! # => 2
238
+ # logger.error! # => 3
239
+ # logger.fatal! # => 4
163
240
  #
164
- # 1. Original interface.
241
+ # You can retrieve the log level with method #level.
165
242
  #
166
- # logger.sev_threshold = Logger::WARN
243
+ # logger.level = Logger::ERROR
244
+ # logger.level # => 3
167
245
  #
168
- # 2. Log4r (somewhat) compatible interface.
246
+ # These methods return whether a given level is to be written:
169
247
  #
170
- # logger.level = Logger::INFO
248
+ # logger.level = Logger::ERROR
249
+ # logger.debug? # => false
250
+ # logger.info? # => false
251
+ # logger.warn? # => false
252
+ # logger.error? # => true
253
+ # logger.fatal? # => true
171
254
  #
172
- # # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
255
+ # ## Log File Rotation
173
256
  #
174
- # 3. Symbol or String (case insensitive)
257
+ # By default, a log file is a single file that grows indefinitely (until
258
+ # explicitly closed); there is no file rotation.
175
259
  #
176
- # logger.level = :info
177
- # logger.level = 'INFO'
260
+ # To keep log files to a manageable size, you can use *log* *file* *rotation*,
261
+ # which uses multiple log files:
178
262
  #
179
- # # :debug < :info < :warn < :error < :fatal < :unknown
263
+ # * Each log file has entries for a non-overlapping time interval.
264
+ # * Only the most recent log file is open and active; the others are closed
265
+ # and inactive.
180
266
  #
181
- # 4. Constructor
267
+ # ### Size-Based Rotation
182
268
  #
183
- # Logger.new(logdev, level: Logger::INFO)
184
- # Logger.new(logdev, level: :info)
185
- # Logger.new(logdev, level: 'INFO')
269
+ # For size-based log file rotation, call Logger.new with:
186
270
  #
271
+ # * Argument `logdev` as a file path.
272
+ # * Argument `shift_age` with a positive integer: the number of log files to
273
+ # be in the rotation.
274
+ # * Argument `shift_size` as a positive integer: the maximum size (in bytes)
275
+ # of each log file; defaults to 1048576 (1 megabyte).
187
276
  #
188
- # ## Format
277
+ # Examples:
189
278
  #
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:
279
+ # logger = Logger.new('t.log', 3) # Three 1-megabyte files.
280
+ # logger = Logger.new('t.log', 5, 10485760) # Five 10-megabyte files.
192
281
  #
193
- # Log format:
194
- # SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
282
+ # For these examples, suppose:
195
283
  #
196
- # Log sample:
197
- # I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.
284
+ # logger = Logger.new('t.log', 3)
198
285
  #
199
- # You may change the date and time format via #datetime_format=.
286
+ # Logging begins in the new log file, `t.log`; the log file is "full" and ready
287
+ # for rotation when a new entry would cause its size to exceed `shift_size`.
200
288
  #
201
- # logger.datetime_format = '%Y-%m-%d %H:%M:%S'
202
- # # e.g. "2004-01-03 00:54:26"
289
+ # The first time `t.log` is full:
203
290
  #
204
- # or via the constructor.
291
+ # * `t.log` is closed and renamed to `t.log.0`.
292
+ # * A new file `t.log` is opened.
205
293
  #
206
- # Logger.new(logdev, datetime_format: '%Y-%m-%d %H:%M:%S')
294
+ # The second time `t.log` is full:
207
295
  #
208
- # Or, you may change the overall format via the #formatter= method.
296
+ # * +t.log.0 is renamed as `t.log.1`.
297
+ # * `t.log` is closed and renamed to `t.log.0`.
298
+ # * A new file `t.log` is opened.
209
299
  #
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"
300
+ # Each subsequent time that `t.log` is full, the log files are rotated:
214
301
  #
215
- # or via the constructor.
302
+ # * `t.log.1` is removed.
303
+ # * +t.log.0 is renamed as `t.log.1`.
304
+ # * `t.log` is closed and renamed to `t.log.0`.
305
+ # * A new file `t.log` is opened.
216
306
  #
217
- # Logger.new(logdev, formatter: proc {|severity, datetime, progname, msg|
218
- # "#{datetime}: #{msg}\n"
219
- # })
307
+ # ### Periodic Rotation
220
308
  #
221
- # <!-- rdoc-file=lib/logger/errors.rb -->
222
- # not used after 1.2.7. just for compat.
309
+ # For periodic rotation, call Logger.new with:
310
+ #
311
+ # * Argument `logdev` as a file path.
312
+ # * Argument `shift_age` as a string period indicator.
313
+ #
314
+ # Examples:
315
+ #
316
+ # logger = Logger.new('t.log', 'daily') # Rotate log files daily.
317
+ # logger = Logger.new('t.log', 'weekly') # Rotate log files weekly.
318
+ # logger = Logger.new('t.log', 'monthly') # Rotate log files monthly.
319
+ #
320
+ # Example:
321
+ #
322
+ # logger = Logger.new('t.log', 'daily')
323
+ #
324
+ # When the given period expires:
325
+ #
326
+ # * The base log file, `t.log` is closed and renamed with a date-based suffix
327
+ # such as `t.log.20220509`.
328
+ # * A new log file `t.log` is opened.
329
+ # * Nothing is removed.
330
+ #
331
+ # The default format for the suffix is `'%Y%m%d'`, which produces a suffix
332
+ # similar to the one above. You can set a different format using create-time
333
+ # option `shift_period_suffix`; see details and suggestions at
334
+ # [Time#strftime](rdoc-ref:Time#strftime).
223
335
  #
224
336
  class Logger
225
337
  interface _WriteCloser
@@ -231,57 +343,52 @@ class Logger
231
343
 
232
344
  include Logger::Severity
233
345
 
234
- public
235
-
236
346
  # <!--
237
347
  # rdoc-file=lib/logger.rb
238
348
  # - <<(msg)
239
349
  # -->
240
- # Dump given message to the log device without any formatting. If no log device
241
- # exists, return `nil`.
350
+ # Writes the given `msg` to the log with no formatting; returns the number of
351
+ # characters written, or `nil` if no log device exists:
352
+ #
353
+ # logger = Logger.new($stdout)
354
+ # logger << 'My message.' # => 10
355
+ #
356
+ # Output:
357
+ #
358
+ # My message.
242
359
  #
243
360
  def <<: (untyped msg) -> (untyped | nil)
244
361
 
245
362
  # <!--
246
363
  # rdoc-file=lib/logger.rb
247
- # - Logger#add(severity, message = nil, progname = nil) { ... }
364
+ # - add(severity, message = nil, progname = nil) { || ... }
248
365
  # -->
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.
261
- #
366
+ # Creates a log entry, which may or may not be written to the log, depending on
367
+ # the entry's severity and on the log level. See [Log
368
+ # Level](rdoc-ref:Logger@Log+Level) and [Entries](rdoc-ref:Logger@Entries) for
369
+ # details.
262
370
  #
263
- # ### Return
371
+ # Examples:
264
372
  #
265
- # When the given severity is not high enough (for this particular logger), log
266
- # no message, and return `true`.
373
+ # logger = Logger.new($stdout, progname: 'mung')
374
+ # logger.add(Logger::INFO)
375
+ # logger.add(Logger::ERROR, 'No good')
376
+ # logger.add(Logger::ERROR, 'No good', 'gnum')
267
377
  #
268
- # ### Description
378
+ # Output:
269
379
  #
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.
380
+ # I, [2022-05-12T16:25:31.469726 #36328] INFO -- mung: mung
381
+ # E, [2022-05-12T16:25:55.349414 #36328] ERROR -- mung: No good
382
+ # E, [2022-05-12T16:26:35.841134 #36328] ERROR -- gnum: No good
273
383
  #
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.
384
+ # These convenience methods have implicit severity:
279
385
  #
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.
386
+ # * #debug.
387
+ # * #info.
388
+ # * #warn.
389
+ # * #error.
390
+ # * #fatal.
391
+ # * #unknown.
285
392
  #
286
393
  def add: (Integer severity, ?untyped message, ?untyped progname) ?{ () -> untyped } -> true
287
394
 
@@ -289,7 +396,13 @@ class Logger
289
396
  # rdoc-file=lib/logger.rb
290
397
  # - close()
291
398
  # -->
292
- # Close the logging device.
399
+ # Closes the logger; returns `nil`:
400
+ #
401
+ # logger = Logger.new('t.log')
402
+ # logger.close # => nil
403
+ # logger.info('foo') # Prints "log writing failed. closed stream"
404
+ #
405
+ # Related: Logger#reopen.
293
406
  #
294
407
  def close: () -> untyped
295
408
 
@@ -297,7 +410,7 @@ class Logger
297
410
  # rdoc-file=lib/logger.rb
298
411
  # - datetime_format()
299
412
  # -->
300
- # Returns the date format being used. See #datetime_format=
413
+ # Returns the date-time format; see #datetime_format=.
301
414
  #
302
415
  def datetime_format: () -> String?
303
416
 
@@ -305,10 +418,13 @@ class Logger
305
418
  # rdoc-file=lib/logger.rb
306
419
  # - datetime_format=(datetime_format)
307
420
  # -->
308
- # Set date-time format.
421
+ # Sets the date-time format.
309
422
  #
310
- # `datetime_format`
311
- # : A string suitable for passing to `strftime`.
423
+ # Argument `datetime_format` should be either of these:
424
+ #
425
+ # * A string suitable for use as a format for method
426
+ # [Time#strftime](rdoc-ref:Time#strftime).
427
+ # * `nil`: the logger uses `'%Y-%m-%dT%H:%M:%S.%6N'`.
312
428
  #
313
429
  def datetime_format=: (String datetime_format) -> String
314
430
  | (nil datetime_format) -> nil
@@ -317,9 +433,7 @@ class Logger
317
433
  # rdoc-file=lib/logger.rb
318
434
  # - debug(progname = nil, &block)
319
435
  # -->
320
- # Log a `DEBUG` message.
321
- #
322
- # See #info for more information.
436
+ # Equivalent to calling #add with severity `Logger::DEBUG`.
323
437
  #
324
438
  def debug: (?untyped progname) ?{ () -> untyped } -> true
325
439
 
@@ -327,7 +441,8 @@ class Logger
327
441
  # rdoc-file=lib/logger.rb
328
442
  # - debug!()
329
443
  # -->
330
- # Sets the severity to DEBUG.
444
+ # Sets the log level to Logger::DEBUG. See [Log
445
+ # Level](rdoc-ref:Logger@Log+Level).
331
446
  #
332
447
  def debug!: () -> Integer
333
448
 
@@ -335,8 +450,8 @@ class Logger
335
450
  # rdoc-file=lib/logger.rb
336
451
  # - debug?()
337
452
  # -->
338
- # Returns `true` if and only if the current severity level allows for the
339
- # printing of `DEBUG` messages.
453
+ # Returns `true` if the log level allows entries with severity Logger::DEBUG to
454
+ # be written, `false` otherwise. See [Log Level](rdoc-ref:Logger@Log+Level).
340
455
  #
341
456
  def debug?: () -> bool
342
457
 
@@ -344,9 +459,7 @@ class Logger
344
459
  # rdoc-file=lib/logger.rb
345
460
  # - error(progname = nil, &block)
346
461
  # -->
347
- # Log an `ERROR` message.
348
- #
349
- # See #info for more information.
462
+ # Equivalent to calling #add with severity `Logger::ERROR`.
350
463
  #
351
464
  def error: (?untyped progname) ?{ () -> untyped } -> true
352
465
 
@@ -354,7 +467,8 @@ class Logger
354
467
  # rdoc-file=lib/logger.rb
355
468
  # - error!()
356
469
  # -->
357
- # Sets the severity to ERROR.
470
+ # Sets the log level to Logger::ERROR. See [Log
471
+ # Level](rdoc-ref:Logger@Log+Level).
358
472
  #
359
473
  def error!: () -> Integer
360
474
 
@@ -362,8 +476,8 @@ class Logger
362
476
  # rdoc-file=lib/logger.rb
363
477
  # - error?()
364
478
  # -->
365
- # Returns `true` if and only if the current severity level allows for the
366
- # printing of `ERROR` messages.
479
+ # Returns `true` if the log level allows entries with severity Logger::ERROR to
480
+ # be written, `false` otherwise. See [Log Level](rdoc-ref:Logger@Log+Level).
367
481
  #
368
482
  def error?: () -> bool
369
483
 
@@ -371,9 +485,7 @@ class Logger
371
485
  # rdoc-file=lib/logger.rb
372
486
  # - fatal(progname = nil, &block)
373
487
  # -->
374
- # Log a `FATAL` message.
375
- #
376
- # See #info for more information.
488
+ # Equivalent to calling #add with severity `Logger::FATAL`.
377
489
  #
378
490
  def fatal: (?untyped progname) ?{ () -> untyped } -> true
379
491
 
@@ -381,7 +493,8 @@ class Logger
381
493
  # rdoc-file=lib/logger.rb
382
494
  # - fatal!()
383
495
  # -->
384
- # Sets the severity to FATAL.
496
+ # Sets the log level to Logger::FATAL. See [Log
497
+ # Level](rdoc-ref:Logger@Log+Level).
385
498
  #
386
499
  def fatal!: () -> Integer
387
500
 
@@ -389,83 +502,83 @@ class Logger
389
502
  # rdoc-file=lib/logger.rb
390
503
  # - fatal?()
391
504
  # -->
392
- # Returns `true` if and only if the current severity level allows for the
393
- # printing of `FATAL` messages.
505
+ # Returns `true` if the log level allows entries with severity Logger::FATAL to
506
+ # be written, `false` otherwise. See [Log Level](rdoc-ref:Logger@Log+Level).
394
507
  #
395
508
  def fatal?: () -> bool
396
509
 
397
510
  # <!-- 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:
511
+ # Sets or retrieves the logger entry formatter proc.
512
+ #
513
+ # When `formatter` is `nil`, the logger uses Logger::Formatter.
400
514
  #
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.
515
+ # When `formatter` is a proc, a new entry is formatted by the proc, which is
516
+ # called with four arguments:
409
517
  #
518
+ # * `severity`: The severity of the entry.
519
+ # * `time`: A Time object representing the entry's timestamp.
520
+ # * `progname`: The program name for the entry.
521
+ # * `msg`: The message for the entry (string or string-convertible object).
410
522
  #
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.
523
+ # The proc should return a string containing the formatted entry.
524
+ #
525
+ # This custom formatter uses [String#dump](rdoc-ref:String#dump) to escape the
526
+ # message string:
527
+ #
528
+ # logger = Logger.new($stdout, progname: 'mung')
529
+ # original_formatter = logger.formatter || Logger::Formatter.new
530
+ # logger.formatter = proc { |severity, time, progname, msg|
531
+ # original_formatter.call(severity, time, progname, msg.dump)
532
+ # }
533
+ # logger.add(Logger::INFO, "hello \n ''")
534
+ # logger.add(Logger::INFO, "\f\x00\xff\\\"")
535
+ #
536
+ # Output:
537
+ #
538
+ # I, [2022-05-13T13:16:29.637488 #8492] INFO -- mung: "hello \n ''"
539
+ # I, [2022-05-13T13:16:29.637610 #8492] INFO -- mung: "\f\x00\xFF\\\""
413
540
  #
414
541
  def formatter: () -> (_Formatter | nil)
415
542
 
416
543
  # <!-- 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:
544
+ # Sets or retrieves the logger entry formatter proc.
545
+ #
546
+ # When `formatter` is `nil`, the logger uses Logger::Formatter.
547
+ #
548
+ # When `formatter` is a proc, a new entry is formatted by the proc, which is
549
+ # called with four arguments:
419
550
  #
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.
551
+ # * `severity`: The severity of the entry.
552
+ # * `time`: A Time object representing the entry's timestamp.
553
+ # * `progname`: The program name for the entry.
554
+ # * `msg`: The message for the entry (string or string-convertible object).
428
555
  #
556
+ # The proc should return a string containing the formatted entry.
429
557
  #
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.
558
+ # This custom formatter uses [String#dump](rdoc-ref:String#dump) to escape the
559
+ # message string:
560
+ #
561
+ # logger = Logger.new($stdout, progname: 'mung')
562
+ # original_formatter = logger.formatter || Logger::Formatter.new
563
+ # logger.formatter = proc { |severity, time, progname, msg|
564
+ # original_formatter.call(severity, time, progname, msg.dump)
565
+ # }
566
+ # logger.add(Logger::INFO, "hello \n ''")
567
+ # logger.add(Logger::INFO, "\f\x00\xff\\\"")
568
+ #
569
+ # Output:
570
+ #
571
+ # I, [2022-05-13T13:16:29.637488 #8492] INFO -- mung: "hello \n ''"
572
+ # I, [2022-05-13T13:16:29.637610 #8492] INFO -- mung: "\f\x00\xFF\\\""
432
573
  #
433
574
  def formatter=: (_Formatter) -> _Formatter
434
575
  | (nil) -> nil
435
576
 
436
577
  # <!--
437
578
  # rdoc-file=lib/logger.rb
438
- # - info(message)
439
- # - info(progname, &block)
579
+ # - info(progname = nil, &block)
440
580
  # -->
441
- # Log an `INFO` message.
442
- #
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
- #
454
- #
455
- # ### Examples
456
- #
457
- # logger.info("MainApp") { "Received connection from #{ip}" }
458
- # # ...
459
- # logger.info "Waiting for input from user"
460
- # # ...
461
- # logger.info { "User typed #{input}" }
462
- #
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).
465
- #
466
- # ### Return
467
- #
468
- # See #add.
581
+ # Equivalent to calling #add with severity `Logger::INFO`.
469
582
  #
470
583
  def info: (?untyped progname) ?{ () -> untyped } -> true
471
584
 
@@ -473,7 +586,8 @@ class Logger
473
586
  # rdoc-file=lib/logger.rb
474
587
  # - info!()
475
588
  # -->
476
- # Sets the severity to INFO.
589
+ # Sets the log level to Logger::INFO. See [Log
590
+ # Level](rdoc-ref:Logger@Log+Level).
477
591
  #
478
592
  def info!: () -> Integer
479
593
 
@@ -481,12 +595,15 @@ class Logger
481
595
  # rdoc-file=lib/logger.rb
482
596
  # - info?()
483
597
  # -->
484
- # Returns `true` if and only if the current severity level allows for the
485
- # printing of `INFO` messages.
598
+ # Returns `true` if the log level allows entries with severity Logger::INFO to
599
+ # be written, `false` otherwise. See [Log Level](rdoc-ref:Logger@Log+Level).
486
600
  #
487
601
  def info?: () -> bool
488
602
 
489
- # <!-- rdoc-file=lib/logger.rb -->
603
+ # <!--
604
+ # rdoc-file=lib/logger.rb
605
+ # - level()
606
+ # -->
490
607
  # Logging severity threshold (e.g. `Logger::INFO`).
491
608
  #
492
609
  def level: () -> Integer
@@ -495,12 +612,19 @@ class Logger
495
612
  # rdoc-file=lib/logger.rb
496
613
  # - level=(severity)
497
614
  # -->
498
- # Set logging severity threshold.
615
+ # Sets the log level; returns `severity`. See [Log
616
+ # Level](rdoc-ref:Logger@Log+Level).
617
+ #
618
+ # Argument `severity` may be an integer, a string, or a symbol:
499
619
  #
500
- # `severity`
501
- # : The Severity of the log message.
620
+ # logger.level = Logger::ERROR # => 3
621
+ # logger.level = 3 # => 3
622
+ # logger.level = 'error' # => "error"
623
+ # logger.level = :error # => :error
502
624
  #
503
- def level=: (Integer | String | Symbol severity) -> Integer
625
+ # Logger#sev_threshold= is an alias for Logger#level=.
626
+ #
627
+ def level=: (Integer | interned severity) -> Integer
504
628
 
505
629
  # <!--
506
630
  # rdoc-file=lib/logger.rb
@@ -521,26 +645,37 @@ class Logger
521
645
 
522
646
  # <!--
523
647
  # rdoc-file=lib/logger.rb
524
- # - Logger#reopen
525
- # - Logger#reopen(logdev)
648
+ # - reopen(logdev = nil)
526
649
  # -->
527
- # ### Args
528
- #
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`.
533
- #
534
- #
535
- # ### Description
536
- #
537
- # Reopen a log device.
650
+ # Sets the logger's output stream:
651
+ #
652
+ # * If `logdev` is `nil`, reopens the current output stream.
653
+ # * If `logdev` is a filepath, opens the indicated file for append.
654
+ # * If `logdev` is an IO stream (usually `$stdout`, `$stderr`, or an open File
655
+ # object), opens the stream for append.
656
+ #
657
+ # Example:
658
+ #
659
+ # logger = Logger.new('t.log')
660
+ # logger.add(Logger::ERROR, 'one')
661
+ # logger.close
662
+ # logger.add(Logger::ERROR, 'two') # Prints 'log writing failed. closed stream'
663
+ # logger.reopen
664
+ # logger.add(Logger::ERROR, 'three')
665
+ # logger.close
666
+ # File.readlines('t.log')
667
+ # # =>
668
+ # # ["# Logfile created on 2022-05-12 14:21:19 -0500 by logger.rb/v1.5.0\n",
669
+ # # "E, [2022-05-12T14:21:27.596726 #22428] ERROR -- : one\n",
670
+ # # "E, [2022-05-12T14:23:05.847241 #22428] ERROR -- : three\n"]
538
671
  #
539
672
  def reopen: () -> self
540
673
  | (logdev?) -> self
541
674
 
542
- # <!-- rdoc-file=lib/logger.rb -->
543
- # Logging severity threshold (e.g. `Logger::INFO`).
675
+ # <!--
676
+ # rdoc-file=lib/logger.rb
677
+ # - sev_threshold()
678
+ # -->
544
679
  #
545
680
  alias sev_threshold level
546
681
 
@@ -555,10 +690,7 @@ class Logger
555
690
  # rdoc-file=lib/logger.rb
556
691
  # - unknown(progname = nil, &block)
557
692
  # -->
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.
693
+ # Equivalent to calling #add with severity `Logger::UNKNOWN`.
562
694
  #
563
695
  def unknown: (?untyped progname) ?{ () -> untyped } -> true
564
696
 
@@ -566,9 +698,7 @@ class Logger
566
698
  # rdoc-file=lib/logger.rb
567
699
  # - warn(progname = nil, &block)
568
700
  # -->
569
- # Log a `WARN` message.
570
- #
571
- # See #info for more information.
701
+ # Equivalent to calling #add with severity `Logger::WARN`.
572
702
  #
573
703
  def warn: (?untyped progname) ?{ () -> untyped } -> true
574
704
 
@@ -576,7 +706,8 @@ class Logger
576
706
  # rdoc-file=lib/logger.rb
577
707
  # - warn!()
578
708
  # -->
579
- # Sets the severity to WARN.
709
+ # Sets the log level to Logger::WARN. See [Log
710
+ # Level](rdoc-ref:Logger@Log+Level).
580
711
  #
581
712
  def warn!: () -> Integer
582
713
 
@@ -584,8 +715,8 @@ class Logger
584
715
  # rdoc-file=lib/logger.rb
585
716
  # - warn?()
586
717
  # -->
587
- # Returns `true` if and only if the current severity level allows for the
588
- # printing of `WARN` messages.
718
+ # Returns `true` if the log level allows entries with severity Logger::WARN to
719
+ # be written, `false` otherwise. See [Log Level](rdoc-ref:Logger@Log+Level).
589
720
  #
590
721
  def warn?: () -> bool
591
722
 
@@ -607,46 +738,52 @@ class Logger
607
738
 
608
739
  # <!--
609
740
  # 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')
741
+ # - Logger.new(logdev, shift_age = 0, shift_size = 1048576, **options)
616
742
  # -->
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.
648
- #
649
- 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
743
+ # With the single argument `logdev`, returns a new logger with all default
744
+ # options:
745
+ #
746
+ # Logger.new('t.log') # => #<Logger:0x000001e685dc6ac8>
747
+ #
748
+ # Argument `logdev` must be one of:
749
+ #
750
+ # * A string filepath: entries are to be written to the file at that path; if
751
+ # the file at that path exists, new entries are appended.
752
+ # * An IO stream (typically +$stdout+, +$stderr+. or an open file): entries
753
+ # are to be written to the given stream.
754
+ # * `nil` or `File::NULL`: no entries are to be written.
755
+ #
756
+ # Examples:
757
+ #
758
+ # Logger.new('t.log')
759
+ # Logger.new($stdout)
760
+ #
761
+ # The keyword options are:
762
+ #
763
+ # * `level`: sets the log level; default value is Logger::DEBUG. See [Log
764
+ # Level](rdoc-ref:Logger@Log+Level):
765
+ #
766
+ # Logger.new('t.log', level: Logger::ERROR)
767
+ #
768
+ # * `progname`: sets the default program name; default is `nil`. See [Program
769
+ # Name](rdoc-ref:Logger@Program+Name):
770
+ #
771
+ # Logger.new('t.log', progname: 'mung')
772
+ #
773
+ # * `formatter`: sets the entry formatter; default is `nil`. See
774
+ # [formatter=](Logger.html#attribute-i-formatter).
775
+ # * `datetime_format`: sets the format for entry timestamp; default is `nil`.
776
+ # See #datetime_format=.
777
+ # * `binmode`: sets whether the logger writes in binary mode; default is
778
+ # `false`.
779
+ # * `shift_period_suffix`: sets the format for the filename suffix for
780
+ # periodic log file rotation; default is `'%Y%m%d'`. See [Periodic
781
+ # Rotation](rdoc-ref:Logger@Periodic+Rotation).
782
+ # * `reraise_write_errors`: An array of exception classes, which will be
783
+ # reraised if there is an error when writing to the log device. The default
784
+ # is to swallow all exceptions raised.
785
+ #
786
+ 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 | interned) -> void
650
787
  end
651
788
 
652
789
  Logger::ProgName: String