sinlog 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/License +1 -1
- data/docs/Readme-zh.md +114 -100
- data/docs/Readme.md +139 -111
- data/lib/{init.rb → sinlog/init.rb} +26 -10
- data/lib/sinlog/log_ext.rb +74 -0
- data/lib/sinlog/log_short_ext.rb +81 -0
- data/lib/sinlog/loggable.rb +57 -0
- data/lib/sinlog/version.rb +1 -1
- data/lib/sinlog.rb +40 -9
- data/rbi/sinlog/init.rbi +34 -0
- data/rbi/sinlog/log_ext.rbi +37 -0
- data/rbi/sinlog/log_short_ext.rbi +37 -0
- data/rbi/sinlog/loggable.rbi +25 -0
- data/rbi/sinlog/version.rbi +3 -0
- metadata +13 -7
- data/lib/lambda.rb +0 -184
data/lib/sinlog.rb
CHANGED
|
@@ -1,18 +1,49 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# == Logging Modules Overview
|
|
4
4
|
#
|
|
5
|
-
#
|
|
5
|
+
# The following modules provide different ways to add logging capabilities:
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
7
|
+
# * Loggable : A mixin module. Include it in your class to add logging methods with the `log_` prefix.
|
|
8
|
+
# * LogExt : A refinement. Activate it with `using` to add logging methods with the `log_` prefix.
|
|
9
|
+
# * LogShortExt : A refinement. Similar to LogExt, but methods omit the `log_` prefix.
|
|
10
|
+
#
|
|
11
|
+
# === Comparison Table
|
|
12
|
+
#
|
|
13
|
+
# Module | Type | Activation | Method Naming
|
|
14
|
+
# -------------- | ---------- | ------------ | -------------------------
|
|
15
|
+
# Loggable | Mixin | include | log_dbg, log_info, etc.
|
|
16
|
+
# LogExt | Refinement | using | log_dbg, log_info, etc.
|
|
17
|
+
# LogShortExt | Refinement | using | dbg, info, warn, err, fatal, unk
|
|
18
|
+
#
|
|
19
|
+
# == Examples
|
|
20
|
+
#
|
|
21
|
+
# === Classic (neither mixin nor refinement)
|
|
22
|
+
#
|
|
23
|
+
# require 'sinlog'
|
|
24
|
+
#
|
|
25
|
+
# log = Sinlog.logger
|
|
26
|
+
# log.info "Information"
|
|
27
|
+
# log.debug "This is a debug message"
|
|
28
|
+
#
|
|
29
|
+
# === Mixin
|
|
30
|
+
#
|
|
31
|
+
# require 'sinlog'
|
|
32
|
+
# include Sinlog::Loggable
|
|
33
|
+
# "Hello".log_info
|
|
34
|
+
#
|
|
35
|
+
# === Refinement
|
|
36
|
+
#
|
|
37
|
+
# require 'sinlog'
|
|
38
|
+
# using Sinlog::LogShortExt
|
|
39
|
+
# "Hello".info
|
|
10
40
|
#
|
|
11
41
|
# Read more: https://github.com/2moe/sinlog-gem
|
|
42
|
+
class Sinlog; end
|
|
12
43
|
|
|
13
44
|
require_relative 'sinlog/version'
|
|
14
|
-
require 'singleton'
|
|
15
|
-
require 'logger'
|
|
16
45
|
|
|
17
|
-
require_relative 'init'
|
|
18
|
-
require_relative '
|
|
46
|
+
require_relative 'sinlog/init'
|
|
47
|
+
require_relative 'sinlog/loggable'
|
|
48
|
+
require_relative 'sinlog/log_ext'
|
|
49
|
+
require_relative 'sinlog/log_short_ext'
|
data/rbi/sinlog/init.rbi
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# rubocop:disable Style/FrozenStringLiteralComment
|
|
2
|
+
# rubocop:disable Style/Documentation
|
|
3
|
+
# typed: true
|
|
4
|
+
|
|
5
|
+
class Sinlog
|
|
6
|
+
include ::Singleton::SingletonInstanceMethods
|
|
7
|
+
include ::Singleton
|
|
8
|
+
extend ::Singleton::SingletonClassMethods
|
|
9
|
+
|
|
10
|
+
sig { params(level: Integer).returns(Logger) }
|
|
11
|
+
def self.logger_with_level(level = LV[:warn]); end
|
|
12
|
+
|
|
13
|
+
sig { returns(Logger) }
|
|
14
|
+
def self.logger; end
|
|
15
|
+
|
|
16
|
+
sig { returns(Logger) }
|
|
17
|
+
def logger; end
|
|
18
|
+
|
|
19
|
+
sig { params(env_name: String).returns(NilClass) }
|
|
20
|
+
def set_level_from_env!(env_name = ''); end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
sig { params(progname: T.any(String, Symbol)).returns(String) }
|
|
25
|
+
def format_prog_name(progname); end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Sinlog::COLORS = T.let(T.unsafe(nil), T::Hash[Symbol, String])
|
|
29
|
+
|
|
30
|
+
Sinlog::LV = T.let(T.unsafe(nil), T::Hash[Symbol, Integer])
|
|
31
|
+
|
|
32
|
+
# ---------
|
|
33
|
+
# LambdaExt
|
|
34
|
+
# LoggerFn = T.type_alias { T.proc.params(msg: T.untyped).void }
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# rubocop:disable Style/FrozenStringLiteralComment
|
|
2
|
+
# rubocop:disable Style/Documentation
|
|
3
|
+
# typed: true
|
|
4
|
+
|
|
5
|
+
class Sinlog
|
|
6
|
+
module LogExt
|
|
7
|
+
refine Object do
|
|
8
|
+
sig { void }
|
|
9
|
+
def log_dbg; end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
refine Object do
|
|
13
|
+
sig { void }
|
|
14
|
+
def log_info; end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
refine Object do
|
|
18
|
+
sig { void }
|
|
19
|
+
def log_warn; end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
refine Object do
|
|
23
|
+
sig { void }
|
|
24
|
+
def log_err; end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
refine Object do
|
|
28
|
+
sig { void }
|
|
29
|
+
def log_fatal; end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
refine Object do
|
|
33
|
+
sig { void }
|
|
34
|
+
def log_unk; end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# rubocop:disable Style/FrozenStringLiteralComment
|
|
2
|
+
# rubocop:disable Style/Documentation
|
|
3
|
+
# typed: true
|
|
4
|
+
|
|
5
|
+
class Sinlog
|
|
6
|
+
module LogExt
|
|
7
|
+
refine Object do
|
|
8
|
+
sig { void }
|
|
9
|
+
def dbg; end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
refine Object do
|
|
13
|
+
sig { void }
|
|
14
|
+
def info; end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
refine Object do
|
|
18
|
+
sig { void }
|
|
19
|
+
def warn; end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
refine Object do
|
|
23
|
+
sig { void }
|
|
24
|
+
def err; end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
refine Object do
|
|
28
|
+
sig { void }
|
|
29
|
+
def fatal; end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
refine Object do
|
|
33
|
+
sig { void }
|
|
34
|
+
def unk; end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# rubocop:disable Style/FrozenStringLiteralComment
|
|
2
|
+
# rubocop:disable Style/Documentation
|
|
3
|
+
# typed: true
|
|
4
|
+
|
|
5
|
+
class Sinlog
|
|
6
|
+
module Loggleable
|
|
7
|
+
sig { void }
|
|
8
|
+
def log_dbg; end
|
|
9
|
+
|
|
10
|
+
sig { void }
|
|
11
|
+
def log_info; end
|
|
12
|
+
|
|
13
|
+
sig { void }
|
|
14
|
+
def log_warn; end
|
|
15
|
+
|
|
16
|
+
sig { void }
|
|
17
|
+
def log_err; end
|
|
18
|
+
|
|
19
|
+
sig { void }
|
|
20
|
+
def log_fatal; end
|
|
21
|
+
|
|
22
|
+
sig { void }
|
|
23
|
+
def log_unk; end
|
|
24
|
+
end
|
|
25
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sinlog
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- 2moe
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: A very, very simple singleton logger with colored log levels.
|
|
13
13
|
executables: []
|
|
@@ -17,16 +17,22 @@ files:
|
|
|
17
17
|
- License
|
|
18
18
|
- docs/Readme-zh.md
|
|
19
19
|
- docs/Readme.md
|
|
20
|
-
- lib/init.rb
|
|
21
|
-
- lib/lambda.rb
|
|
22
20
|
- lib/sinlog.rb
|
|
21
|
+
- lib/sinlog/init.rb
|
|
22
|
+
- lib/sinlog/log_ext.rb
|
|
23
|
+
- lib/sinlog/log_short_ext.rb
|
|
24
|
+
- lib/sinlog/loggable.rb
|
|
23
25
|
- lib/sinlog/version.rb
|
|
26
|
+
- rbi/sinlog/init.rbi
|
|
27
|
+
- rbi/sinlog/log_ext.rbi
|
|
28
|
+
- rbi/sinlog/log_short_ext.rbi
|
|
29
|
+
- rbi/sinlog/loggable.rbi
|
|
30
|
+
- rbi/sinlog/version.rbi
|
|
24
31
|
homepage: https://github.com/2moe/sinlog-gem
|
|
25
32
|
licenses:
|
|
26
33
|
- MIT
|
|
27
34
|
metadata:
|
|
28
35
|
homepage_uri: https://github.com/2moe/sinlog-gem
|
|
29
|
-
source_code_uri: https://github.com/2moe/sinlog-gem
|
|
30
36
|
rdoc_options: []
|
|
31
37
|
require_paths:
|
|
32
38
|
- lib
|
|
@@ -34,14 +40,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
34
40
|
requirements:
|
|
35
41
|
- - ">="
|
|
36
42
|
- !ruby/object:Gem::Version
|
|
37
|
-
version: 3.
|
|
43
|
+
version: 3.1.0
|
|
38
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
45
|
requirements:
|
|
40
46
|
- - ">="
|
|
41
47
|
- !ruby/object:Gem::Version
|
|
42
48
|
version: '0'
|
|
43
49
|
requirements: []
|
|
44
|
-
rubygems_version: 3.
|
|
50
|
+
rubygems_version: 3.7.2
|
|
45
51
|
specification_version: 4
|
|
46
52
|
summary: colorful singleton logger
|
|
47
53
|
test_files: []
|
data/lib/lambda.rb
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# rubocop:disable Lint/MissingCopEnableDirective, Style/ClassVars
|
|
4
|
-
|
|
5
|
-
class Sinlog
|
|
6
|
-
# Module to simplify logger calls using lambda expressions.
|
|
7
|
-
#
|
|
8
|
-
# The following methods define lambda expressions for different log levels.
|
|
9
|
-
# These lambdas can be used to log messages at the corresponding log level.
|
|
10
|
-
module LogLambdaExt
|
|
11
|
-
@@_sinlog_lambda_ext_logger_ = Sinlog.instance.logger
|
|
12
|
-
|
|
13
|
-
# Debug Logging
|
|
14
|
-
#
|
|
15
|
-
# Example:
|
|
16
|
-
#
|
|
17
|
-
# require 'sinlog'
|
|
18
|
-
# include Sinlog::LogLambdaExt
|
|
19
|
-
#
|
|
20
|
-
# 'Debug Message'.then(&log_dbg)
|
|
21
|
-
#
|
|
22
|
-
# cmd = %w[ls -l -h]
|
|
23
|
-
# "cmd_arr: #{cmd}".tap(&log_dbg)
|
|
24
|
-
def log_dbg
|
|
25
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.debug(msg) }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Info(a.k.a. Information) Logging
|
|
29
|
-
#
|
|
30
|
-
# Example:
|
|
31
|
-
#
|
|
32
|
-
# require 'pathname'
|
|
33
|
-
#
|
|
34
|
-
# Pathname('lib/lambda.rb').tap {
|
|
35
|
-
# "Filename: #{it}".then(&log_info)
|
|
36
|
-
# "size: #{it.size}".then(&log_info)
|
|
37
|
-
# }
|
|
38
|
-
def log_info
|
|
39
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.info(msg) }
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Warning Logging
|
|
43
|
-
#
|
|
44
|
-
# Example:
|
|
45
|
-
#
|
|
46
|
-
# arr = (0..256).to_a
|
|
47
|
-
# 'This array is too large'.then(&log_warn) if arr.length > 128
|
|
48
|
-
def log_warn
|
|
49
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.warn(msg) }
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# Warning Logging
|
|
53
|
-
#
|
|
54
|
-
# Same as `log_warn`
|
|
55
|
-
def log_warning
|
|
56
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.warn(msg) }
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# Warning Logging
|
|
60
|
-
#
|
|
61
|
-
# Same as `log_warn`
|
|
62
|
-
def log_wng
|
|
63
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.warn(msg) }
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Error Logging
|
|
67
|
-
#
|
|
68
|
-
# Example:
|
|
69
|
-
#
|
|
70
|
-
# 'CLI error: You should pass the --url'.then(&log_err)
|
|
71
|
-
def log_err
|
|
72
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.error(msg) }
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Fatal error logging
|
|
76
|
-
#
|
|
77
|
-
# Example:
|
|
78
|
-
#
|
|
79
|
-
# 'Failed to open xxx'.then(&log_fatal)
|
|
80
|
-
def log_fatal
|
|
81
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.fatal(msg) }
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# Example:
|
|
85
|
-
#
|
|
86
|
-
# 'Unknown'.then(&log_unk)
|
|
87
|
-
def log_unk
|
|
88
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.unknown(msg) }
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# Similar to LogLambdaExt, but the lambda functions do not have the `log_` prefix.
|
|
93
|
-
# One important thing to note is that LambdaExt defines the `warning` function, not `warn`.
|
|
94
|
-
#
|
|
95
|
-
# The following methods define lambda expressions for different log levels.
|
|
96
|
-
# These lambdas can be used to log messages at the corresponding log level.
|
|
97
|
-
module LambdaExt
|
|
98
|
-
@@_sinlog_lambda_ext_logger_ = Sinlog.instance.logger
|
|
99
|
-
|
|
100
|
-
# Debug Logging
|
|
101
|
-
#
|
|
102
|
-
# Example:
|
|
103
|
-
#
|
|
104
|
-
# require 'sinlog'
|
|
105
|
-
# include Sinlog::LambdaExt
|
|
106
|
-
#
|
|
107
|
-
# 'Debug Message'.then(&dbg)
|
|
108
|
-
#
|
|
109
|
-
# cmd = %w[ls -l -h]
|
|
110
|
-
# "cmd_arr: #{cmd}".tap(&dbg)
|
|
111
|
-
def dbg
|
|
112
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.debug(msg) }
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# Info(a.k.a. Information) Logging
|
|
116
|
-
#
|
|
117
|
-
# Example:
|
|
118
|
-
#
|
|
119
|
-
# require 'pathname'
|
|
120
|
-
#
|
|
121
|
-
# Pathname('lib/lambda.rb').tap {
|
|
122
|
-
# "Filename: #{it}".then(&info)
|
|
123
|
-
# "size: #{it.size}".then(&info)
|
|
124
|
-
# }
|
|
125
|
-
def info
|
|
126
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.info(msg) }
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
# Warning Logging
|
|
130
|
-
#
|
|
131
|
-
# Example:
|
|
132
|
-
#
|
|
133
|
-
# arr = (0..1024).to_a
|
|
134
|
-
# 'This array is too large'.then(&warning) if arr.length > 128
|
|
135
|
-
def warning
|
|
136
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.warn(msg) }
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
# Warning Logging
|
|
140
|
-
#
|
|
141
|
-
# Same as `warning`
|
|
142
|
-
def wng
|
|
143
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.warn(msg) }
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
# Error Logging
|
|
147
|
-
#
|
|
148
|
-
# Example:
|
|
149
|
-
#
|
|
150
|
-
# 'CLI error: You should pass the --url'.then(&err)
|
|
151
|
-
def err
|
|
152
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.error(msg) }
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
# Fatal error logging
|
|
156
|
-
#
|
|
157
|
-
# Example:
|
|
158
|
-
#
|
|
159
|
-
# 'Failed to open xxx'.then(&fatal)
|
|
160
|
-
def fatal
|
|
161
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.fatal(msg) }
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
# Unknown(log-level) logging
|
|
165
|
-
#
|
|
166
|
-
# Example:
|
|
167
|
-
#
|
|
168
|
-
# 'Unknown'.then(&unk)
|
|
169
|
-
def unk
|
|
170
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.unknown(msg) }
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
# Defines the `warn` lambda expression
|
|
175
|
-
module LambdaWarnExt
|
|
176
|
-
@@_sinlog_lambda_ext_logger_ = Sinlog.instance.logger
|
|
177
|
-
# Warning Logging
|
|
178
|
-
#
|
|
179
|
-
# Same as `LambdaExt.warning`
|
|
180
|
-
def warn
|
|
181
|
-
->(msg) { @@_sinlog_lambda_ext_logger_.warn(msg) }
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
end
|