hatchet 0.0.7 → 0.0.8
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/lib/hatchet/simple_formatter.rb +28 -0
- data/lib/hatchet/standard_formatter.rb +4 -2
- data/lib/hatchet/version.rb +1 -1
- data/lib/hatchet.rb +1 -0
- data/spec/configuration_spec.rb +1 -1
- data/spec/helpers/{simple_formatter.rb → test_formatter.rb} +1 -1
- data/spec/logger_appender_spec.rb +1 -1
- data/spec/simple_formatter_spec.rb +18 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/standard_formatter_spec.rb +14 -0
- metadata +8 -5
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Hatchet
|
4
|
+
|
5
|
+
# Public: Simple formatter class. Outputs messages with just level, context,
|
6
|
+
# and message.
|
7
|
+
#
|
8
|
+
class SimpleFormatter
|
9
|
+
|
10
|
+
# Public: Returns the formatted message.
|
11
|
+
#
|
12
|
+
# level - The severity of the log message.
|
13
|
+
# context - The context of the log message.
|
14
|
+
# message - The message provided by the log caller.
|
15
|
+
#
|
16
|
+
# Returns messages in the format:
|
17
|
+
#
|
18
|
+
# LEVEL - CONTEXT - MESSAGE
|
19
|
+
#
|
20
|
+
def format(level, context, message)
|
21
|
+
message = message.to_s.strip
|
22
|
+
"#{level.to_s.upcase} - #{context} - #{message}"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Hatchet
|
4
4
|
|
5
|
-
# Public: Standard formatter class.
|
5
|
+
# Public: Standard formatter class. Outputs messages in the TTCC of log4j.
|
6
6
|
#
|
7
7
|
class StandardFormatter
|
8
8
|
|
@@ -16,7 +16,9 @@ module Hatchet
|
|
16
16
|
# context - The context of the log message.
|
17
17
|
# message - The message provided by the log caller.
|
18
18
|
#
|
19
|
-
# Returns
|
19
|
+
# Returns messages in the format:
|
20
|
+
#
|
21
|
+
# %Y-%m-%d %H:%M:%S.%L [THREAD] LEVEL CONTEXT - MESSAGE
|
20
22
|
#
|
21
23
|
def format(level, context, message)
|
22
24
|
message = message.to_s.strip
|
data/lib/hatchet/version.rb
CHANGED
data/lib/hatchet.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative 'hatchet/configuration'
|
|
5
5
|
require_relative 'hatchet/hatchet_logger'
|
6
6
|
require_relative 'hatchet/logger_appender'
|
7
7
|
require_relative 'hatchet/message'
|
8
|
+
require_relative 'hatchet/simple_formatter'
|
8
9
|
require_relative 'hatchet/standard_formatter'
|
9
10
|
require_relative 'hatchet/version'
|
10
11
|
|
data/spec/configuration_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe 'configuration' do
|
|
32
32
|
describe 'appender overrides' do
|
33
33
|
let(:default_levels) { { unique: :fake_level } }
|
34
34
|
let(:appender_levels) { { appender: :faker_level } }
|
35
|
-
let(:appender_formatter) {
|
35
|
+
let(:appender_formatter) { TestFormatter.new }
|
36
36
|
let(:appender) do
|
37
37
|
StoringAppender.new do |app|
|
38
38
|
app.levels = appender_levels
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require_relative 'spec_helper'
|
4
|
+
|
5
|
+
describe SimpleFormatter do
|
6
|
+
let(:subject) { SimpleFormatter.new }
|
7
|
+
|
8
|
+
describe 'when formatting a message' do
|
9
|
+
before do
|
10
|
+
@message = subject.format(:info, 'Custom::Context', 'Hello, World')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'outputs the message in the LEVEL CONTEXT - MESSAGE format' do
|
14
|
+
assert 'INFO - Custom::Context - Hello, World' == @message, "got #{@message}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -8,7 +8,7 @@ require_relative '../lib/hatchet'
|
|
8
8
|
include Hatchet
|
9
9
|
|
10
10
|
require_relative 'helpers/logger_double'
|
11
|
-
require_relative 'helpers/
|
11
|
+
require_relative 'helpers/test_formatter'
|
12
12
|
require_relative 'helpers/storing_appender'
|
13
13
|
|
14
14
|
INITIAL_EXECUTION_CONTEXT = self
|
@@ -3,6 +3,20 @@
|
|
3
3
|
require_relative 'spec_helper'
|
4
4
|
require 'date'
|
5
5
|
|
6
|
+
describe SimpleFormatter do
|
7
|
+
let(:subject) { SimpleFormatter.new }
|
8
|
+
|
9
|
+
describe 'when formatting a message' do
|
10
|
+
before do
|
11
|
+
@message = subject.format(:info, 'Custom::Context', 'Hello, World')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'outputs the message in the LEVEL CONTEXT - MESSAGE format' do
|
15
|
+
assert 'INFO - Custom::Context - Hello, World' == @message, "got #{@message}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
6
20
|
describe StandardFormatter do
|
7
21
|
TIME_FORMAT = '%Y-%m-%d %H:%M:%S.%L'
|
8
22
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hatchet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Logging library that provides the ability to add class/module specific
|
15
15
|
filters
|
@@ -25,17 +25,19 @@ files:
|
|
25
25
|
- lib/hatchet/logger_appender.rb
|
26
26
|
- lib/hatchet/message.rb
|
27
27
|
- lib/hatchet/railtie.rb
|
28
|
+
- lib/hatchet/simple_formatter.rb
|
28
29
|
- lib/hatchet/standard_formatter.rb
|
29
30
|
- lib/hatchet/version.rb
|
30
31
|
- lib/hatchet.rb
|
31
32
|
- spec/configuration_spec.rb
|
32
33
|
- spec/helpers/logger_double.rb
|
33
|
-
- spec/helpers/simple_formatter.rb
|
34
34
|
- spec/helpers/storing_appender.rb
|
35
|
+
- spec/helpers/test_formatter.rb
|
35
36
|
- spec/level_manager_spec.rb
|
36
37
|
- spec/logger_appender_spec.rb
|
37
38
|
- spec/logger_spec.rb
|
38
39
|
- spec/message_spec.rb
|
40
|
+
- spec/simple_formatter_spec.rb
|
39
41
|
- spec/spec_helper.rb
|
40
42
|
- spec/standard_formatter_spec.rb
|
41
43
|
- LICENSE
|
@@ -59,18 +61,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
61
|
version: '0'
|
60
62
|
requirements: []
|
61
63
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.8.
|
64
|
+
rubygems_version: 1.8.17
|
63
65
|
signing_key:
|
64
66
|
specification_version: 3
|
65
67
|
summary: Logging library that provides the ability to add class/module specific filters
|
66
68
|
test_files:
|
67
69
|
- spec/configuration_spec.rb
|
68
70
|
- spec/helpers/logger_double.rb
|
69
|
-
- spec/helpers/simple_formatter.rb
|
70
71
|
- spec/helpers/storing_appender.rb
|
72
|
+
- spec/helpers/test_formatter.rb
|
71
73
|
- spec/level_manager_spec.rb
|
72
74
|
- spec/logger_appender_spec.rb
|
73
75
|
- spec/logger_spec.rb
|
74
76
|
- spec/message_spec.rb
|
77
|
+
- spec/simple_formatter_spec.rb
|
75
78
|
- spec/spec_helper.rb
|
76
79
|
- spec/standard_formatter_spec.rb
|