meow-logger 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in meow-logger.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kristjan Rang
2
+
3
+ MIT License
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.md ADDED
@@ -0,0 +1,13 @@
1
+ # MeowLogger
2
+
3
+ Overrides Rails' built in logger to send all logs to stdout with colors similar to Heroku
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'meow_logger'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "meow-logger/version"
2
+ require "meow-logger/railtie" if defined?(Rails)
@@ -0,0 +1,37 @@
1
+ module Meow
2
+ module Logger
3
+ class Formatter
4
+ SEVERITY_TO_COLOR_MAP =
5
+ { 'DEBUG'=>'0;37',
6
+ 'INFO'=>'32',
7
+ 'WARN'=>'33',
8
+ 'ERROR'=>'31',
9
+ 'FATAL'=>'31',
10
+ 'UNKNOWN'=>'37'}
11
+
12
+ def call(severity, time, progname, msg)
13
+ formatted_severity = sprintf("%-5s","#{severity}")
14
+
15
+ formatted_time =
16
+ time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3)
17
+
18
+ color = SEVERITY_TO_COLOR_MAP[severity]
19
+
20
+ "\033[0;37m#{formatted_time}\033[0m [\033[#{color}m#{formatted_severity}\033[0m] #{msg.strip} (pid:#{$$})\n"
21
+ end
22
+ end
23
+
24
+ class Rails
25
+ def self.stdout_logger
26
+ logger = Logger.new(STDOUT)
27
+ logger.level = Logger.const_get(([ENV['LOG_LEVEL'].to_s.upcase, "INFO"] & %w[DEBUG INFO WARN ERROR FATAL UNKNOWN]).compact.first)
28
+ logger.formatter = Formatter.new
29
+ logger
30
+ end
31
+
32
+ def self.set_logger
33
+ STDOUT.sync = true
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,12 @@
1
+ require 'meow-logger/rails'
2
+
3
+ module Meow
4
+ module Logger
5
+ class Rails3 < Rails
6
+ def self.set_logger(config)
7
+ super()
8
+ ::Rails.logger = config.logger = stdout_logger
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'meow_logger/rails3'
2
+
3
+ module Meow
4
+ module Logger
5
+ class Railtie < ::Rails::Railtie
6
+ config.after_initialize do
7
+ Rails3.set_logger(config)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Meow
2
+ module Logger
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'meow-logger/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "meow-logger"
8
+ gem.version = Meow::Logger::VERSION
9
+ gem.authors = ["Kristjan Rang"]
10
+ gem.email = ["mail@kristjanrang.eu"]
11
+ gem.description = %q{Custom Rails logger to stdout}
12
+ gem.summary = %q{Overrides Rails' built in logger to send all logs to stdout with colors}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meow-logger
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Kristjan Rang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Custom Rails logger to stdout
15
+ email:
16
+ - mail@kristjanrang.eu
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/meow-logger.rb
27
+ - lib/meow-logger/rails.rb
28
+ - lib/meow-logger/rails3.rb
29
+ - lib/meow-logger/railtie.rb
30
+ - lib/meow-logger/version.rb
31
+ - meow-logger.gemspec
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ none: false
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.23
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Overrides Rails' built in logger to send all logs to stdout with colors
56
+ test_files: []