custom_log_space 0.1.4 → 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: 58dddf2fc7026b74b4f4afea69035a4a3c94f6d0b1e356a033c8c7368919d530
4
- data.tar.gz: '0826fdfdb8537d4935182fb05bb7155e5de1162a357fcdf333a89ede1c78900b'
3
+ metadata.gz: 0e1062675aa1401b1e4b4cfa888586406c375b2b659f70e96e72734a0e770786
4
+ data.tar.gz: 865838694e1eb10da0caf7f35e9d58f4984591a092380f1ed16355753a76a7a5
5
5
  SHA512:
6
- metadata.gz: b6a1dcbf9c647fa2402aa11564af5875b0c6718ebf6ee59c8316cddd1a0072e27539ff9e8ea91a5602aced4625d7b098b18778b20b19a8fc2f9e22d977d63a16
7
- data.tar.gz: 938eb0064c5156508e350ec591a5bca3be50bb3955ec087753dd78fb8f8e90842dd290301492099272616c80800b00c6c2d665447b4a8b5ade3612857079db94
6
+ metadata.gz: a7dbddd8b4777adb61b4bff9732fb1859927f51170292036f9cd78f57a083a5f4dee17d23091ca1c20ff138ae055392c7ec8398a2c4b5c7110e1da7ec87e31b5
7
+ data.tar.gz: 7460fa253f9b52a92748fa458492b1c7f4085badffed04fe4d3f45fe4f462a0610bbf4cc28beafaba7d853d1d44e3b6cae0aa0339cbc8643b235a9cbae6989b2
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
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/`
6
+
7
+ ## [0.1.5] - 2023-09-18
8
+ ### Changed
9
+ Modify so that only 10 files can be created
2
10
 
3
11
  ## [0.1.4] - 2023-09-15
4
12
  ### Changed
data/README.md CHANGED
@@ -34,25 +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
51
+ ## Log Retention Policy
52
+ To maintain system performance and manage disk space:
54
53
 
55
- 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.
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/`
56
59
 
57
60
  ## Ignoring Logs in Git
58
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,19 +49,43 @@ 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|
56
58
  yield(file) # Header or other info can be passed and written here
57
59
  file.puts(message)
58
60
  end
61
+
62
+ cleanup_old_log_files(directory_path)
59
63
  rescue SystemCallError, IOError => e
60
64
  error_prefix = e.is_a?(SystemCallError) ? "Error" : "IO Error"
61
65
  puts "#{error_prefix}: #{e.message}"
62
66
  end
63
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
+
80
+ def cleanup_old_log_files(directory_path)
81
+ log_files = Dir.entries(directory_path).select { |entry| entry =~ /\.log$/ }.sort
82
+ while log_files.size > 10
83
+ oldest_log_file = log_files.shift
84
+ path_to_remove = File.join(directory_path, oldest_log_file)
85
+ File.delete(path_to_remove)
86
+ end
87
+ end
88
+
64
89
  # rubocop:disable Metrics/AbcSize
65
90
  def write_header_information(file)
66
91
  return if Thread.current[:header_written]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CustomLogSpace
4
- VERSION = "0.1.4"
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.4
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-15 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