itslog 0.5.0 → 0.6.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.
data/README.md CHANGED
@@ -33,7 +33,7 @@ end
33
33
  Configure
34
34
  -----------
35
35
 
36
- Itslog does not need to be configured unless you want to customize the output structure and color.
36
+ Itslog does not need to be configured unless you want to customize the output structure and color.
37
37
 
38
38
  Example:
39
39
 
@@ -46,6 +46,8 @@ Itslog.configure do |config|
46
46
  'action_view' => "\e[36m"
47
47
  }
48
48
  config.format = "%t [%n]: %m"
49
+ config.message_color = "\e[37m"
50
+ config.timestamp_format = "%Y-%b-%d %H:%M:%S %z"
49
51
  end
50
52
  ```
51
53
 
@@ -55,6 +57,8 @@ Configure format by building a string anyway you'd like and using the following
55
57
  %n (namespace)
56
58
  %m (log message)
57
59
 
60
+ Configure time format using a strftime format string. [foragoodstrftime](http://www.foragoodstrftime.com/) is a nice reference.
61
+
58
62
  I don't recommend coloring by severity because it's not very useful. To color by severity instead of the default of namespace:
59
63
 
60
64
  ``` ruby
@@ -1,7 +1,7 @@
1
1
  module Itslog
2
2
  module Configure
3
3
  extend self
4
- attr_accessor :format, :namespace_colors, :severity_colors, :color_by
4
+ attr_accessor :format, :timestamp_format, :namespace_colors, :severity_colors, :message_color, :color_by
5
5
 
6
6
  def color_by
7
7
  @color_by ||= :namespace
@@ -23,6 +23,14 @@ module Itslog
23
23
  @severity_colors ||= [ "\e[36m","\e[32m","\e[33m","\e[31m","\e[31m","\e[37m"]
24
24
  end
25
25
 
26
+ def message_color
27
+ @message_color ||= "\e[37m"
28
+ end
29
+
30
+ def timestamp_format
31
+ @timestamp_format ||= '%H:%M:%S'
32
+ end
33
+
26
34
  def color(namespace, severity)
27
35
  if self.color_by == :severity || severity > 1
28
36
  self.severity_colors[severity].presence || "\e[37m"
@@ -39,8 +47,9 @@ module Itslog
39
47
 
40
48
  def reset
41
49
  configure do |config|
42
- config.color_by = :namespace
43
- config.format = '%t %n_%m'
50
+ config.color_by = :namespace
51
+ config.format = '%t %n_%m'
52
+ config.message_color = "\e[37m"
44
53
  config.namespace_colors = {
45
54
  'action_controller' => "\e[32m",
46
55
  'active_record' => "\e[94m",
@@ -48,6 +57,7 @@ module Itslog
48
57
  'action_view' => "\e[36m"}
49
58
  config.severity_colors = [
50
59
  "\e[36m","\e[32m","\e[33m","\e[31m","\e[31m","\e[37m"]
60
+ config.timestamp_format = '%H:%M:%S'
51
61
  end
52
62
  end
53
63
  end
@@ -11,8 +11,8 @@ module Itslog
11
11
  def add_with_format(severity, message = nil, progname = nil, &block)
12
12
  return if @level > severity || message.nil?
13
13
 
14
- time = Time.now.to_s(:db).split.last
15
- message = "\e[37m" + message.to_s.strip
14
+ time = Time.now.strftime(Itslog::Configure.timestamp_format)
15
+ message = Itslog::Configure.message_color + message.to_s.strip
16
16
  msg = namespace.present? ? '' : "\n"
17
17
  msg << Itslog::Configure.color(namespace, severity)
18
18
  msg << Itslog::Configure.format.dup
@@ -1,3 +1,3 @@
1
1
  module Itslog
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
Binary file
@@ -1,2 +1,2 @@
1
1
 
2
- 01:01:01 test
2
+ 2011-Aug-16 01:01:01 -0400 test
data/test/helper.rb CHANGED
@@ -15,7 +15,7 @@ Itslog::Railtie.insert
15
15
 
16
16
  def assert_log(log, msg, severity=0, namespace=nil)
17
17
  level = [:debug, :info, :warn, :error, :fatal, :unknown]
18
- Timecop.freeze(Time.parse('01:01:01'))
18
+ Timecop.freeze(Time.parse('08/16/11 01:01:01'))
19
19
  file_name = File.dirname(__FILE__) + '/fixtures/log.txt'
20
20
  File.delete(file_name)
21
21
  Rails.logger = ActiveSupport::BufferedLogger.new(file_name)
data/test/itslog_test.rb CHANGED
@@ -57,4 +57,23 @@ class ItslogTest < Test::Unit::TestCase
57
57
  assert_log "\n\e[37m[] \e[37mtest\n", 'test', 0
58
58
  assert_log "\e[32m[action_controller] \e[37mtest\n", 'test', 0, 'action_controller'
59
59
  end
60
+
61
+ def test_default_message_color
62
+ Itslog::Configure.reset
63
+ assert_log "\e[32m01:01:01 action_controller \e[37mtest\n", 'test', 0, 'action_controller'
64
+ end
65
+
66
+ def test_custom_message_color
67
+ Itslog::Configure.reset
68
+ Itslog.configure do |config|
69
+ config.message_color = 'black'
70
+ end
71
+ assert_log "\e[32m01:01:01 action_controller blacktest\n", 'test', 0, 'action_controller'
72
+ end
73
+
74
+ def test_custom_timestamp_format
75
+ Itslog::Configure.reset
76
+ Itslog.configure { |config| config.timestamp_format = '%m-%e-%y %H:%M' }
77
+ assert_log "\n\e[37m08-16-11 01:01 \e[37mtest\n", 'test', 0
78
+ end
60
79
  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: 11
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
8
+ - 6
9
9
  - 0
10
- version: 0.5.0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Thomas Marino
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-28 00:00:00 -04:00
19
- default_executable:
18
+ date: 2011-08-16 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description: "\n `itslog` is a log formatter designed to aid rails 3 development.\n "
@@ -42,7 +41,6 @@ files:
42
41
  - test/fixtures/schema.rb
43
42
  - test/helper.rb
44
43
  - test/itslog_test.rb
45
- has_rdoc: true
46
44
  homepage: http://github.com/johmas/itslog
47
45
  licenses: []
48
46
 
@@ -72,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
70
  requirements: []
73
71
 
74
72
  rubyforge_project: itslog
75
- rubygems_version: 1.3.7
73
+ rubygems_version: 1.8.6
76
74
  signing_key:
77
75
  specification_version: 3
78
76
  summary: itslog makes logs more useful for rails 3 development.