itslog 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,12 @@
1
1
  require 'rails'
2
2
  require 'itslog/railtie'
3
- require 'itslog/formatter'
3
+ require 'itslog/configure'
4
+ require 'itslog/extension'
5
+
6
+ module Itslog
7
+ extend self
8
+
9
+ def configure(&block)
10
+ Itslog::Configure.configure(&block)
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ module Itslog
2
+ module Configure
3
+ extend self
4
+ attr_accessor :format, :namespace_colors, :severity_colors, :color_by
5
+
6
+ def color_by
7
+ @color_by ||= :namespace
8
+ end
9
+
10
+ def format
11
+ @format ||= '%t %n %m'
12
+ end
13
+
14
+ def namespace_colors
15
+ @namespace_colors ||= {
16
+ 'action_controller' => "\e[32m",
17
+ 'active_record' => "\e[94m",
18
+ 'action_view' => "\e[36m"}
19
+ end
20
+
21
+ def severity_colors
22
+ @severity_colors ||= [ "\e[36m","\e[32m","\e[33m","\e[31m","\e[31m","\e[37m"]
23
+ end
24
+
25
+ def color(namespace, severity)
26
+ if self.color_by == :severity || severity > 1
27
+ self.severity_colors[severity].presence || "\e[37m"
28
+ elsif self.color_by == :namespace
29
+ self.namespace_colors[namespace].presence || "\e[37m"
30
+ else
31
+ raise 'itslog: configuration of color_by can only be :severity or :namespace'
32
+ end
33
+ end
34
+
35
+ def configure
36
+ yield self
37
+ end
38
+ end
39
+ end
@@ -1,6 +1,7 @@
1
1
  module Itslog
2
2
  module BufferedLoggerExtension
3
3
  extend ActiveSupport::Concern
4
+ include Itslog::Configure
4
5
  attr_accessor :namespace
5
6
 
6
7
  def namespace
@@ -9,19 +10,17 @@ module Itslog
9
10
 
10
11
  def add_with_format(severity, message = nil, progname = nil, &block)
11
12
  return if @level > severity
12
- colors = ["\e[36m","\e[32m","\e[33m","\e[31m","\e[31m","\e[37m"]
13
- time = Time.now.to_s(:db)
14
-
15
- msg = ''
16
- msg << colors[severity]
17
- msg << "#{time.split.first} " unless Rails.env.development? || Rails.env.test?
18
- msg << "#{time.split.last}"
19
- msg << " #{namespace}" if namespace.present?
20
- msg << ': '
21
- msg << colors[5]
22
- msg << message.to_s.strip
23
-
24
- add_without_format(severity, msg, progname, &block)
13
+
14
+ time = Time.now.to_s(:db).split.last
15
+ message = "\e[37m" + message.to_s.strip
16
+ msg = ''
17
+ msg << Itslog::Configure.color(namespace, severity)
18
+ msg << Itslog::Configure.format.dup
19
+ {'%t' => time, '%n' => namespace, '%m' => message}.each do |k,v|
20
+ msg.gsub! k, v if v.present?
21
+ end
22
+
23
+ add_without_format severity, msg, progname, &block
25
24
  end
26
25
 
27
26
  included do
@@ -1,3 +1,3 @@
1
1
  module Itslog
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itslog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Thomas Marino
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-05 00:00:00 -04:00
18
+ date: 2011-05-24 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: "\n `itslog` is a log formatter designed to aid rails development.\n\n The formatting will prepend all log statements with a colored header and additional information about the statement.\n\n [timestamp] [rails namespace]: [normal log], example:\n\n 15:16:32 action_view: Rendered layouts/_head.haml (8.5ms)\n\n In addition to more readable logs you can tail and grep specific parts of your application. example:\n\n tail -f log/development.log | grep active_record\n "
22
+ description: "\n `itslog` is a log formatter designed to aid rails 3 development.\n "
23
23
  email: writejm@gmail.com
24
24
  executables: []
25
25
 
@@ -31,7 +31,8 @@ files:
31
31
  - README.md
32
32
  - Rakefile
33
33
  - LICENSE
34
- - lib/itslog/formatter.rb
34
+ - lib/itslog/configure.rb
35
+ - lib/itslog/extension.rb
35
36
  - lib/itslog/railtie.rb
36
37
  - lib/itslog/version.rb
37
38
  - lib/itslog.rb
@@ -68,6 +69,6 @@ rubyforge_project: itslog
68
69
  rubygems_version: 1.3.7
69
70
  signing_key:
70
71
  specification_version: 3
71
- summary: itslog makes logs more useful for rails development
72
+ summary: itslog makes logs more useful for rails 3 development.
72
73
  test_files: []
73
74