colorize_logs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/lib/colorize_logs/formatter.rb +52 -0
- data/lib/colorize_logs/version.rb +5 -0
- data/lib/colorize_logs.rb +8 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 24e8012a066cd6081ce2a0592902ad8151fb91c0a185dd7a49ff1e4e0d3bec05
|
4
|
+
data.tar.gz: 4099845270390945e81efffe62a91d03956bf0b31718e3b55fb84f49f40098ae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3aae37ae8779812e3df956b908578f5fc622284cec397f2d532e22338f6310005d87dcd26241bf918b92f6b2f56fb4e55224b0d36d444ec2738ff21380e6157
|
7
|
+
data.tar.gz: ca5a5a6226022f9907bef2830c4262af3ddce93b65812cb3ca92c6bd844d52b10fe9cfb0414112dc215bb464d1c1d68c03ee25aa7e3c5ba031dfe18e09a8cb54
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Santosh Wadghule
|
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,83 @@
|
|
1
|
+
# ColorizeLogs
|
2
|
+
|
3
|
+
As developers, we often deal with current controller's action, its main view page and the layout associated with it. To
|
4
|
+
trace and debug these logs information, we check the logs through our console.
|
5
|
+
|
6
|
+
However, by default, the logs are all in the same color, which makes it difficult to find the ones which we're working
|
7
|
+
on. To simplify our lives and speed up the debugging process, we want to assign different colors to these logs.
|
8
|
+
This will make it much easier for us to spot the right information and save time when we're fixing issues and improving
|
9
|
+
our software.
|
10
|
+
|
11
|
+
To ease our development time, we can use this gem. It will colorize the logs for controller's action, view, layout,
|
12
|
+
and etc.
|
13
|
+
|
14
|
+
![colorize_logs](https://user-images.githubusercontent.com/77895/270565495-a75fc46d-b574-4fbe-9976-998abbf0b7b7.png)
|
15
|
+
|
16
|
+
[![Build Status](https://github.com/mechanicles/colorize_logs/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/mechanicles/colorize_logs/actions)
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application’s Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
group :development do
|
24
|
+
gem "colorize_logs"
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
29
|
+
|
30
|
+
$ gem install colorize_logs
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Create an initializer file `config/initializers/colorize_logs.rb` and add the following code:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# frozen_string_literal: true
|
38
|
+
|
39
|
+
colorize_logs_formatter = ColorizeLogs::Formatter.new
|
40
|
+
|
41
|
+
colorize_logs_formatter.configure do
|
42
|
+
match(/Processing by/) do |msg|
|
43
|
+
msg.red
|
44
|
+
end
|
45
|
+
|
46
|
+
match(/Rendering layout/) do |msg|
|
47
|
+
msg.green
|
48
|
+
end
|
49
|
+
|
50
|
+
match(/Rendering.*within layouts/) do |msg|
|
51
|
+
msg.green
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
::Rails.logger.formatter = colorize_logs_formatter
|
56
|
+
```
|
57
|
+
|
58
|
+
That's it. Restart your server and you should see the logs in different colors.
|
59
|
+
|
60
|
+
|
61
|
+
## Credits
|
62
|
+
|
63
|
+
This gem is inspired by [Shog](https://github.com/phallguy/shog) gem. All the credits goes to the author of Shog gem.
|
64
|
+
I had to create this one as original gem is not maintained anymore and I wanted minimal stuff from it.
|
65
|
+
|
66
|
+
## Development
|
67
|
+
|
68
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
69
|
+
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
70
|
+
|
71
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
72
|
+
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
73
|
+
push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mechanicles/colorize_logs. This project is
|
78
|
+
intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
|
79
|
+
[code of conduct](https://github.com/mechanicles/colorize_logs/blob/master/CODE_OF_CONDUCT.md).
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/tagged_logging"
|
4
|
+
require "colorize"
|
5
|
+
|
6
|
+
module ColorizeLogs
|
7
|
+
# Custom formatter for Rails logger
|
8
|
+
class Formatter < ActiveSupport::Logger::SimpleFormatter
|
9
|
+
include ActiveSupport::TaggedLogging::Formatter
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
|
14
|
+
@matchers = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure(&block)
|
18
|
+
instance_eval(&block)
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(severity, time, progname, msg)
|
23
|
+
return if msg.blank?
|
24
|
+
|
25
|
+
msg = colorize_message(msg)
|
26
|
+
|
27
|
+
super(severity, time, progname, msg)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def colorize_message(msg)
|
33
|
+
msg = msg.is_a?(String) ? msg : msg.inspect
|
34
|
+
|
35
|
+
proc = find_matching_pattern(msg)
|
36
|
+
|
37
|
+
proc ? proc.call(msg) : msg
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_matching_pattern(msg)
|
41
|
+
matcher = @matchers.find { |pattern, _| pattern.match(msg) }
|
42
|
+
|
43
|
+
matcher&.last
|
44
|
+
end
|
45
|
+
|
46
|
+
def match(pattern, proc = nil, &block)
|
47
|
+
proc ||= block
|
48
|
+
@matchers[pattern] = proc
|
49
|
+
self
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: colorize_logs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Santosh Wadghule
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- santosh.wadghule@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE.txt
|
49
|
+
- README.md
|
50
|
+
- lib/colorize_logs.rb
|
51
|
+
- lib/colorize_logs/formatter.rb
|
52
|
+
- lib/colorize_logs/version.rb
|
53
|
+
homepage: https://github.com/mechanicles/colorize_logs
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.6.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.3.7
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Colorize your Rails logs
|
76
|
+
test_files: []
|