versalog 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1985cdbce1b4b3bb3dda6573700f12da050ac8b31f5a350be72bc66d1fe9fff5
4
+ data.tar.gz: d6b091088bb69c9f85c31da76bd1a3e474aa6b75c7952ef0ab6198f66fd9764d
5
+ SHA512:
6
+ metadata.gz: 709fb02663f87fc5154b3c00784e3eda4ad0ee112bc88c78a469ac16ed9d7b98fbe3cf56c567783eed0d0188cb87951149c2f1be74d971ce6bed175929fefabc
7
+ data.tar.gz: 6e2510c7dd6658813b26e2dce0c8157eb14c5388e668c2773945722bd2fc4272538f081ee9433381bf43b7bd4b7f8991cf111db767b79230f261a4ab088ea708
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-10-06
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2025 VersaLog
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # What is VersaLog.rb?
2
+
3
+ What is VersaLog.rb?
4
+ VersaLog is a powerful and flexible logging library for Ruby.
5
+ It supports everything from simple usage to advanced, highly customizable configurations to meet a wide range of needs.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+
11
+ ```
12
+
13
+ ### Enum
14
+
15
+ | Enum | Description |
16
+ | ---------- | ---------------------------------------------------------------------------- |
17
+ | `detailed` | Logs including execution time and log levels |
18
+ | `file` | Logs with filename and line number |
19
+ | `simple` | Simple and easy-to-read logs |
20
+ | `simple2` | Simple and easy-to-read log format. The timestamp is automatically included. |
21
+
22
+ ### Options
23
+
24
+ | Options | Description |
25
+ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
26
+ | `show_file` | True : Display filename and line number (for simple and detailed modes) |
27
+ | `show_tag` | True : Show self.tag if no explicit tag is provided |
28
+ | `tag` | Default tag to use when show_tag is enabled |
29
+ | `enable_all` | Shortcut to enable both show_file and show_tag |
30
+ | `notice` | True : When an error or critical level log is output, a desktop notification (using plyer.notification) will be displayed. The notification includes the log level and message. |
31
+ | `all_save` | True : When an error or critical level log is output, the log will be saved to a file. |
32
+ | `save_levels` | A list of log levels to save. Defaults to ["INFO", "ERROR", "WARNING", "DEBUG", "CRITICAL"]. |
33
+ | `silent` | True : Suppress standard output (print) |
34
+ | `catch_exceptions` | True : Automatically catch unhandled exceptions and log them as critical |
35
+
36
+ ## Log save
37
+
38
+ ```
39
+ [2025-08-06 04:10:36][INFO] : ok
40
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Versalog
4
+ VERSION = "1.6.0"
5
+ end
data/lib/versalog.rb ADDED
@@ -0,0 +1,272 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "time"
4
+ require "caller"
5
+ require "ENV"
6
+ require "ARGV"
7
+ require "thread"
8
+ require "win32/notification"
9
+ require "date"
10
+ require "fileutils"
11
+
12
+ require_relative "versalog/version"
13
+
14
+ module Versalog
15
+ class VersaLog
16
+ COLOURS = {
17
+ "INFO": "\033[32m",
18
+ "ERROR": "\033[31m",
19
+ "WARNING": "\033[33m",
20
+ "DEBUG": "\033[36m",
21
+ "CRITICAL": "\033[35m",
22
+ }.freeze
23
+
24
+ SYMBOLS = {
25
+ "INFO": "[+]",
26
+ "ERROR": "[-]",
27
+ "WARNING": "[!]",
28
+ "DEBUG": "[D]",
29
+ "CRITICAL": "[C]",
30
+ }.freeze
31
+
32
+ RESET = "\033[0m"
33
+
34
+ VALID_MODES = ["simple", "simple2", "detailed", "file"].freeze
35
+ VALID_SAVE_LEVELS = ["INFO", "ERROR", "WARNING", "DEBUG", "CRITICAL"].freeze
36
+
37
+ def initialize(
38
+ enum: "simple",
39
+ tag: nil,
40
+ show_file: false,
41
+ show_tag: false,
42
+ enable_all: false,
43
+ notice: false,
44
+ all_save: false,
45
+ save_levels: nil,
46
+ silent: false,
47
+ catch_exceptions: false)
48
+
49
+ if enable_all
50
+ show_file = true
51
+ show_tag = true
52
+ notice = true
53
+ all_save = true
54
+ end
55
+
56
+ @enum = enum.downcase
57
+ @tag = tag
58
+ @show_file = show_file
59
+ @show_tag = show_tag
60
+ @enable_all = enable_all
61
+ @notice = notice
62
+ @all_save = all_save
63
+ @save_levels = save_levels
64
+ @silent = silent
65
+ @catch_exceptions = catch_exceptions
66
+
67
+ @log_queue = Queue.new
68
+ @worker_thread = Thread.new { _worker }
69
+ @last_cleanup_date = nil
70
+
71
+ unless VALID_MODES.include?(@enum)
72
+ raise ArgumentError, "Invalid enum: #{@enum}"
73
+ end
74
+
75
+ if @all_save
76
+ if @save_levels.nil?
77
+ @save_levels = VALID_SAVE_LEVELS.dup
78
+ elsif !@save_levels.is_a?(Array)
79
+ raise ArgumentError, "save_levels must be an Array. Example: ['ERROR']"
80
+ elsif !@save_levels.all? { |level| VALID_SAVE_LEVELS.include?(level) }
81
+ raise ArgumentError, "Invalid save_levels specified. Valid levels are: #{VALID_SAVE_LEVELS.join(', ')}"
82
+ end
83
+ end
84
+
85
+ if @catch_exceptions
86
+ at_exit do
87
+ exception = $!
88
+ _handle_exception(exception) if exception && exception.is_a?(Exception)
89
+ end
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ def _handle_exception(exception)
96
+ tb_str = exception.backtrace.join("\n")
97
+ critical("Unhandled exception:\n#{exception.class}: #{exception.message}\n#{tb_str}")
98
+ end
99
+
100
+ def _worker
101
+ loop do
102
+ job = @log_queue.pop
103
+ break if job.nil?
104
+
105
+ case job[:type]
106
+ when :log
107
+ _save_log_sync(job[:log_text], job[:level])
108
+ when :exception
109
+ _handle_exception(job[:exception])
110
+ end
111
+ end
112
+ end
113
+
114
+ def _GetTime
115
+ return Time.now.strftime("%Y-%m-%d %H:%M:%S")
116
+ end
117
+
118
+ def _GetCaller
119
+ frame = caller(3, 1).first
120
+ return nil if frame.nil?
121
+
122
+ match = frame.match(/^(.+):(\d+):/)
123
+ return nil unless match
124
+
125
+ filename = File.basename(match[1])
126
+ lineno = match[2]
127
+ return "#{filename}:#{lineno}"
128
+ end
129
+
130
+ def _Cleanup_old_logs(days: 7)
131
+ log_dir = File.join(Dir.pwd, 'log')
132
+ return unless Dir.exist?(log_dir)
133
+
134
+ now = Time.now
135
+ Dir.entries(log_dir).each do |filename|
136
+ next unless filename.end_with?('.log')
137
+ next if filename == '.' || filename == '..'
138
+
139
+ filepath = File.join(log_dir, filename)
140
+
141
+ begin
142
+ date_str = filename.gsub('.log', '')
143
+ file_date = Date.strptime(date_str, '%Y-%m-%d').to_time
144
+ rescue ArgumentError
145
+ file_date = File.mtime(filepath)
146
+ end
147
+
148
+ if (now - file_date) / (24 * 60 * 60) >= days
149
+ begin
150
+ File.delete(filepath)
151
+ info("[LOG CLEANUP] removed: #{filepath}") unless @silent
152
+ rescue => e
153
+ warning("[LOG CLEANUP WARNING] #{filepath} cannot be removed: #{e}") unless @silent
154
+ end
155
+ end
156
+ end
157
+ end
158
+
159
+ def _save_log_sync(log_text, level)
160
+ return unless @all_save
161
+ return unless @save_levels.include?(level)
162
+
163
+ log_dir = File.join(Dir.pwd, 'log')
164
+ FileUtils.mkdir_p(log_dir)
165
+ log_file = File.join(log_dir, Time.now.strftime('%Y-%m-%d') + '.log')
166
+
167
+ File.open(log_file, 'a', encoding: 'utf-8') do |f|
168
+ f.write(log_text + "\n")
169
+ end
170
+
171
+ today = Date.today
172
+ if @last_cleanup_date != today
173
+ _Cleanup_old_logs(days: 7)
174
+ @last_cleanup_date = today
175
+ end
176
+ end
177
+
178
+ def _save_log(log_text, level)
179
+ return unless @save_levels.include?(level)
180
+
181
+ log_dir = File.join(Dir.pwd, 'log')
182
+ FileUtils.mkdir_p(log_dir) unless Dir.exist?(log_dir)
183
+ log_file = File.join(log_dir, Time.now.strftime('%Y-%m-%d') + '.log')
184
+
185
+ File.open(log_file, 'a', encoding: 'utf-8') do |f|
186
+ f.write(log_text + "\n")
187
+ end
188
+ end
189
+
190
+ def _Log(msg, tye, tag = nil)
191
+ colors = COLOURS[tye.to_sym] || ""
192
+ types = tye.upcase
193
+
194
+ final_tag = tag || (@show_tag ? @tag : nil)
195
+ tag_str = final_tag || ""
196
+
197
+ caller_info = (@show_file || @enum == "file") ? _GetCaller() : ""
198
+
199
+ if @notice && ["ERROR", "CRITICAL"].include?(types)
200
+ Win32::Notification.new(
201
+ title: "#{types} Log notice",
202
+ message: msg,
203
+ app_name: "VersaLog"
204
+ ).show
205
+ end
206
+
207
+ case @enum
208
+ when "simple"
209
+ symbol = SYMBOLS[tye.to_sym] || "[?]"
210
+ if @show_file
211
+ formatted = "[#{caller_info}][#{tag_str}]#{colors}#{symbol}#{RESET} #{msg}"
212
+ plain = "[#{caller_info}][#{tag_str}]#{symbol} #{msg}"
213
+ else
214
+ formatted = "#{colors}#{symbol}#{RESET} #{msg}"
215
+ plain = "#{symbol} #{msg}"
216
+ end
217
+
218
+ when "simple2"
219
+ symbol = SYMBOLS[tye.to_sym] || "[?]"
220
+ time = _GetTime()
221
+ if @show_file
222
+ formatted = "[#{time}] [#{caller_info}][#{tag_str}]#{colors}#{symbol}#{RESET} #{msg}"
223
+ plain = "[#{time}] [#{caller_info}][#{tag_str}]#{symbol} #{msg}"
224
+ else
225
+ formatted = "[#{time}] #{colors}#{symbol}#{RESET} #{msg}"
226
+ plain = "[#{time}] #{symbol} #{msg}"
227
+ end
228
+
229
+ when "file"
230
+ formatted = "[#{caller_info}]#{colors}[#{types}]#{RESET} #{msg}"
231
+ plain = "[#{caller_info}][#{types}] #{msg}"
232
+
233
+ else
234
+ time = _GetTime()
235
+ formatted = "[#{time}]#{colors}[#{types}]#{RESET}"
236
+ plain = "[#{time}][#{types}]"
237
+ if final_tag
238
+ formatted += "[#{final_tag}]"
239
+ plain += "[#{final_tag}]"
240
+ end
241
+ if @show_file
242
+ formatted += "[#{caller_info}]"
243
+ plain += "[#{caller_info}]"
244
+ end
245
+ formatted += " : #{msg}"
246
+ plain += " : #{msg}"
247
+ end
248
+
249
+ puts(formatted) unless @silent
250
+
251
+ @log_queue << { type: :log, log_text: plain, level: types }
252
+ end
253
+
254
+ def info(msg, tag = nil)
255
+ _Log(msg, "INFO", tag)
256
+ end
257
+
258
+ def error(msg, tag = nil)
259
+ _Log(msg, "ERROR", tag)
260
+ end
261
+
262
+ def warning(msg, tag = nil)
263
+ _Log(msg, "WARNING", tag)
264
+ end
265
+
266
+ def debug(msg, tag = nil)
267
+ _Log(msg, "DEBUG", tag)
268
+ end
269
+
270
+ def critical(msg, tag = nil)
271
+ _Log(msg, "CRITICAL", tag)
272
+ end
data/sig/versalog.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Versalog
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: versalog
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.0
5
+ platform: ruby
6
+ authors:
7
+ - kaedeek
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: VersaLog is a logging library for Ruby.
13
+ executables: []
14
+ extensions: []
15
+ extra_rdoc_files: []
16
+ files:
17
+ - ".rspec"
18
+ - ".rubocop.yml"
19
+ - CHANGELOG.md
20
+ - CODE_OF_CONDUCT.md
21
+ - LICENSE.txt
22
+ - README.md
23
+ - Rakefile
24
+ - lib/versalog.rb
25
+ - lib/versalog/version.rb
26
+ - sig/versalog.rbs
27
+ homepage: https://github.com/VersaLog/VersaLog.rb
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ homepage_uri: https://github.com/VersaLog/VersaLog.rb
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.1.0
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.6.9
47
+ specification_version: 4
48
+ summary: VersaLog is a logging library for Ruby.
49
+ test_files: []