turner_logs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in turner_logs.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,58 @@
1
+ =begin
2
+ Add colors to logger statements
3
+
4
+ e.g.
5
+ Rails.logger.debug "<b>This <c!>is <g>a <G>test"
6
+
7
+ lowercase - font color
8
+ uppercase - background color
9
+
10
+ k => black
11
+ r => red
12
+ g => green
13
+ y => yellow
14
+ b => blue
15
+ m => magenta
16
+ c => cyan
17
+ w => white
18
+ ! => <bright/bold>
19
+ =end
20
+
21
+ module ActiveSupport
22
+ class BufferedLogger
23
+
24
+ def add(severity, message = nil, progname = nil, &block)
25
+ return if @level > severity
26
+ message = (message || (block && block.call) || progname).to_s
27
+ message = colorize_message(message)
28
+ # If a newline is necessary then create a new message ending with a newline.
29
+ # Ensures that the original message is not mutated.
30
+ message = "#{message}\n" unless message[1] == "\n"
31
+ buffer << message
32
+ auto_flush
33
+ message
34
+ end
35
+
36
+ private
37
+ def colorize_message(message)
38
+ return if message.blank?
39
+ message.gsub!(/<([a-zA-Z!]*)[\/]*>/) {|color| color_to_code($1)}
40
+ message << color_to_code('Z') # always reset at the end of each line
41
+ end
42
+
43
+ @@_color_map = {
44
+ 'k' => 30, 'K' => 40,
45
+ 'r' => 31, 'R' => 41,
46
+ 'g' => 32, 'G' => 42,
47
+ 'y' => 33, 'Y' => 43,
48
+ 'b' => 34, 'B' => 44,
49
+ 'm' => 35, 'M' => 45,
50
+ 'c' => 36, 'C' => 46,
51
+ 'w' => 37, 'W' => 47,
52
+ '!' => 1
53
+ }
54
+ def color_to_code(color)
55
+ "\e[0;#{color.split('').map{|c| @@_color_map[c]}.compact.join(';')}m"
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module TurnerLogs
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ ## Turner Logs
2
+
3
+ Colorize your B&W Rails logs
4
+
5
+ # example
6
+
7
+ e.g.
8
+ Rails.logger.debug "<b>This <c!>is <g>a <G>test"
9
+
10
+ # The Codex
11
+
12
+ lowercase - font color
13
+ uppercase - background color
14
+
15
+ k => black
16
+ r => red
17
+ g => green
18
+ y => yellow
19
+ b => blue
20
+ m => magenta
21
+ c => cyan
22
+ w => white
23
+ ! => <bright/bold>
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "turner_logs/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "turner_logs"
7
+ s.version = TurnerLogs::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ben Sharpe"]
10
+ s.email = ["me@bsharpe.com"]
11
+ s.homepage = "http://bsharpe.com"
12
+ s.summary = %q{Colorize your B&W Rails logs}
13
+ s.description = %q{Support for color escape codes in the Rails logger}
14
+
15
+ s.rubyforge_project = "turner_logs"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turner_logs
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Ben Sharpe
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-08 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Support for color escape codes in the Rails logger
22
+ email:
23
+ - me@bsharpe.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - Rakefile
34
+ - lib/turner_logs.rb
35
+ - lib/turner_logs/version.rb
36
+ - readme.md
37
+ - turner_logs.gemspec
38
+ has_rdoc: true
39
+ homepage: http://bsharpe.com
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project: turner_logs
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Colorize your B&W Rails logs
70
+ test_files: []
71
+