loggerx 0.2.0 → 0.3.1

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: ef752536a65e45147353b942c929a06694dbe744ab5482ad9eb51eed26e9a739
4
- data.tar.gz: 53f9e598326aa28f1ab8abdd06434c1f268863d9e77d7096c1552fdcb5138b87
3
+ metadata.gz: 3fd826254376e64dc953e21e9ba92bc7ae0fc1a9f53c293b19ed093616acce29
4
+ data.tar.gz: 81d5fcb3dc14a34df39d491a88604a163041548baffa1f9d829645d8f2f95f95
5
5
  SHA512:
6
- metadata.gz: b6655835b8695913f29fd84e94fcf1700dba61951a24fb32e2d0cb567ff20c340068f0e4f0a56957ce7a1ba697fcace8878a31af69c4c2e3402f0765960ed4ad
7
- data.tar.gz: 4e445fa4b53d19d360325da3e09f190c2959e867d74ed912598bec47aa48dc114b4159eba4f3b8a702a124fa65b091ffbeaea9dc0bfee1cddd693e3f56993535
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
- 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/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
 
data/SECURITY.md ADDED
@@ -0,0 +1,21 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 5.1.x | :white_check_mark: |
11
+ | 5.0.x | :x: |
12
+ | 4.0.x | :white_check_mark: |
13
+ | < 4.0 | :x: |
14
+
15
+ ## Reporting a Vulnerability
16
+
17
+ Use this section to tell people how to report a vulnerability.
18
+
19
+ Tell them where to go, how often they can expect to get an update on a
20
+ reported vulnerability, what to expect if the vulnerability is accepted or
21
+ declined, etc.
@@ -0,0 +1,8 @@
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "../.."
5
+ }
6
+ ],
7
+ "settings": {}
8
+ }
@@ -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,12 +38,19 @@ 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
+ # register_log_format(obj)
42
+ # register_log_level(level_hs[level])
43
+ level_hs[level]
44
+ end
41
45
 
42
- obj = proc do |_, _, _, msg|
43
- "#{msg}\n"
44
- end
45
- register_log_format(obj)
46
- register_log_level(level_hs[level])
46
+ def formatter
47
+ @log_file&.formatter
48
+ # @log_stdout&.formatter
49
+ end
50
+
51
+ def formatter=(obj)
52
+ @log_file&.formatter = obj
53
+ @log_stdout&.formatter = obj
47
54
  end
48
55
 
49
56
  def logger_stdout
@@ -60,30 +67,37 @@ module Loggerx
60
67
  return log_stdout unless log_stdout.nil?
61
68
 
62
69
  begin
63
- # log_stdout = Logger.new($stdout)
64
- log_stdout = Logger.new($stdout)
70
+ log ||= ActiveSupport::TaggedLogging.new($stdout)
65
71
  rescue StandardError
66
72
  @error_stderror_count += 1
67
73
  end
68
- log_stdout
74
+ log
69
75
  end
70
76
 
71
77
  def setup_logger_file(log_dir, fname)
72
78
  filepath = Pathname.new(log_dir).join(fname)
73
- log_file = nil
74
79
  begin
75
- log_file = Logger.new(filepath)
80
+ log ||= ActiveSupport::TaggedLogging.new(filepath)
76
81
  rescue Errno::EACCES
77
82
  @error_access_count += 1
78
83
  rescue StandardError
79
84
  @error_stderror_count += 1
80
85
  end
81
- log_file
86
+ log
82
87
  end
83
88
 
84
- def register_log_format(obj)
85
- @log_file&.formatter = obj
86
- @log_stdout&.formatter = obj
89
+ def level
90
+ @log_file&.level
91
+ # @log_stdout&.level
92
+ # Log4r互換インターフェイス
93
+ # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
94
+ end
95
+
96
+ def level=(value)
97
+ @log_file&.level = value
98
+ @log_stdout&.level = value
99
+ # Log4r互換インターフェイス
100
+ # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
87
101
  end
88
102
 
89
103
  def register_log_level(level)
@@ -96,7 +110,7 @@ module Loggerx
96
110
  def to_string(value)
97
111
  if value.instance_of?(Array)
98
112
  @stdout_backup ||= $stdout
99
- @stringio ||= StringIO.new(+"", "w+")
113
+ @stringio ||= StringIO.new(+'', 'w+')
100
114
  $stdout = @stringio
101
115
  $stdout = @stdout_backup
102
116
  @stringio.rewind
@@ -130,7 +144,6 @@ module Loggerx
130
144
 
131
145
  def debug(value)
132
146
  str = to_string(value)
133
- # p str
134
147
  @log_file&.debug(str)
135
148
  @log_stdout&.debug(str)
136
149
  true
@@ -168,39 +181,39 @@ module Loggerx
168
181
  end
169
182
 
170
183
  def hash_to_args(hash)
171
- prefix = hash["prefix"]
172
- log_dir_pn = Pathname.new(hash["log_dir"])
184
+ prefix = hash['prefix']
185
+ log_dir_pn = Pathname.new(hash['log_dir'])
173
186
 
174
- stdout_flag_str = hash["stdout_flag"]
187
+ stdout_flag_str = hash['stdout_flag']
175
188
  stdout_flag = if stdout_flag_str.instance_of?(String)
176
- case stdout_flag_str
177
- when "true"
178
- true
179
- else
180
- false
181
- end
182
- else
183
- stdout_flag_str
184
- end
185
-
186
- 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']
187
200
  fname = case fname_str
188
- when "default"
189
- fname_str.to_sym
190
- when "false"
191
- false
192
- else
193
- fname_str
194
- end
201
+ when 'default'
202
+ fname_str.to_sym
203
+ when 'false'
204
+ false
205
+ else
206
+ fname_str
207
+ end
195
208
 
196
- level = hash["level"].to_sym
209
+ level = hash['level'].to_sym
197
210
 
198
211
  [prefix, fname, log_dir_pn, stdout_flag, level]
199
212
  end
200
213
 
201
214
  def create_by_hash(hash)
202
215
  prefix, fname, log_dir_pn, stdout_flag, level = hash_to_args(hash)
203
- new(prefix, fname, log_dir_pn, stdout_flag, level)
216
+ Loggerx.new(prefix, fname, log_dir_pn, stdout_flag, level)
204
217
  end
205
218
 
206
219
  def init_by_hash(hash)
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "pathname"
3
+ require 'pathname'
4
4
 
5
5
  module Loggerx
6
6
  class Loggerxcm0
7
- require "logger"
8
- require "fileutils"
9
- require "stringio"
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(+"", "w+")
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
- @error_count += 1
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(+"", "w+")
101
+ @stringio ||= StringIO.new(+'', 'w+')
102
102
  $stdout = @stringio
103
103
  $stdout = @stdout_backup
104
104
  @stringio.rewind
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Loggerx
4
- VERSION = "0.2.0"
4
+ VERSION = '0.3.1'
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.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ykominami
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-17 00:00:00.000000000 Z
11
+ date: 2024-10-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Utility class for Logging.
14
14
  email:
@@ -25,20 +25,22 @@ files:
25
25
  - LICENSE.txt
26
26
  - README.md
27
27
  - Rakefile
28
+ - SECURITY.md
28
29
  - lib/loggerx.rb
30
+ - lib/loggerx/loggerx.code-workspace
29
31
  - lib/loggerx/loggerx.rb
30
32
  - lib/loggerx/loggerxcm.rb
31
33
  - lib/loggerx/version.rb
32
34
  - loggerx.code-workspace
33
35
  - sig/loggerx.rbs
34
- homepage:
36
+ homepage:
35
37
  licenses:
36
38
  - MIT
37
39
  metadata:
38
40
  source_code_uri: https://github.com/ykominami/loggerx
39
41
  changelog_uri: https://github.com/ykominami/loggerx/blob/main/CHANGELOG.md
40
42
  rubygems_mfa_required: 'true'
41
- post_install_message:
43
+ post_install_message:
42
44
  rdoc_options: []
43
45
  require_paths:
44
46
  - lib
@@ -53,8 +55,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
55
  - !ruby/object:Gem::Version
54
56
  version: '0'
55
57
  requirements: []
56
- rubygems_version: 3.3.7
57
- signing_key:
58
+ rubygems_version: 3.5.14
59
+ signing_key:
58
60
  specification_version: 4
59
61
  summary: Utility class for Logging.
60
62
  test_files: []