custom_log_space 0.1.5 → 0.1.6

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: bb593f3ada3627f418dfe35b2b55ea90c1a697bea93122ecc2e134df75f3a22e
4
- data.tar.gz: 9b67ad5d122d6eb55624342ef20612ac10b92d3d0c6a6177bf85293e513fc9af
3
+ metadata.gz: 0e1062675aa1401b1e4b4cfa888586406c375b2b659f70e96e72734a0e770786
4
+ data.tar.gz: 865838694e1eb10da0caf7f35e9d58f4984591a092380f1ed16355753a76a7a5
5
5
  SHA512:
6
- metadata.gz: '0738eaf07b4526d6d156874d1f5865e70c247ecdf085cd4bce305a04a80b15943a3431a83859a3cc3a4e9342e1b565b4e40d7b6a3be8457543bf2905e70344bf'
7
- data.tar.gz: 945319f56b0e7055791bbcb877d7baa20685199d0f31d67f271e1c485c6cbe3c0de28bbfaf9c7298579814fc2ff288ed8d486eddf99a2e88bc083ab21f5cf833
6
+ metadata.gz: a7dbddd8b4777adb61b4bff9732fb1859927f51170292036f9cd78f57a083a5f4dee17d23091ca1c20ff138ae055392c7ec8398a2c4b5c7110e1da7ec87e31b5
7
+ data.tar.gz: 7460fa253f9b52a92748fa458492b1c7f4085badffed04fe4d3f45fe4f462a0610bbf4cc28beafaba7d853d1d44e3b6cae0aa0339cbc8643b235a9cbae6989b2
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
  ## [Unreleased]
2
+ ## [0.1.6] - 2023-09-19
3
+ ### Changed
4
+ I have modified the implementation to create a 'saved' folder.
5
+ `log/custom_log_space/#{controller_name}/#{action_name}/saved/`
2
6
 
3
7
  ## [0.1.5] - 2023-09-18
4
8
  ### Changed
data/README.md CHANGED
@@ -34,30 +34,28 @@ user log % tree
34
34
  ├── custom_log_space
35
35
  │   └── articles_controller
36
36
  │   ├── index
37
- │   │   ├── 2023-09-14
38
- │   │   │   ├── 08:45.log
39
- │   │   │   └── 08:46.log
40
- │   │   └── 2023-09-15
41
- │   │   ├── 02:10.log
42
- │   │   ├── 08:10.log
43
- │   │   └── 08:11.log
44
- │   ├── new
45
- │   │   └── 2023-09-14
46
- │   │   └── 08:45.log
37
+ │   │   ├── 2023-09-19
38
+ │   │   │   ├── 09:13.log
39
+ │   │   │   └── 20:00.log
40
+ │   │   └── saved
47
41
  │   └── show
48
- │   └── 2023-09-15
49
-    └── 02:10.log
42
+ │   ├── 2023-09-18
43
+    │   ├── 21:29.log
44
+ │   │   └── 22:02.log
45
+ │   ├── 2023-09-19
46
+ │   │   └── 20:00.log
47
+ │   └── saved
50
48
  └── development.log
51
49
  ```
52
50
 
53
- ## Retention Policy
54
- To ensure optimal system performance and to prevent excessive disk usage, our logging system implements a strict retention policy:
51
+ ## Log Retention Policy
52
+ To maintain system performance and manage disk space:
55
53
 
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.
59
-
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.
54
+ * Date Directory: Max of 2 date-folders, excluding 'saved'. A third will remove the oldest.
55
+ * File Limit: Up to 10 log files per date folder. Monitor your logs to stay within this.
56
+ * Extended Retention: Need logs longer? Archive or back up them. Accidental losses are avoided this way.
57
+ Remember: Files in the 'saved' directory won't be deleted. To keep a log, move it there:
58
+ `log/custom_log_space/#{controller_name}/#{action_name}/saved/`
61
59
 
62
60
  ## Ignoring Logs in Git
63
61
  If needed, add `/log/custom_log_space/*` to your `.gitignore` to ensure the logs aren't committed to your repository.
@@ -27,13 +27,14 @@ module CustomLogSpace
27
27
  def cleanup_old_directories
28
28
  return unless Dir.exist?(base_directory_path)
29
29
 
30
- # If there are more than 2 date-directories, remove the oldest ones
31
- remove_oldest_directory while all_directories.size > 2
30
+ # If there are more than 2 date-directories(except saved directory), remove the oldest ones
31
+ remove_oldest_directory while all_directories.size > 3
32
32
  end
33
33
 
34
34
  def all_directories
35
35
  @all_directories ||= Dir.entries(base_directory_path).select do |entry|
36
- File.directory?(File.join(base_directory_path, entry)) && entry !~ /^\./
36
+ path = File.join(base_directory_path, entry)
37
+ File.directory?(path) && entry !~ /^\./ && entry != "saved"
37
38
  end.sort
38
39
  end
39
40
 
@@ -48,8 +49,9 @@ module CustomLogSpace
48
49
  end
49
50
 
50
51
  def write_to_custom_log(message)
51
- directory_path = File.join(base_directory_path, Time.now.strftime("%Y-%m-%d"))
52
- FileUtils.mkdir_p(directory_path) unless Dir.exist?(directory_path)
52
+ create_saved_directory
53
+ directory_path = create_log_directory
54
+
53
55
  custom_log_path = "#{directory_path}/#{Time.now.strftime("%H:%M")}.log"
54
56
 
55
57
  File.open(custom_log_path, "a") do |file|
@@ -63,6 +65,18 @@ module CustomLogSpace
63
65
  puts "#{error_prefix}: #{e.message}"
64
66
  end
65
67
 
68
+ # Create the 'saved' directory (but don't place logs in it)
69
+ def create_saved_directory
70
+ saved_directory_path = File.join(base_directory_path, "saved")
71
+ FileUtils.mkdir_p(saved_directory_path) unless Dir.exist?(saved_directory_path)
72
+ end
73
+
74
+ def create_log_directory
75
+ directory_path = File.join(base_directory_path, Time.now.strftime("%Y-%m-%d"))
76
+ FileUtils.mkdir_p(directory_path) unless Dir.exist?(directory_path)
77
+ directory_path
78
+ end
79
+
66
80
  def cleanup_old_log_files(directory_path)
67
81
  log_files = Dir.entries(directory_path).select { |entry| entry =~ /\.log$/ }.sort
68
82
  while log_files.size > 10
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CustomLogSpace
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
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.5
4
+ version: 0.1.6
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-18 00:00:00.000000000 Z
11
+ date: 2023-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport