loggerx 0.3.0 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3d670b6073866d77bce705fbfee4766ec35a56efa25915c1640bacc6752ef76
4
- data.tar.gz: 1ccd5529fb4a87b383e500cad777d7c58441b803343753ea93c43f34c940e42d
3
+ metadata.gz: b94fc11a31ed8efbf76e939a7765325fc226339bdea71edb61c026a16f2dad67
4
+ data.tar.gz: 48b1a9cca11d4610bdfc1146d5a83076827e8be5b045e3d9c7501b39608734e9
5
5
  SHA512:
6
- metadata.gz: 1727d5e45c7910f3fe631b52329d0fadcb6e9d05eed54ed1731552dcf46c3ba257ade18e53bb51ae9a9bbf5477f69fe16bbff6067e0f495412b1b42c289516d4
7
- data.tar.gz: 7fe553f310c18547b0274e6f45f2a06b8bedd69df01c2eb06700c62e7fa2434312b2f5dfee9a2f76df3600670fd1f0956a829aba4905b264d7e31700f5bf5b30
6
+ metadata.gz: 73b6239ea4cbc60897f3017a7ed10b56d2a1de0abbb9aa5a21ef58d5217a88dda7444253d7c4e6b472f96d6e5b3064e41addb76eeb6f3d3d669623373714cefa
7
+ data.tar.gz: 73d856baf3ab5a92e6415bac098bba6915aaf6a789ea136c5d4a11e015cb0f5337baf70d3ce231903f11f8b1e8cbd4845c530f989c931d0afa0ea3f887c59775
data/.rubocop.yml CHANGED
@@ -8,29 +8,80 @@ AllCops:
8
8
  NewCops: enable
9
9
  TargetRubyVersion: 3.1
10
10
 
11
- Style/StringLiterals:
12
- Enabled: true
13
- EnforcedStyle: double_quotes
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/LineLength:
20
- Max: 120
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
- Style/FrozenStringLiteralComment:
24
- Enabled: false
25
-
26
- Style/Documentation:
27
- Enabled: false
28
- Style/ClassAndModuleChildren:
29
- Enabled: false
30
- Style/GuardClause:
31
- Enabled: false
32
- Style/IfUnlessModifier:
33
- Enabled: false
34
-
35
- Metrics/ClassLength:
36
- Enabled: false
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/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.1.2
1
+ ruby 3.3.4
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
@@ -2,15 +2,15 @@
2
2
 
3
3
  module Loggerx
4
4
  class Loggerx
5
- require "logger"
6
- require "fileutils"
7
- require "stringio"
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(+"", "w+")
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
- level = level_hs[level]
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(+"", "w+")
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["prefix"]
192
- log_dir_pn = Pathname.new(hash["log_dir"])
184
+ prefix = hash['prefix']
185
+ log_dir_pn = Pathname.new(hash['log_dir'])
193
186
 
194
- stdout_flag_str = hash["stdout_flag"]
187
+ stdout_flag_str = hash['stdout_flag']
195
188
  stdout_flag = if stdout_flag_str.instance_of?(String)
196
- case stdout_flag_str
197
- when "true"
198
- true
199
- else
200
- false
201
- end
202
- else
203
- stdout_flag_str
204
- end
205
-
206
- fname_str = hash["fname"]
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
- when "default"
209
- fname_str.to_sym
210
- when "false"
211
- false
212
- else
213
- fname_str
214
- end
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["level"].to_sym
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)
@@ -1,19 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "pathname"
3
+ require 'pathname'
4
4
 
5
5
  module Loggerx
6
+ # The `Loggerx::Loggerxcm0` class is designed to provide logging functionality specific to the Mkspec framework.
7
+ # It encapsulates the logging mechanism, offering a unified interface for recording various levels of messages,
8
+ # such as debug, info, warning, and error. This class aims to facilitate debugging and tracking of the application's
9
+ # flow by providing detailed and structured log messages. It can be configured to log messages to different outputs,
10
+ # including standard output, files, or external logging services, depending on the needs of the framework.
11
+ #
12
+ # @example Logging a debug message
13
+ # Loggerx::Loggerxcm0.debug("This is a debug message")
14
+ #
15
+ # @example Logging an error message
16
+ # Loggerx::Loggerxcm0.error("This is an error message")
17
+ #
18
+ # This class may also support log rotation, filtering of log messages based on severity, and formatting of log messages
19
+ # to include timestamps, source identifiers, and other relevant information.
6
20
  class Loggerxcm0
7
- require "logger"
8
- require "fileutils"
9
- require "stringio"
21
+ # Implementation omitted
22
+ require 'logger'
23
+ require 'fileutils'
24
+ require 'stringio'
10
25
 
11
- LOG_FILENAME_BASE = "#{Time.now.strftime("%Y%m%d-%H%M%S")}.log".freeze
26
+ LOG_FILENAME_BASE = "#{Time.now.strftime('%Y%m%d-%H%M%S')}.log".freeze
12
27
  @log_file = nil
13
28
  @log_stdout = nil
14
29
  @stdout_backup = $stdout
15
- @stringio = StringIO.new(+"", "w+")
16
- # @limit_of_num_of_files ||= 3
30
+ @stringio = StringIO.new(+"", 'w+')
31
+
32
+ @valid = false
17
33
 
18
34
  class << self
19
35
  def ensure_quantum_log_files(log_dir_pn, limit_of_num_of_files, prefix)
@@ -32,7 +48,7 @@ module Loggerx
32
48
  warn: Logger::WARN,
33
49
  error: Logger::ERROR,
34
50
  fatal: Logger::FATAL,
35
- unknown: Logger::UNKNOWN,
51
+ unknown: Logger::UNKNOWN
36
52
  }
37
53
  @log_dir_pn = Pathname.new(log_dir)
38
54
 
@@ -51,10 +67,15 @@ module Loggerx
51
67
  end
52
68
  register_log_format(obj)
53
69
  register_log_level(level_hs[level])
54
- end
55
70
 
56
- def valid?
57
- !@log_file.nil?
71
+ @valid = true
72
+
73
+ Loggerxcm.fatal("fatal")
74
+ Loggerxcm.debug("debug")
75
+ Loggerxcm.info("info")
76
+ Loggerxcm.warn("warn")
77
+ Loggerxcm.error("error")
78
+ # Loggerxcm.unknown("unknown")
58
79
  end
59
80
 
60
81
  def setup_logger_stdout(log_stdout)
@@ -62,7 +83,8 @@ module Loggerx
62
83
 
63
84
  begin
64
85
  log_stdout = Logger.new($stdout)
65
- rescue StandardError
86
+ rescue StandardError => exc
87
+ pust exc.message
66
88
  @error_count += 1
67
89
  end
68
90
  log_stdout
@@ -72,10 +94,11 @@ module Loggerx
72
94
  filepath = Pathname.new(log_dir).join(fname)
73
95
  if log_file.nil?
74
96
  begin
75
- log_file = Logger.new(filepath)
97
+ log_file = Logger.new(filepath.to_s)
76
98
  rescue Errno::EACCES
77
99
  @error_count += 1
78
- rescue StandardError
100
+ rescue StandardError => exc
101
+ puts exc
79
102
  @error_count += 1
80
103
  end
81
104
  end
@@ -88,6 +111,7 @@ module Loggerx
88
111
  end
89
112
 
90
113
  def register_log_level(level)
114
+ puts "============ Loggerxcm.register_log_level level=#{level} ==========="
91
115
  @log_file&.level = level
92
116
  @log_stdout&.level = level
93
117
  #
@@ -98,12 +122,12 @@ module Loggerx
98
122
  def to_string(value)
99
123
  if value.instance_of?(Array)
100
124
  @stdout_backup ||= $stdout
101
- @stringio ||= StringIO.new(+"", "w+")
125
+ @stringio ||= StringIO.new(+"", 'w+')
102
126
  $stdout = @stringio
103
- $stdout = @stdout_backup
104
127
  @stringio.rewind
105
128
  str = @stringio.read
106
129
  @stringio.truncate(0)
130
+ $stdout = @stdout_backup
107
131
  str
108
132
  else
109
133
  value
@@ -111,17 +135,27 @@ module Loggerx
111
135
  end
112
136
 
113
137
  def show(value)
114
- puts(value)
115
- str = error_sub(value)
116
- # puts(str) unless @log_stdout
117
- puts(str) # unless @log_stdout
138
+ if @valid
139
+ if value.instance_of?(Array)
140
+ value.map do |v|
141
+ str = v.to_s
142
+ Util.puts_valid_str(str)
143
+ end
144
+ else
145
+ Util.puts_valid_str(str)
146
+ end
147
+ str = error_sub(value)
148
+ Util.puts_valid_str(str)
149
+ end
118
150
  true
119
151
  end
120
152
 
121
153
  def error_sub(value)
122
154
  str = to_string(value)
123
- @log_file&.error(str)
124
- @log_stdout&.error(str)
155
+ if @valid
156
+ @log_file&.error(str)
157
+ @log_stdout&.error(str)
158
+ end
125
159
  str
126
160
  end
127
161
 
@@ -132,34 +166,49 @@ module Loggerx
132
166
 
133
167
  def debug(value)
134
168
  str = to_string(value)
135
- @log_file&.debug(str)
136
- @log_stdout&.debug(str)
169
+ if @valid
170
+ @log_file&.debug(str)
171
+ @log_stdout&.debug(str)
172
+ end
173
+
137
174
  true
138
175
  end
139
176
 
140
177
  def info(value)
141
178
  str = to_string(value)
142
- @log_file&.info(str)
143
- @log_stdout&.info(str)
179
+ if @valid
180
+ @log_file&.info(str)
181
+ @log_stdout&.info(str)
182
+ end
144
183
  true
145
184
  end
146
185
 
147
186
  def warn(value)
148
187
  str = to_string(value)
149
- @log_file&.warn(str)
150
- @log_stdout&.warn(str)
188
+ if @valid
189
+ @log_file&.warn(str)
190
+ @log_stdout&.warn(str)
191
+ end
151
192
  true
152
193
  end
153
194
 
154
195
  def fatal(value)
155
196
  str = to_string(value)
156
- @log_file&.fatal(str)
157
- @log_stdout&.fatal(str)
197
+ if @valid
198
+ @log_file&.fatal(str)
199
+ @log_stdout&.fatal(str)
200
+ end
158
201
  true
159
202
  end
160
203
 
161
204
  def close
205
+ retrun unless @valid
206
+
162
207
  @log_file&.close
208
+ @log_file = nil
209
+ @log_stdout = nil
210
+
211
+ @valid = false
163
212
  # @log_stdout&.close
164
213
  end
165
214
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Loggerx
4
- VERSION = "0.3.0"
4
+ VERSION = '0.3.2'
5
5
  end
data/lib/loggerx.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "loggerx/version"
4
- require_relative "loggerx/loggerx"
5
- require_relative "loggerx/loggerxcm"
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggerx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ykominami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-19 00:00:00.000000000 Z
11
+ date: 2024-12-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Utility class for Logging.
14
14
  email:
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  requirements: []
58
- rubygems_version: 3.5.14
58
+ rubygems_version: 3.5.11
59
59
  signing_key:
60
60
  specification_version: 4
61
61
  summary: Utility class for Logging.