coloured_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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/coloured_logger.gemspec +26 -0
- data/docs/demo_output.png +0 -0
- data/lib/coloured_logger.rb +74 -0
- data/lib/coloured_logger/logger.rb +15 -0
- data/lib/coloured_logger/version.rb +3 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 923b9a83f70092681c1c512aab5a6064e10393be
|
4
|
+
data.tar.gz: 78ec6f7454b9a86ea9b9757c9e7193cc61040b72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ad9df360686fcfee8367f8c46dde5bb70ab31e74f082c64f6e07fecc5cca177bbe0ccd5905007ef05a7ea2330cb793f8492b806135c829181e69b4c78f1a72f
|
7
|
+
data.tar.gz: e363765d799eecc8a95554fee499462431c43043e857ef6030ca024ecf65727c69a61c5b330260d799a487a5ff68dea7b59558daab8d8c7912dc9791b8e1ad74
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Sushma Satish
|
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
|
+
# ColouredLogger
|
2
|
+
|
3
|
+
Coloured Logger provides a handy way to colorize your logs based on the log severity: (debug, info, warn, error, fatal, unknown, perf)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'coloured_logger'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install coloured_logger
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
ColouredLogger::CLogger.debug("method_or_task_name","message to be logged")
|
25
|
+
ColouredLogger::CLogger.info("method_or_task_name","message to be logged")
|
26
|
+
ColouredLogger::CLogger.warn("method_or_task_name","message to be logged")
|
27
|
+
ColouredLogger::CLogger.error("method_or_task_name","message to be logged")
|
28
|
+
ColouredLogger::CLogger.fatal("method_or_task_name","message to be logged")
|
29
|
+
ColouredLogger::CLogger.unknown("method_or_task_name","message to be logged")
|
30
|
+
start_time = Time.now.ago(10.minute)
|
31
|
+
ColouredLogger::CLogger.log_time("method_or_task_name",start_time,"to finish job")
|
32
|
+
```
|
33
|
+
|
34
|
+

|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
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).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sushmasatish/coloured_logger.
|
45
|
+
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
50
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "coloured_logger"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coloured_logger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "coloured_logger"
|
8
|
+
spec.version = ColouredLogger::VERSION
|
9
|
+
spec.authors = ["Sushma Satish"]
|
10
|
+
spec.email = ["sushmasatish@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provides a handy tool to colorize logs.}
|
13
|
+
spec.description = %q{Using coloured logger, now all your logs are coloured based on their severity.}
|
14
|
+
spec.homepage = "https://github.com/sushmasatish/coloured_logger"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
Binary file
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'active_support/all'
|
3
|
+
require 'coloured_logger/version'
|
4
|
+
require 'coloured_logger/logger'
|
5
|
+
|
6
|
+
module ColouredLogger
|
7
|
+
class CLogger
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
attr_reader :logger
|
11
|
+
|
12
|
+
SEVERITY_TO_COLOR_MAP = {'DEBUG'=>'36', 'INFO'=>'32', 'WARN'=>'33', 'ERROR'=>'31', 'FATAL'=>'31', 'UNKNOWN'=>'37', 'PERF'=>'35'}
|
13
|
+
SEVERITY_TO_BACKGROUND_COLOR_MAP = {'DEBUG'=>'0', 'INFO'=>'0', 'WARN'=>'0', 'ERROR'=>'0', 'FATAL'=>'103', 'UNKNOWN'=>'0', 'PERF'=>'0'}
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@logger = Logger.new(STDOUT)
|
17
|
+
# Logger.LEVEL = DEBUG - logs all levels, INFO - would not log debug level.
|
18
|
+
@logger.level = Logger::DEBUG
|
19
|
+
@logger.formatter = proc do |severity, time, progname, msg|
|
20
|
+
formatted_severity = sprintf("%-5s",severity.to_s)
|
21
|
+
formatted_time = sprintf("[%s]", time.strftime("%Y-%m-%d %H:%M:%S"))
|
22
|
+
date_color ='1;34'
|
23
|
+
severity_color = SEVERITY_TO_COLOR_MAP[severity]
|
24
|
+
background_color = SEVERITY_TO_BACKGROUND_COLOR_MAP[severity]
|
25
|
+
"\033[#{date_color}m#{formatted_time} \033[#{background_color};#{severity_color}m#{formatted_severity}\033[0m-- #{msg.to_s.strip}\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def formatted_method(method)
|
30
|
+
sprintf("%-20s", method)
|
31
|
+
end
|
32
|
+
|
33
|
+
# low-level information for developers
|
34
|
+
def self.debug(method, message)
|
35
|
+
formatted_method = CLogger.instance.formatted_method(method)
|
36
|
+
CLogger.instance.logger.debug("#{formatted_method}: #{message}")
|
37
|
+
end
|
38
|
+
|
39
|
+
# generic (useful) information about system operation
|
40
|
+
def self.info(method, message)
|
41
|
+
formatted_method = CLogger.instance.formatted_method(method)
|
42
|
+
CLogger.instance.logger.info("#{formatted_method}: #{message}")
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.warn(method, message)
|
46
|
+
formatted_method = CLogger.instance.formatted_method(method)
|
47
|
+
CLogger.instance.logger.warn("#{formatted_method}: #{message}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.error(method, message)
|
51
|
+
formatted_method = CLogger.instance.formatted_method(method)
|
52
|
+
CLogger.instance.logger.error("#{formatted_method}: #{message}")
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.fatal(method, message)
|
56
|
+
formatted_method = CLogger.instance.formatted_method(method)
|
57
|
+
CLogger.instance.logger.fatal("#{formatted_method}: #{message}")
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.unknown(method, message)
|
61
|
+
formatted_method = CLogger.instance.formatted_method(method)
|
62
|
+
CLogger.instance.logger.unknown("#{formatted_method}: #{message}")
|
63
|
+
end
|
64
|
+
|
65
|
+
# Logs time taken to execute a task
|
66
|
+
def self.log_time(method, start_time, task_name)
|
67
|
+
end_time = Time.now
|
68
|
+
formatted_method = CLogger.instance.formatted_method(method)
|
69
|
+
time_taken = end_time - start_time
|
70
|
+
formatted_time_taken = sprintf("[%.4f sec]", time_taken)
|
71
|
+
CLogger.instance.logger.perf("#{formatted_method}: Time taken to #{task_name} - \033[35m#{formatted_time_taken}\033[0m")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
def self.custom_level(tag)
|
5
|
+
SEV_LABEL << tag
|
6
|
+
idx = SEV_LABEL.size - 1
|
7
|
+
|
8
|
+
define_method(tag.downcase.gsub(/\W+/, '_').to_sym) do |progname, &block|
|
9
|
+
add(idx, nil, progname, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Adding PERF custom level
|
14
|
+
custom_level 'PERF'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coloured_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sushma Satish
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-09 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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Using coloured logger, now all your logs are coloured based on their
|
70
|
+
severity.
|
71
|
+
email:
|
72
|
+
- sushmasatish@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- coloured_logger.gemspec
|
87
|
+
- docs/demo_output.png
|
88
|
+
- lib/coloured_logger.rb
|
89
|
+
- lib/coloured_logger/logger.rb
|
90
|
+
- lib/coloured_logger/version.rb
|
91
|
+
homepage: https://github.com/sushmasatish/coloured_logger
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Provides a handy tool to colorize logs.
|
115
|
+
test_files: []
|