colorized_logger 0.1.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: 8e0e8ff102e38416afed6db0a66264a5b7573e373ddd7b18ef529f8e1b39b366
4
+ data.tar.gz: 3b36c32078619fdbd86841942077244cec4d497db421e7bcc9f4d497abc3960c
5
+ SHA512:
6
+ metadata.gz: 8e1edaba02ea3509b912f1e3825ea51aae6ad6ed29346381099dba547410bfc8260db0b478234f2dca6a249ad74fce49a58fb9545a43ed5ca5ba0ece56b0bca0
7
+ data.tar.gz: b395172e98ab59f707675c8a00428b0e5a29e80d3a97e05af2f4eceee56dbe8933276622dd5f58e5abb4a807992f355a062dfd593847a8e0fad700237d9e93e6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-07-04
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ivorjpc@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Ivor Padilla
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # ColorizedLogger
2
+
3
+ ColorizedLogger is a gem that provides a customizable, colorful logging solution for Rails applications, with file and line number information.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'colorized_logger'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install colorized_logger
20
+
21
+ ## Usage
22
+
23
+ In your Rails application, you can use ColorizedLogger like this:
24
+
25
+ ```ruby
26
+ # config/application.rb
27
+ config.logger = ActiveSupport::TaggedLogging.new(ColorizedLogger::Logger.new(Rails.root.join('log', "#{Rails.env}.log")))
28
+
29
+ # In your controllers or models
30
+ logger.print "This is a debug message", color: :yellow
31
+ logger.print "Getting all #{self.all.count} posts", "custom tag", severity: :warn
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ivorpad/colorized_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ivorpad/colorized_logger/blob/master/CODE_OF_CONDUCT.md).
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
47
+
48
+ ## Code of Conduct
49
+
50
+ Everyone interacting in the ColorizedLogger project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ivorpad/colorized_logger/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/colorized_logger/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "colorized_logger"
7
+ spec.version = ColorizedLogger::VERSION
8
+ spec.authors = ["Ivor Padilla"]
9
+ spec.email = ["ivorjpc@gmail.com"]
10
+
11
+ spec.summary = %q{A colorful logger for Rails applications}
12
+ spec.description = %q{ColorizedLogger provides a customizable, colorful logging solution for Rails applications, with file and line number information.}
13
+ spec.homepage = "https://github.com/ivorpad/colorized_logger"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/ivorpad/colorized_logger"
19
+ spec.metadata["changelog_uri"] = "https://github.com/ivorpad/colorized_logger/CHANGELOG.rb"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (File.expand_path(f) == __FILE__) ||
26
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColorizedLogger
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "colorized_logger/version"
4
+ require 'active_support/logger'
5
+ require 'active_support/tagged_logging'
6
+
7
+ module ColorizedLogger
8
+ class Error < StandardError; end
9
+ class Logger < ActiveSupport::Logger
10
+ def initialize(path, colorize: false)
11
+ super(path)
12
+ return unless colorize
13
+ @formatter = ActiveSupport::Logger::SimpleFormatter.new
14
+ self.formatter = proc { |severity, datetime, progname, msg|
15
+ formatted_message = "#{datetime} #{severity} -- #{progname}: #{msg}\n"
16
+ colorize(formatted_message, color_for_severity(severity))
17
+ }
18
+ end
19
+
20
+ def print(message, tag = nil, severity: :debug)
21
+ caller_file = find_caller_file
22
+ tag = tag ? "#{tag} | /#{caller_file}.rb" : "/#{caller_file}.rb"
23
+ color_code = color_for_severity(severity.to_s.upcase)
24
+ colorized_tag = colorize(tag, color_code)
25
+ colorized_message = colorize(message, color_code)
26
+ Rails.logger.tagged(colorized_tag) do
27
+ Rails.logger.debug(colorized_message)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def colorize(text, color_code)
34
+ "\e[#{color_code}m#{text}\e[0m"
35
+ end
36
+
37
+ def color_for_severity(severity)
38
+ case severity
39
+ when "DEBUG" then '36' # cyan
40
+ when "INFO" then '32' # green
41
+ when "WARN" then '33' # yellow
42
+ when "ERROR", "FATAL" then '31' # red
43
+ else '0' # default
44
+ end
45
+ end
46
+
47
+ def find_caller_file
48
+ caller_locations.each do |location|
49
+ file_path = location.path
50
+ if file_path.include?('/app/') && !file_path.include?('/lib/')
51
+ relative_path = extract_relative_path(file_path)
52
+ return "#{relative_path}:#{location.lineno}"
53
+ end
54
+ end
55
+ 'unknown'
56
+ end
57
+
58
+ def extract_relative_path(file_path)
59
+ app_index = file_path.index('/app/')
60
+ return file_path[app_index + 5..-1] if app_index
61
+ file_path
62
+ end
63
+
64
+ def color_for_custom_color(color)
65
+ case color
66
+ when :cyan then '36'
67
+ when :green then '32'
68
+ when :yellow then '33'
69
+ when :red then '31'
70
+ else '0' # default
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,4 @@
1
+ module ColorizedLogger
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colorized_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ivor Padilla
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ColorizedLogger provides a customizable, colorful logging solution for
14
+ Rails applications, with file and line number information.
15
+ email:
16
+ - ivorjpc@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - CODE_OF_CONDUCT.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - colorized_logger.gemspec
27
+ - lib/colorized_logger.rb
28
+ - lib/colorized_logger/version.rb
29
+ - sig/color_logger.rbs
30
+ homepage: https://github.com/ivorpad/colorized_logger
31
+ licenses:
32
+ - MIT
33
+ metadata:
34
+ homepage_uri: https://github.com/ivorpad/colorized_logger
35
+ source_code_uri: https://github.com/ivorpad/colorized_logger
36
+ changelog_uri: https://github.com/ivorpad/colorized_logger/CHANGELOG.rb
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.3.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.5.5
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: A colorful logger for Rails applications
56
+ test_files: []