custom_log_space 0.1.0 → 0.1.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: 98b901d882ede4d8684e25e13741a5e65eb6f61cbbae5b4e8bb597c15781d23e
4
- data.tar.gz: bf6f8ccf000f73f92d4b94853847d7f04cfb575b6460bbb791702a1f4ed8514d
3
+ metadata.gz: 86f641a93a9acedc9acd1bd245dc3647a8ff0c03cc51e86a2f460e1d2129eb69
4
+ data.tar.gz: 28f2797855109065af34d10c97fb84232d0f5d19982a33bfd8805867c7e2863e
5
5
  SHA512:
6
- metadata.gz: dc4463dfe438bf6d25b200177211506c5e34c3011199caf737013083f121ceb0004d633901d3bf859a89037137b99e9bef5907e1ccdc35ee4e096a8b6e9da096
7
- data.tar.gz: 173effc0824a52f8cf383d91c15c027157b03c2c0ffbf46b99368cb0b9a841a05eba2f37131083f61e880bc95ffb5c1fc4b9fa9183f46f1358c08d910ff3d852
6
+ metadata.gz: e61a8eea062c891e6b84e1b221ade929e01e27201f65d420d2909681fb61eac3ea89292a79013da0ac569fda9619af05913459c6961b1ef8591cd0768e695f59
7
+ data.tar.gz: 343a26cfd26d3191e371b059985a1056ee0b4a84b2a279ac2c33515255e8e6ab4e1952f29bc84e90c4352fdfa1dd3dd3dbd31785a3e9972094ed87da911a7478
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2023-09-12
3
+ ## [0.1.1] - 2023-09-13
4
+ ### Added
5
+ - Added `cleanup_old_directories` method to manage and delete old directories, ensuring only the two most recent date-directories remain.
4
6
 
7
+ ## [0.1.0] - 2023-09-12
5
8
  - Initial release
data/README.md CHANGED
@@ -25,10 +25,15 @@ $ gem install custom_log_space
25
25
  ```
26
26
 
27
27
  ## Usage
28
- Logs are saved in the `log/custom_log_space/[date]/[time]/[controller_name]/` directory. The filenames follow the pattern: "[action_name].log".
28
+ Logs are saved in the `log/custom_log_space/[date]/[time]/[controller_name]/` directory. The filenames follow the pattern: `[action_name].log`.
29
29
 
30
30
  <img width="492" alt="スクリーンショット 2023-09-12 8 37 43" src="https://github.com/nishikawa1031/custom_log_space/assets/53680568/95cf44c8-e256-44d0-b0cb-9d6367601985">
31
31
 
32
+ ## Ignoring Logs in Git
33
+ If needed, add `/log/custom_log_space/*` to your `.gitignore` to ensure the logs aren't committed to your repository.
34
+ ```
35
+ /log/custom_log_space/*
36
+ ```
32
37
 
33
38
  ## Supported environments
34
39
  - Rails 7
@@ -3,6 +3,7 @@
3
3
  module CustomLogSpace
4
4
  # CustomLogSpace::Subscriber is a class for handling custom logging in Rails applications.
5
5
  # It provides methods for processing different types of log events and organizing log messages.
6
+ # https://github.com/rails/rails/blob/7-0-stable/activesupport/lib/active_support/log_subscriber.rb
6
7
  class BaseSubscriber < ActiveSupport::LogSubscriber
7
8
  def start_processing(event)
8
9
  setup_thread_variables(event.payload)
@@ -49,6 +50,21 @@ module CustomLogSpace
49
50
 
50
51
  FileUtils.mkdir_p(controller_log_directory) unless Dir.exist?(controller_log_directory)
51
52
  write_to_custom_log(message)
53
+ cleanup_old_directories
54
+ end
55
+
56
+ def cleanup_old_directories
57
+ base_directory = File.join(Rails.root, "log", "custom_log_space")
58
+ all_directories = Dir.entries(base_directory).select do |entry|
59
+ File.directory?(File.join(base_directory, entry)) && entry !~ /^\./
60
+ end.sort
61
+
62
+ # If there are more than 2 date-directories, remove the oldest one
63
+ while all_directories.size > 2
64
+ directory_to_remove = all_directories.shift
65
+ path_to_remove = File.join(base_directory, directory_to_remove)
66
+ FileUtils.rm_rf(path_to_remove)
67
+ end
52
68
  end
53
69
 
54
70
  def custom_log_directory
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CustomLogSpace
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  # ViewSubscriber logs view rendering events for CustomLogSpace.
4
4
  # It tracks events like template rendering, partial rendering, and collection rendering.
5
+ # https://github.com/rails/rails/blob/7-0-stable/actionview/lib/action_view/log_subscriber.rb
5
6
  class ViewSubscriber < CustomLogSpace::BaseSubscriber
6
7
  def render_template(event)
7
8
  identifier = event.payload[:identifier]
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.0
4
+ version: 0.1.1
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 00:00:00.000000000 Z
11
+ date: 2023-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport