custom_log_space 0.1.3 → 0.1.5

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: 4c3499fa8649b5c47d67508aa782bbc432da75450f1853050b1c10f444508112
4
- data.tar.gz: 3e680a83be530a4c4ee0b684f113a81b2cfddd0ebf0b817b9131b0553b04cace
3
+ metadata.gz: bb593f3ada3627f418dfe35b2b55ea90c1a697bea93122ecc2e134df75f3a22e
4
+ data.tar.gz: 9b67ad5d122d6eb55624342ef20612ac10b92d3d0c6a6177bf85293e513fc9af
5
5
  SHA512:
6
- metadata.gz: 7167f9dc93e5903cb2c82964b2109b8e58b13a2cc8c084ed47f1ad73877a1ca43d94d20bdec4c676deaba767a0f0ae8c2eb2f07157b34a1090c9309748ccdde6
7
- data.tar.gz: 687f7ca2dc683d757fe2f097857676b8818a6a4a675361b9cebdf10930d2dcf5297637c32f39ea763c2df1b517a01293c285fe60c83303acfaddfc067bd343c5
6
+ metadata.gz: '0738eaf07b4526d6d156874d1f5865e70c247ecdf085cd4bce305a04a80b15943a3431a83859a3cc3a4e9342e1b565b4e40d7b6a3be8457543bf2905e70344bf'
7
+ data.tar.gz: 945319f56b0e7055791bbcb877d7baa20685199d0f31d67f271e1c485c6cbe3c0de28bbfaf9c7298579814fc2ff288ed8d486eddf99a2e88bc083ab21f5cf833
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.5] - 2023-09-18
4
+ ### Changed
5
+ Modify so that only 10 files can be created
6
+
7
+ ## [0.1.4] - 2023-09-15
8
+ ### Changed
9
+ Simplify the gem description
10
+
3
11
  ## [0.1.3] - 2023-09-15
4
12
  ### Changed
5
13
  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
 
@@ -52,8 +51,13 @@ user log % tree
52
51
  ```
53
52
 
54
53
  ## Retention Policy
54
+ To ensure optimal system performance and to prevent excessive disk usage, our logging system implements a strict retention policy:
55
+
56
+ * Date Directory Limitation: Only up to 2 date directories can be created. Any additional date directory beyond this limit will lead to the automatic deletion of the oldest directory.
57
+
58
+ * File Limitation: Only up to 10 log files can be created within the date directory. Ensure to manage the number of logs being generated to stay within this limit.
55
59
 
56
- To prevent excessive disk usage, logs within the `date` directory are retained for only 2 days. Any logs older than this retention period will be automatically deleted, starting with the oldest. Ensure that you archive or backup logs if you need them for longer periods.
60
+ Important: If you require logs to be retained for longer periods or need to keep more extensive records, make sure to archive or backup the necessary log files regularly to prevent any unwanted data loss.
57
61
 
58
62
  ## Ignoring Logs in Git
59
63
  If needed, add `/log/custom_log_space/*` to your `.gitignore` to ensure the logs aren't committed to your repository.
@@ -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,66 @@ 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
59
+
60
+ cleanup_old_log_files(directory_path)
58
61
  rescue SystemCallError, IOError => e
59
- handle_file_error(e)
62
+ error_prefix = e.is_a?(SystemCallError) ? "Error" : "IO Error"
63
+ puts "#{error_prefix}: #{e.message}"
60
64
  end
61
65
 
62
- def handle_file_error(error)
63
- error_prefix = error.is_a?(SystemCallError) ? "Error" : "IO Error"
64
- puts "#{error_prefix}: #{error.message}"
66
+ def cleanup_old_log_files(directory_path)
67
+ log_files = Dir.entries(directory_path).select { |entry| entry =~ /\.log$/ }.sort
68
+ while log_files.size > 10
69
+ oldest_log_file = log_files.shift
70
+ path_to_remove = File.join(directory_path, oldest_log_file)
71
+ File.delete(path_to_remove)
72
+ end
65
73
  end
66
74
 
75
+ # rubocop:disable Metrics/AbcSize
67
76
  def write_header_information(file)
68
77
  return if Thread.current[:header_written]
69
78
 
70
- current_controller = Thread.current[:current_controller]
71
- current_action = Thread.current[:current_action]
72
-
73
79
  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)
80
+ file.puts "Started GET \"#{Thread.current[:path]}\" for ::1 at #{Time.now.strftime("%Y-%m-%d %H:%M:%S %z")}"
86
81
  file.puts "Processing by #{current_controller}##{current_action} as HTML"
87
- end
88
82
 
89
- def write_parameters_info(file)
90
83
  params = Thread.current[:params] || {}
91
84
  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
85
 
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)
86
+ Thread.current[:header_written] = true
105
87
  end
88
+ # rubocop:enable Metrics/AbcSize
106
89
  end
107
90
  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.5"
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,14 +1,14 @@
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - nishikawa1031
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-15 00:00:00.000000000 Z
11
+ date: 2023-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -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: