humorous_log_formatter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75017446ad553bc703ef510dc89d9253513c1d58
4
- data.tar.gz: 6125691606998008ccac484f28a95b2a4c972dd8
3
+ metadata.gz: a61d81a7088603de9ecc0371591a2e1420b29b03
4
+ data.tar.gz: 4d137e11ddc5aabe10e4ac3ef28f47715aa75dbb
5
5
  SHA512:
6
- metadata.gz: 904b862ab91785b7b70298ea848a5c8670e4e0db4b8526a376a4d4cdd53015de7a4a75697a68fd29eddadf80e56975a29427dc8d53d6cebf0470b168e5b641d3
7
- data.tar.gz: 7a6a79620121411e6aada2624978994b6b6b3db4d441d57654ab20addfdaaed7430ca98177f4dc7acbf15867b04142cc82390d06dbfe88545627c1d62439b1b2
6
+ metadata.gz: 953f58cb2aeee4e482dcfe17bae9ca7798277d4e21e7c90011f2953a58b64d48b0ede82181cbaab085e1f26690b2be534da8cae21b47bb9d76c0255b2b159580
7
+ data.tar.gz: e5bce548d857cd8b765c06645d6b979cf153af9131dc4450ecd5da6b07ad7e68902eb2b120fef32b3d757c84d735b1ac783c02e892cb383e98426224d419fd0c
data/README.md CHANGED
@@ -1,13 +1,17 @@
1
1
  # HumorousLogFormatter
2
2
 
3
- You want Humorous Log Levels and Color (in Rails development)? Can chickens turtle all the way down? Of course!
3
+ You want Humorous Log Levels and Color? Can chickens turtle all the way down? Of course!
4
+
5
+ Works with Rails 3 & 4!
4
6
 
5
7
  ## Installation
6
8
 
7
- Add this line to your application's Gemfile:
9
+ Add this line to your application's Gemfile in the `:development` group, or wherever else you want awesome logs:
8
10
 
9
11
  ```ruby
10
- gem 'humorous_log_formatter'
12
+ group :development do
13
+ gem 'humorous_log_formatter'
14
+ end
11
15
  ```
12
16
 
13
17
  And then execute:
@@ -20,6 +24,9 @@ Or install it yourself as:
20
24
 
21
25
  ## Usage
22
26
 
27
+ * There is ZERO configuration. It makes some assumptions.
28
+ * Putting the gem in your Gemfile and restart your app.
29
+ * Now you have beautiful logs.
23
30
  * Use the source.
24
31
  * There are a bunch of CONSTANTS defined in the code, and everything this gem does is driven by them.
25
32
  * Override them for magic.
@@ -10,10 +10,21 @@ require "humorous_log_formatter/version"
10
10
 
11
11
  module HumorousLogFormatter
12
12
  class LogFormatter
13
- # TODO: For Rails 4, uncomment the line below
14
- #include ActiveSupport::TaggedLogging::Formatter
13
+
14
+ # Make it work with Rails 4
15
+ if defined?(Rails)
16
+ if ::Rails::VERSION::MAJOR >= 4
17
+ include ActiveSupport::TaggedLogging::Formatter
18
+ end
19
+ end
20
+
15
21
  SEVERITY_TO_TAG_MAP = {'DEBUG' => 'meh', 'INFO' => 'fyi', 'WARN' => 'hmm', 'ERROR' => 'wtf', 'FATAL' => 'omg', 'UNKNOWN' => '???'}
16
22
  SEVERITY_TO_COLOR_MAP = {'DEBUG' => '0;37', 'INFO' => '32', 'WARN' => '33', 'ERROR' => '31', 'FATAL' => '31', 'UNKNOWN' => '37'}
23
+ TIME_FORMAT = "%Y-%m-%d %H:%M:%S."
24
+ SKIP_TIME = !Rails.env.development? # because heroku already prints the time, override if you use in prod and aren't on Heroku
25
+ SUPER_TIME_PRECISION = 3
26
+ SUPER_TIME_PRECISION_STOP_INDEX = SUPER_TIME_PRECISION - 1
27
+ USE_SUPER_TIME = SUPER_TIME_PRECISION > 0
17
28
  USE_HUMOROUS_SEVERITIES = begin
18
29
  if ENV['LOG_HUMOR']
19
30
  ENV['LOG_HUMOR'] != 'false' # Default to true
@@ -38,20 +49,24 @@ module HumorousLogFormatter
38
49
  FORMATTED_MESSAGE = if USE_COLOR
39
50
  lambda { |severity, formatted_time, msg|
40
51
  color = SEVERITY_TO_COLOR_MAP[severity]
41
- "[\033[#{color}m#{formatted_time}\033[0m] [\033[#{color}m#{FORMATTED_SEVERITY.call(severity)}\033[0m] #{msg.strip}\n"
52
+ res = ''
53
+ res << "[\033[#{color}m#{formatted_time}\033[0m] " if formatted_time
54
+ res << "[\033[#{color}m#{FORMATTED_SEVERITY.call(severity)}\033[0m] #{msg.strip}\n"
42
55
  }
43
56
  else
44
57
  lambda { |severity, formatted_time, msg|
45
- "[#{formatted_time}] [#{FORMATTED_SEVERITY.call(severity)}] #{msg.strip}\n"
58
+ res = ''
59
+ res << "[#{formatted_time}]" if formatted_time
60
+ res << "[#{FORMATTED_SEVERITY.call(severity)}] #{msg.strip}\n"
46
61
  }
47
62
  end
48
63
 
49
64
  def exception_values(e)
50
65
  trace = e.backtrace.select { |x| !line.starts_with?(THIS_FILE_PATH) }
51
66
  trace = trace.map { |l| colorize_exception(l) } if USE_COLOR
52
- first = "\n" + trace.first + ": " + e.message + " (#{e.class})"
53
- rest = "\t" + trace[1..-1].join("\n\t")
54
- return first + "\n" + rest
67
+ first = "\n#{trace.first}: #{e.message} (#{e.class})"
68
+ rest = "\t#{trace[1..-1].join("\n\t")}"
69
+ "#{first}\n#{rest}"
55
70
  end
56
71
 
57
72
  def colorize_exception(line)
@@ -59,13 +74,18 @@ module HumorousLogFormatter
59
74
  end
60
75
 
61
76
  def call(severity, time, progname, msg)
62
- formatted_time = time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3)
77
+ if SKIP_TIME
78
+ formatted_time = nil
79
+ else
80
+ formatted_time = time.strftime(TIME_FORMAT)
81
+ formatted_time << time.usec.to_s[0..(SUPER_TIME_PRECISION_STOP_INDEX)].rjust(SUPER_TIME_PRECISION) if USE_SUPER_TIME
82
+ end
63
83
  text = if msg.is_a? String
64
84
  msg
65
85
  elsif msg.is_a? Exception
66
- " --> Exception: " + exception_values(msg)
86
+ " --> Exception:#{exception_values(msg)}"
67
87
  else
68
- "!!!!! UNKNOWN TYPE: #{msg.class}" + msg.to_s
88
+ "!!!!! UNKNOWN TYPE: #{msg.class} #{msg.to_s}"
69
89
  end
70
90
  FORMATTED_MESSAGE.call(severity, formatted_time, text)
71
91
  end
@@ -1,3 +1,3 @@
1
1
  module HumorousLogFormatter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humorous_log_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-16 00:00:00.000000000 Z
11
+ date: 2014-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.2.2
106
+ rubygems_version: 2.4.2
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Humorous Log Levels and Color For Rails.