wololo_formatter 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require "wololo_formatter/version"
2
2
  require "wololo_formatter/logger"
3
+ require "wololo_formatter/active_support"
3
4
 
4
5
  module WololoFormatter
5
6
  end
@@ -0,0 +1,33 @@
1
+ module ActiveSupport
2
+ class BufferedLogger
3
+ def add(severity, message = nil, progname = nil, &block)
4
+ return if @level > severity
5
+ severity_map = { 0=> "DEBUG", 1=> "INFO", 2=> "WARN", 3=> "ERROR", 4=> "FATAL", 5=> "UNKNOWN"}
6
+ severity = severity_map[severity]
7
+ time = ->{Time.now}.call
8
+ formatted_time = time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3)
9
+ message = "#{severity_color severity} \033[0;37m#{formatted_time}\033[0m #{String === message ? message : message.inspect} (pid:#{$$})\n"
10
+ buffer << message
11
+ auto_flush
12
+ message
13
+ end
14
+ private
15
+
16
+ def severity_color(severity)
17
+ case severity
18
+ when "DEBUG"
19
+ "\033[1;34;40m[DEBUG]\033[0m" # blue
20
+ when "INFO"
21
+ "\033[0;32;40m[INFO]\033[0m" # bold white
22
+ when "WARN"
23
+ "\033[0;33;40m[WARNING]\033[0m" # bold yellow
24
+ when "ERROR"
25
+ "\033[1;31;40m[ERROR]\033[0m" # bold red
26
+ when "FATAL"
27
+ "\033[7;31;40m[FATAL]\033[0m" # bold black, red bg
28
+ else
29
+ "[#{severity}]" # none
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module WololoFormatter
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wololo_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -56,6 +56,7 @@ files:
56
56
  - README.md
57
57
  - Rakefile
58
58
  - lib/wololo_formatter.rb
59
+ - lib/wololo_formatter/active_support.rb
59
60
  - lib/wololo_formatter/logger.rb
60
61
  - lib/wololo_formatter/version.rb
61
62
  - wololo_formatter.gemspec