loggerx 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +73 -22
- data/Rakefile +2 -2
- data/lib/loggerx/loggerx.rb +29 -36
- data/lib/loggerx/loggerxcm.rb +8 -8
- data/lib/loggerx/version.rb +1 -1
- data/lib/loggerx.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fd826254376e64dc953e21e9ba92bc7ae0fc1a9f53c293b19ed093616acce29
|
4
|
+
data.tar.gz: 81d5fcb3dc14a34df39d491a88604a163041548baffa1f9d829645d8f2f95f95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9af8636e84e6469b63737a4b884406a3288b94d1ed60538f170272ac558515cd867d1f05317ad4d720dd1a3b41d2f88d2534cf3c3ebc731c55d70f2ceee0886
|
7
|
+
data.tar.gz: c5f6b9998cde8d0cc122786b20a7287120e07a215ac3182c24e116efb04cad518018ee4b0fc49db50bd8253e6f20d9b5bbaef88175022fd04588fadc89991889
|
data/.rubocop.yml
CHANGED
@@ -8,29 +8,80 @@ AllCops:
|
|
8
8
|
NewCops: enable
|
9
9
|
TargetRubyVersion: 3.1
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
DisplayCopNames: true
|
12
|
+
StyleGuideBaseURL: https://github.com/fortissimo1997/ruby-style-guide/blob/japanese/README.ja.md
|
13
|
+
# 結果のsuggest部分を非表示にする
|
14
|
+
SuggestExtensions: false
|
15
|
+
# rubocopの対象外ファイル
|
16
|
+
Exclude:
|
17
|
+
- "Gemfile"
|
18
|
+
- "bin/**/*"
|
19
|
+
- "db/**/*"
|
20
|
+
- "log/**/*"
|
21
|
+
- "tmp/**/*"
|
22
|
+
- "vendor/**/*"
|
23
|
+
- "lib/tasks/auto_annotate_models.rake"
|
24
|
+
- "config/environments/*"
|
25
|
+
- "config/puma.rb"
|
26
|
+
- "root/**/*"
|
27
|
+
- "test_data/**/*"
|
28
|
+
- "test_data_y/**/*"
|
29
|
+
- "test_other/**/*"
|
30
|
+
- "test_output/**/*"
|
31
|
+
- "tmp/**/*"
|
32
|
+
- "pkg/**/*"
|
33
|
+
- "docs/**/*"
|
14
34
|
|
15
|
-
Style/StringLiteralsInInterpolation:
|
16
|
-
Enabled: true
|
17
|
-
EnforcedStyle: double_quotes
|
18
35
|
|
19
|
-
Layout
|
20
|
-
|
36
|
+
Layout:
|
37
|
+
# メソッド名をcamelCase に設定します
|
38
|
+
MethodName:
|
39
|
+
# EnforcedStyle: camelCase
|
40
|
+
EnforcedStyle: snake_case
|
41
|
+
# 一行に 120 文字まで書いても OK とする
|
42
|
+
LineLength:
|
43
|
+
Max: 120
|
21
44
|
|
45
|
+
Style:
|
46
|
+
StringLiterals:
|
47
|
+
Enabled: true
|
48
|
+
EnforcedStyle: double_quotes
|
49
|
+
|
50
|
+
StringLiteralsInInterpolation:
|
51
|
+
Enabled: true
|
52
|
+
EnforcedStyle: double_quotes
|
22
53
|
#追加
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
54
|
+
rozenStringLiteralComment:
|
55
|
+
Enabled: false
|
56
|
+
ClassAndModuleChildren:
|
57
|
+
Enabled: false
|
58
|
+
GuardClause:
|
59
|
+
Enabled: false
|
60
|
+
IfUnlessModifier:
|
61
|
+
Enabled: false
|
62
|
+
# 日本語のコメントを OK とする
|
63
|
+
AsciiComments:
|
64
|
+
Enabled: false
|
65
|
+
BlockComments:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
# class documentation commentのアラートを出さない
|
69
|
+
Documentation:
|
70
|
+
Enabled: false
|
71
|
+
IfWithBooleanLiteralBranches:
|
72
|
+
Enabled: false
|
73
|
+
|
74
|
+
Naming:
|
75
|
+
RescuedExceptionsVariableName:
|
76
|
+
PreferredName: exc
|
77
|
+
|
78
|
+
Lint:
|
79
|
+
DuplicateRegexpCharacterClassElement:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
|
83
|
+
Metrics:
|
84
|
+
ClassLength:
|
85
|
+
# Enabled: false
|
86
|
+
Max: 440 # クラスの最大行数をここで設定
|
87
|
+
|
data/Rakefile
CHANGED
data/lib/loggerx/loggerx.rb
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
module Loggerx
|
4
4
|
class Loggerx
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
5
|
+
require 'logger'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'stringio'
|
8
8
|
|
9
9
|
LOG_FILENAME_BASE = "#{Time.now.strftime("%Y%m%d-%H%M%S")}.log".freeze
|
10
10
|
@log_file = nil
|
11
11
|
@log_stdout = nil
|
12
12
|
@stdout_backup = $stdout
|
13
|
-
@stringio = StringIO.new(+
|
13
|
+
@stringio = StringIO.new(+'', 'w+')
|
14
14
|
|
15
15
|
attr_reader :error_count
|
16
16
|
|
@@ -38,14 +38,9 @@ module Loggerx
|
|
38
38
|
fname = nil if fname == false
|
39
39
|
fname = prefix + LOG_FILENAME_BASE if fname == :default
|
40
40
|
@log_file = setup_logger_file(log_dir, fname) if fname
|
41
|
-
|
42
|
-
obj = proc do |_, _, _, msg|
|
43
|
-
"#{msg}\n"
|
44
|
-
end
|
45
41
|
# register_log_format(obj)
|
46
|
-
formatter = obj
|
47
42
|
# register_log_level(level_hs[level])
|
48
|
-
|
43
|
+
level_hs[level]
|
49
44
|
end
|
50
45
|
|
51
46
|
def formatter
|
@@ -81,7 +76,6 @@ module Loggerx
|
|
81
76
|
|
82
77
|
def setup_logger_file(log_dir, fname)
|
83
78
|
filepath = Pathname.new(log_dir).join(fname)
|
84
|
-
log_file = nil
|
85
79
|
begin
|
86
80
|
log ||= ActiveSupport::TaggedLogging.new(filepath)
|
87
81
|
rescue Errno::EACCES
|
@@ -116,7 +110,7 @@ module Loggerx
|
|
116
110
|
def to_string(value)
|
117
111
|
if value.instance_of?(Array)
|
118
112
|
@stdout_backup ||= $stdout
|
119
|
-
@stringio ||= StringIO.new(+
|
113
|
+
@stringio ||= StringIO.new(+'', 'w+')
|
120
114
|
$stdout = @stringio
|
121
115
|
$stdout = @stdout_backup
|
122
116
|
@stringio.rewind
|
@@ -150,7 +144,6 @@ module Loggerx
|
|
150
144
|
|
151
145
|
def debug(value)
|
152
146
|
str = to_string(value)
|
153
|
-
# p str
|
154
147
|
@log_file&.debug(str)
|
155
148
|
@log_stdout&.debug(str)
|
156
149
|
true
|
@@ -188,39 +181,39 @@ module Loggerx
|
|
188
181
|
end
|
189
182
|
|
190
183
|
def hash_to_args(hash)
|
191
|
-
prefix = hash[
|
192
|
-
log_dir_pn = Pathname.new(hash[
|
184
|
+
prefix = hash['prefix']
|
185
|
+
log_dir_pn = Pathname.new(hash['log_dir'])
|
193
186
|
|
194
|
-
stdout_flag_str = hash[
|
187
|
+
stdout_flag_str = hash['stdout_flag']
|
195
188
|
stdout_flag = if stdout_flag_str.instance_of?(String)
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
fname_str = hash[
|
189
|
+
case stdout_flag_str
|
190
|
+
when 'true'
|
191
|
+
true
|
192
|
+
else
|
193
|
+
false
|
194
|
+
end
|
195
|
+
else
|
196
|
+
stdout_flag_str
|
197
|
+
end
|
198
|
+
|
199
|
+
fname_str = hash['fname']
|
207
200
|
fname = case fname_str
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
201
|
+
when 'default'
|
202
|
+
fname_str.to_sym
|
203
|
+
when 'false'
|
204
|
+
false
|
205
|
+
else
|
206
|
+
fname_str
|
207
|
+
end
|
215
208
|
|
216
|
-
level = hash[
|
209
|
+
level = hash['level'].to_sym
|
217
210
|
|
218
211
|
[prefix, fname, log_dir_pn, stdout_flag, level]
|
219
212
|
end
|
220
213
|
|
221
214
|
def create_by_hash(hash)
|
222
215
|
prefix, fname, log_dir_pn, stdout_flag, level = hash_to_args(hash)
|
223
|
-
new(prefix, fname, log_dir_pn, stdout_flag, level)
|
216
|
+
Loggerx.new(prefix, fname, log_dir_pn, stdout_flag, level)
|
224
217
|
end
|
225
218
|
|
226
219
|
def init_by_hash(hash)
|
data/lib/loggerx/loggerxcm.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'pathname'
|
4
4
|
|
5
5
|
module Loggerx
|
6
6
|
class Loggerxcm0
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
7
|
+
require 'logger'
|
8
|
+
require 'fileutils'
|
9
|
+
require 'stringio'
|
10
10
|
|
11
11
|
LOG_FILENAME_BASE = "#{Time.now.strftime("%Y%m%d-%H%M%S")}.log".freeze
|
12
12
|
@log_file = nil
|
13
13
|
@log_stdout = nil
|
14
14
|
@stdout_backup = $stdout
|
15
|
-
@stringio = StringIO.new(+
|
15
|
+
@stringio = StringIO.new(+'', 'w+')
|
16
16
|
# @limit_of_num_of_files ||= 3
|
17
17
|
|
18
18
|
class << self
|
@@ -73,8 +73,8 @@ module Loggerx
|
|
73
73
|
if log_file.nil?
|
74
74
|
begin
|
75
75
|
log_file = Logger.new(filepath)
|
76
|
-
rescue Errno::EACCES
|
77
|
-
|
76
|
+
# rescue Errno::EACCES
|
77
|
+
# @error_count += 1
|
78
78
|
rescue StandardError
|
79
79
|
@error_count += 1
|
80
80
|
end
|
@@ -98,7 +98,7 @@ module Loggerx
|
|
98
98
|
def to_string(value)
|
99
99
|
if value.instance_of?(Array)
|
100
100
|
@stdout_backup ||= $stdout
|
101
|
-
@stringio ||= StringIO.new(+
|
101
|
+
@stringio ||= StringIO.new(+'', 'w+')
|
102
102
|
$stdout = @stringio
|
103
103
|
$stdout = @stdout_backup
|
104
104
|
@stringio.rewind
|
data/lib/loggerx/version.rb
CHANGED
data/lib/loggerx.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
3
|
+
require_relative 'loggerx/version'
|
4
|
+
require_relative 'loggerx/loggerx'
|
5
|
+
require_relative 'loggerx/loggerxcm'
|
6
6
|
|
7
7
|
module Loggerx
|
8
8
|
class Error < StandardError; end
|