custom_log_space 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -3
- data/custom_log_space.gemspec +1 -1
- data/lib/custom_log_space/base_helper/log_writer.rb +23 -51
- data/lib/custom_log_space/version.rb +1 -1
- data/lib/custom_log_space.rb +3 -3
- metadata +6 -6
- /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: 58dddf2fc7026b74b4f4afea69035a4a3c94f6d0b1e356a033c8c7368919d530
|
4
|
+
data.tar.gz: '0826fdfdb8537d4935182fb05bb7155e5de1162a357fcdf333a89ede1c78900b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6a1dcbf9c647fa2402aa11564af5875b0c6718ebf6ee59c8316cddd1a0072e27539ff9e8ea91a5602aced4625d7b098b18778b20b19a8fc2f9e22d977d63a16
|
7
|
+
data.tar.gz: 938eb0064c5156508e350ec591a5bca3be50bb3955ec087753dd78fb8f8e90842dd290301492099272616c80800b00c6c2d665447b4a8b5ade3612857079db94
|
data/CHANGELOG.md
CHANGED
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
|
|
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,55 @@ 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
|
58
59
|
rescue SystemCallError, IOError => e
|
59
|
-
|
60
|
-
|
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
|
-
|
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
|
-
|
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
|
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,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.
|
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:
|
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
|