custom_log_space 0.1.3 → 0.1.4

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: 4c3499fa8649b5c47d67508aa782bbc432da75450f1853050b1c10f444508112
4
- data.tar.gz: 3e680a83be530a4c4ee0b684f113a81b2cfddd0ebf0b817b9131b0553b04cace
3
+ metadata.gz: 58dddf2fc7026b74b4f4afea69035a4a3c94f6d0b1e356a033c8c7368919d530
4
+ data.tar.gz: '0826fdfdb8537d4935182fb05bb7155e5de1162a357fcdf333a89ede1c78900b'
5
5
  SHA512:
6
- metadata.gz: 7167f9dc93e5903cb2c82964b2109b8e58b13a2cc8c084ed47f1ad73877a1ca43d94d20bdec4c676deaba767a0f0ae8c2eb2f07157b34a1090c9309748ccdde6
7
- data.tar.gz: 687f7ca2dc683d757fe2f097857676b8818a6a4a675361b9cebdf10930d2dcf5297637c32f39ea763c2df1b517a01293c285fe60c83303acfaddfc067bd343c5
6
+ metadata.gz: b6a1dcbf9c647fa2402aa11564af5875b0c6718ebf6ee59c8316cddd1a0072e27539ff9e8ea91a5602aced4625d7b098b18778b20b19a8fc2f9e22d977d63a16
7
+ data.tar.gz: 938eb0064c5156508e350ec591a5bca3be50bb3955ec087753dd78fb8f8e90842dd290301492099272616c80800b00c6c2d665447b4a8b5ade3612857079db94
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.4] - 2023-09-15
4
+ ### Changed
5
+ Simplify the gem description
6
+
3
7
  ## [0.1.3] - 2023-09-15
4
8
  ### Changed
5
9
  The retention period for logs within the date directory has been changed from 3 days to 2 days.
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # CustomLogSpace
2
2
 
3
- The CustomLogSpace gem allows Rails developers to direct Rails logs to files, organized by each controller and action. This organization simplifies debugging and analysis.
4
-
5
- Thanks to this gem, developers are freed from the hassle of constantly starting the rails server to check logs every time an action in a controller is executed.
3
+ The CustomLogSpace gem organizes Rails logs by controller and action.
4
+ With it, developers no longer need to start the rails server repeatedly just to check logs.
6
5
 
7
6
  ## Installation
8
7
 
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["tatsunishitatsu@gmail.com"]
10
10
 
11
11
  spec.summary = "A Rails logger extension that organizes logs by controller and action into dedicated folders."
12
- spec.description = "CustomLogSpace refines Rails logs by categorizing them by controller and action. It provides a clearer view."
12
+ spec.description = "This gem organizes Rails logs by controller and action, eliminating the need to start the server for log checks."
13
13
  spec.homepage = "https://github.com/nishikawa1031/custom_log_space.git"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.6.0"
@@ -6,10 +6,15 @@ module CustomLogSpace
6
6
  module LogWriter
7
7
  private
8
8
 
9
- def log_message(message)
10
- current_controller = Thread.current[:current_controller]
11
- current_action = Thread.current[:current_action]
9
+ def current_controller
10
+ Thread.current[:current_controller]
11
+ end
12
12
 
13
+ def current_action
14
+ Thread.current[:current_action]
15
+ end
16
+
17
+ def log_message(message)
13
18
  return unless current_controller && current_action
14
19
 
15
20
  write_to_custom_log(message) do |file|
@@ -20,88 +25,55 @@ module CustomLogSpace
20
25
  end
21
26
 
22
27
  def cleanup_old_directories
23
- return unless Dir.exist?(action_directory)
28
+ return unless Dir.exist?(base_directory_path)
24
29
 
25
- # If there are more than 3 date-directories, remove the oldest ones
30
+ # If there are more than 2 date-directories, remove the oldest ones
26
31
  remove_oldest_directory while all_directories.size > 2
27
32
  end
28
33
 
29
34
  def all_directories
30
- @all_directories ||= Dir.entries(action_directory).select do |entry|
31
- File.directory?(File.join(action_directory, entry)) && entry !~ /^\./
35
+ @all_directories ||= Dir.entries(base_directory_path).select do |entry|
36
+ File.directory?(File.join(base_directory_path, entry)) && entry !~ /^\./
32
37
  end.sort
33
38
  end
34
39
 
35
40
  def remove_oldest_directory
36
41
  directory_to_remove = all_directories.shift
37
- path_to_remove = File.join(action_directory, directory_to_remove)
42
+ path_to_remove = File.join(base_directory_path, directory_to_remove)
38
43
  FileUtils.rm_rf(path_to_remove)
39
44
  end
40
45
 
41
- def action_directory
42
- @action_directory ||= begin
43
- controller_name = Thread.current[:current_controller].underscore
44
- action_name = Thread.current[:current_action]
45
- File.join(Rails.root, "log", "custom_log_space", controller_name, action_name)
46
- end
46
+ def base_directory_path
47
+ File.join(Rails.root, "log", "custom_log_space", current_controller.underscore, current_action)
47
48
  end
48
49
 
49
50
  def write_to_custom_log(message)
50
- directory_path = log_directory_based_on_format
51
+ directory_path = File.join(base_directory_path, Time.now.strftime("%Y-%m-%d"))
51
52
  FileUtils.mkdir_p(directory_path) unless Dir.exist?(directory_path)
52
- custom_log_path = custom_log_file_path(directory_path)
53
+ custom_log_path = "#{directory_path}/#{Time.now.strftime("%H:%M")}.log"
53
54
 
54
55
  File.open(custom_log_path, "a") do |file|
55
56
  yield(file) # Header or other info can be passed and written here
56
57
  file.puts(message)
57
58
  end
58
59
  rescue SystemCallError, IOError => e
59
- handle_file_error(e)
60
- end
61
-
62
- def handle_file_error(error)
63
- error_prefix = error.is_a?(SystemCallError) ? "Error" : "IO Error"
64
- puts "#{error_prefix}: #{error.message}"
60
+ error_prefix = e.is_a?(SystemCallError) ? "Error" : "IO Error"
61
+ puts "#{error_prefix}: #{e.message}"
65
62
  end
66
63
 
64
+ # rubocop:disable Metrics/AbcSize
67
65
  def write_header_information(file)
68
66
  return if Thread.current[:header_written]
69
67
 
70
- current_controller = Thread.current[:current_controller]
71
- current_action = Thread.current[:current_action]
72
-
73
68
  file.puts("") # Add a blank line for better readability.
74
- write_request_info(file)
75
- write_processing_info(file, current_controller, current_action)
76
- write_parameters_info(file)
77
- Thread.current[:header_written] = true
78
- end
79
-
80
- def write_request_info(file)
81
- formatted_time = Time.now.strftime("%Y-%m-%d %H:%M:%S %z")
82
- file.puts "Started GET \"#{Thread.current[:path]}\" for ::1 at #{formatted_time}"
83
- end
84
-
85
- def write_processing_info(file, current_controller, current_action)
69
+ file.puts "Started GET \"#{Thread.current[:path]}\" for ::1 at #{Time.now.strftime("%Y-%m-%d %H:%M:%S %z")}"
86
70
  file.puts "Processing by #{current_controller}##{current_action} as HTML"
87
- end
88
71
 
89
- def write_parameters_info(file)
90
72
  params = Thread.current[:params] || {}
91
73
  file.puts "Parameters: #{params.inspect}" unless params.empty?
92
- end
93
-
94
- def custom_log_file_path(directory_path)
95
- time = Time.now.strftime("%H:%M")
96
- "#{directory_path}/#{time}.log"
97
- end
98
74
 
99
- def log_directory_based_on_format
100
- controller_name = Thread.current[:current_controller].underscore
101
- action_name = Thread.current[:current_action]
102
- date = Time.now.strftime("%Y-%m-%d")
103
-
104
- File.join(Rails.root, "log", "custom_log_space", controller_name, action_name, date)
75
+ Thread.current[:header_written] = true
105
76
  end
77
+ # rubocop:enable Metrics/AbcSize
106
78
  end
107
79
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CustomLogSpace
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "custom_log_space/base_subscriber"
4
- require "custom_log_space/sql_subscriber"
5
- require "custom_log_space/view_subscriber"
3
+ require "custom_log_space/subscribers/base_subscriber"
4
+ require "custom_log_space/subscribers/sql_subscriber"
5
+ require "custom_log_space/subscribers/view_subscriber"
6
6
 
7
7
  CustomLogSpace::BaseSubscriber.attach_to :action_controller
8
8
  SQLSubscriber.attach_to :active_record
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_log_space
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - nishikawa1031
@@ -30,8 +30,8 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '8.0'
33
- description: CustomLogSpace refines Rails logs by categorizing them by controller
34
- and action. It provides a clearer view.
33
+ description: This gem organizes Rails logs by controller and action, eliminating the
34
+ need to start the server for log checks.
35
35
  email:
36
36
  - tatsunishitatsu@gmail.com
37
37
  executables: []
@@ -50,10 +50,10 @@ files:
50
50
  - lib/custom_log_space/base_helper/log_formatter.rb
51
51
  - lib/custom_log_space/base_helper/log_writer.rb
52
52
  - lib/custom_log_space/base_helper/thread_manager.rb
53
- - lib/custom_log_space/base_subscriber.rb
54
- - lib/custom_log_space/sql_subscriber.rb
53
+ - lib/custom_log_space/subscribers/base_subscriber.rb
54
+ - lib/custom_log_space/subscribers/sql_subscriber.rb
55
+ - lib/custom_log_space/subscribers/view_subscriber.rb
55
56
  - lib/custom_log_space/version.rb
56
- - lib/custom_log_space/view_subscriber.rb
57
57
  - sig/custom_log_space.rbs
58
58
  homepage: https://github.com/nishikawa1031/custom_log_space.git
59
59
  licenses: