loggerx 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fd826254376e64dc953e21e9ba92bc7ae0fc1a9f53c293b19ed093616acce29
4
- data.tar.gz: 81d5fcb3dc14a34df39d491a88604a163041548baffa1f9d829645d8f2f95f95
3
+ metadata.gz: b94fc11a31ed8efbf76e939a7765325fc226339bdea71edb61c026a16f2dad67
4
+ data.tar.gz: 48b1a9cca11d4610bdfc1146d5a83076827e8be5b045e3d9c7501b39608734e9
5
5
  SHA512:
6
- metadata.gz: c9af8636e84e6469b63737a4b884406a3288b94d1ed60538f170272ac558515cd867d1f05317ad4d720dd1a3b41d2f88d2534cf3c3ebc731c55d70f2ceee0886
7
- data.tar.gz: c5f6b9998cde8d0cc122786b20a7287120e07a215ac3182c24e116efb04cad518018ee4b0fc49db50bd8253e6f20d9b5bbaef88175022fd04588fadc89991889
6
+ metadata.gz: 73b6239ea4cbc60897f3017a7ed10b56d2a1de0abbb9aa5a21ef58d5217a88dda7444253d7c4e6b472f96d6e5b3064e41addb76eeb6f3d3d669623373714cefa
7
+ data.tar.gz: 73d856baf3ab5a92e6415bac098bba6915aaf6a789ea136c5d4a11e015cb0f5337baf70d3ce231903f11f8b1e8cbd4845c530f989c931d0afa0ea3f887c59775
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.1.2
1
+ ruby 3.3.4
@@ -3,17 +3,33 @@
3
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
21
+ # Implementation omitted
7
22
  require 'logger'
8
23
  require 'fileutils'
9
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)
76
- # rescue Errno::EACCES
77
- # @error_count += 1
78
- rescue StandardError
97
+ log_file = Logger.new(filepath.to_s)
98
+ rescue Errno::EACCES
99
+ @error_count += 1
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.1'
4
+ VERSION = '0.3.2'
5
5
  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.1
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.