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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +8 -4
- data/custom_log_space.gemspec +1 -1
- data/lib/custom_log_space/base_helper/log_writer.rb +32 -49
- data/lib/custom_log_space/version.rb +1 -1
- data/lib/custom_log_space.rb +3 -3
- metadata +7 -7
- /data/lib/custom_log_space/{base_subscriber.rb → subscribers/base_subscriber.rb} +0 -0
- /data/lib/custom_log_space/{sql_subscriber.rb → subscribers/sql_subscriber.rb} +0 -0
- /data/lib/custom_log_space/{view_subscriber.rb → subscribers/view_subscriber.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb593f3ada3627f418dfe35b2b55ea90c1a697bea93122ecc2e134df75f3a22e
|
4
|
+
data.tar.gz: 9b67ad5d122d6eb55624342ef20612ac10b92d3d0c6a6177bf85293e513fc9af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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.
|
data/custom_log_space.gemspec
CHANGED
@@ -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 = "
|
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
|
10
|
-
|
11
|
-
|
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?(
|
28
|
+
return unless Dir.exist?(base_directory_path)
|
24
29
|
|
25
|
-
# If there are more than
|
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(
|
31
|
-
File.directory?(File.join(
|
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(
|
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
|
42
|
-
|
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 =
|
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 =
|
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
|
-
|
62
|
+
error_prefix = e.is_a?(SystemCallError) ? "Error" : "IO Error"
|
63
|
+
puts "#{error_prefix}: #{e.message}"
|
60
64
|
end
|
61
65
|
|
62
|
-
def
|
63
|
-
|
64
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/custom_log_space.rb
CHANGED
@@ -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.
|
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-
|
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:
|
34
|
-
|
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:
|
File without changes
|
File without changes
|
File without changes
|