logger-colors 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT LICENSE
2
+
3
+ Copyright (c) 2011 Jan Lelis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,7 @@
1
+ Colorizes the output of the standard library logger, depending on the logger level:
2
+
3
+ require 'logger/colors'
4
+
5
+ To adjust the colors, look at Logger::Colors::SCHEMA and Logger::Colors::constants
6
+
7
+ J-_-L
@@ -0,0 +1,29 @@
1
+ require 'rake'
2
+ require 'fileutils'
3
+ GEMSPEC = 'logger-colors.gemspec'
4
+
5
+ def gemspec
6
+ @gemspec ||= eval(File.read(GEMSPEC), binding, GEMSPEC)
7
+ end
8
+
9
+ desc "Build the gem"
10
+ task :gem => :gemspec do
11
+ sh "gem build " + GEMSPEC
12
+ FileUtils.mkdir_p 'pkg'
13
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
14
+ end
15
+
16
+ desc "Install the gem locally"
17
+ task :install => :gem do
18
+ sh %{gem install pkg/#{gemspec.name}-#{gemspec.version} --no-rdoc --no-ri}
19
+ end
20
+
21
+ desc "Generate the gemspec"
22
+ task :generate do
23
+ puts gemspec.to_ruby
24
+ end
25
+
26
+ desc "Validate the gemspec"
27
+ task :gemspec do
28
+ gemspec.validate
29
+ end
@@ -0,0 +1,56 @@
1
+ # Colorizes the output of the standard library logger, depending on the logger level:
2
+ #
3
+ # require 'logger/colors'
4
+ #
5
+ # To adjust the colors, look at Logger::Colors::SCHEMA and Logger::Colors::constants
6
+
7
+ require 'logger'
8
+
9
+ class Logger
10
+ module Colors
11
+ VERSION = '1.0.0'
12
+
13
+ NOTHING = '0;0'
14
+ BLACK = '0;30'
15
+ RED = '0;31'
16
+ GREEN = '0;32'
17
+ BROWN = '0;33'
18
+ BLUE = '0;34'
19
+ PURPLE = '0;35'
20
+ CYAN = '0;36'
21
+ LIGHT_GRAY = '0;37'
22
+ DARK_GRAY = '1;30'
23
+ LIGHT_RED = '1;31'
24
+ LIGHT_GREEN = '1;32'
25
+ YELLOW = '1;33'
26
+ LIGHT_BLUE = '1;34'
27
+ LIGHT_PURPLE = '1;35'
28
+ LIGHT_CYAN = '1;36'
29
+ WHITE = '1;37'
30
+
31
+ SCHEMA = {
32
+ STDOUT => %w[nothing green brown red purple cyan],
33
+ STDERR => %w[nothing green yellow light_red light_purple light_cyan],
34
+ }
35
+ end
36
+ end
37
+
38
+ class Logger
39
+ alias format_message_colorless format_message
40
+
41
+ def format_message(level, *args)
42
+ if Logger::Colors::SCHEMA[@logdev.dev]
43
+ color = begin
44
+ Logger::Colors.const_get \
45
+ Logger::Colors::SCHEMA[@logdev.dev][Logger.const_get(level.sub "ANY","UNKNOWN")].to_s.upcase
46
+ rescue NameError
47
+ "0;0"
48
+ end
49
+ "\e[#{ color }m#{ format_message_colorless(level, *args) }\e[0;0m"
50
+ else
51
+ format_message_colorless(level, *args)
52
+ end
53
+ end
54
+ end
55
+
56
+ # J-_-L
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rubygems' unless defined? Gem
3
+ require File.dirname(__FILE__) + "/lib/logger/colors"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "logger-colors"
7
+ s.version = Logger::Colors::VERSION
8
+ s.author = "Jan Lelis"
9
+ s.email = "mail@janlelis.de"
10
+ s.homepage = "https://gist.github.com/962344"
11
+ s.summary = "Colorful stdlib logger levels."
12
+ s.description = "Colorizes the output of the usual standard library logger, depending on the logger level: require 'logger/colors'"
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+ s.files = Dir.glob(%w[lib/**/*.rb]) + %w{README LICENSE Rakefile logger-colors.gemspec}
15
+ s.license = 'MIT'
16
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logger-colors
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Jan Lelis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-09 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: "Colorizes the output of the usual standard library logger, depending on the logger level: require 'logger/colors'"
17
+ email: mail@janlelis.de
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/logger/colors.rb
26
+ - README
27
+ - LICENSE
28
+ - Rakefile
29
+ - logger-colors.gemspec
30
+ homepage: https://gist.github.com/962344
31
+ licenses:
32
+ - MIT
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.3.6
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.0
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Colorful stdlib logger levels.
57
+ test_files: []
58
+