filum 1.0.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmNkYjY1OWM5YzhjZDEyNmE3ZTgzMDhmYzhlOTdkNDhkY2I3NjY1MA==
4
+ NmRmOWQ4ZjJkNmJiZTIxZWRmN2MzYmJkNTEzNzgzZjJhZjBiNjI5Mw==
5
5
  data.tar.gz: !binary |-
6
- MzVkNDc3ZjBlMTMzODQyNDE5N2FjODBkYjJkYWRlMWEwNmZlNzk2Nw==
6
+ MGMxNGQwMmIyZTNkYzlmZjRjZjI4YWIzYTY2OTZmYzUzOTU3MWQ1ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzQ4YjMzMDQzNDIwODczNmYxMzMxZmMyMTQyMTkyN2ViMDliODQ0NmIyNjFk
10
- NGUxYzNkOWYzNDIxNGY5ZDljMjRlNjg4YzU4NWI3ZDViNzdkNTE2NzM4NmEw
11
- ZjRkOWRmMzdlNWQ0YTFlMjhkOWFjNWMyZDdlYjVhNWJhZGFlNmE=
9
+ YjU3ZTVmMmZjMGU4NDczM2M0NjE4OWMzMzBmZDE5OGFlNGJkNGM0ZGUxOWMz
10
+ ODE1ODU1NzNiM2Y5YjQ2NWY5NGRmYTQ2YmM3ZWE4ZDM1YmExZWE3NjY2MmU4
11
+ MDk0NDc4Njg2ZWJkZGNjMjQzNTRkZTMyZWJiOGU1Y2Y3OWMxYzU=
12
12
  data.tar.gz: !binary |-
13
- NjFiMGQzNGUzMDFiYjNjMmNlZjhlZWJkMGE3M2I2ZWQ3YjRjNGZmOGFlZGE2
14
- MjYxZGEwOGE2MDdmODllZDljMTZiMTBiNmU1NTZlN2I5NGYxODE5MTg3ZmI4
15
- NDFmOTNkOGQ2MjMwNGI2YjlhYzdkZGNhM2RmMjIxNmRjYWUwOTE=
13
+ ZmE2NGY5ZTE2NzQ0N2Y2OGJhMmU0MWNlMGUyM2M1N2ZhNjhkYjBhOTJjM2Jl
14
+ N2Y4ZjI5ZmRjZjZkZGQyZTZiZDg3YjdiODQ0NjkyYjI5MmI2MzRiZDYxNjk3
15
+ MGRhN2MwYTkyZGI5NGUzMzMwZWNmZmJkMmJmMzI0NWM4ODhkOTM=
@@ -1,3 +1,6 @@
1
+ 1.0.1 / 2013-12-13
2
+ [BUG_FIX] Rendering correct source file/line
3
+
1
4
  1.0.0 / 2013-12-11
2
5
  [RELEASE] API-stable release
3
6
 
@@ -1,6 +1,7 @@
1
1
  require "filum/version"
2
2
  require "filum/filum_error"
3
3
  require "filum/configuration"
4
+ require "filum/log_formatter"
4
5
  require "filum/logger"
5
6
 
6
7
  module Filum
@@ -0,0 +1,31 @@
1
+ require 'logger'
2
+
3
+ module Filum
4
+ class LogFormatter < Logger::Formatter
5
+ def call(severity, timestamp, progname, msg)
6
+ "#{timestamp} thread_id-#{Thread.current.object_id} [#{formatted_context_id}] #{severity} | #{formatted_calling_file_and_line} | #{msg}\n"
7
+ end
8
+
9
+ private
10
+ def formatted_context_id
11
+ context_id.ljust(Filum.config.context_id_length)
12
+ end
13
+
14
+ def context_id
15
+ Thread.current[:context_id].to_s
16
+ end
17
+
18
+ def formatted_calling_file_and_line
19
+ filename_length = Filum.config.filename_length
20
+ truncated_filename_length = filename_length - 3
21
+
22
+ _, file, line = calling_code.match(/([\w\.]+)\:(\d+)\:in /).to_a
23
+ file = "#{file[0,truncated_filename_length]}..." if file.length >= filename_length
24
+ "#{file}:#{line.ljust(3)}".ljust(filename_length + 4)
25
+ end
26
+
27
+ def calling_code
28
+ caller[5]
29
+ end
30
+ end
31
+ end
@@ -5,39 +5,11 @@ module Filum
5
5
 
6
6
  def initialize(*args)
7
7
  super
8
- self.formatter = Filum::Logger::Formatter.new
8
+ self.formatter = Filum::LogFormatter.new
9
9
  end
10
10
 
11
11
  def context_id=(context_id)
12
12
  Thread.current[:context_id] = context_id
13
13
  end
14
-
15
- class Formatter < Logger::Formatter
16
- def call(severity, timestamp, progname, msg)
17
- "#{timestamp} thread_id-#{Thread.current.object_id} [#{formatted_context_id}] #{severity} | #{formatted_calling_file_and_line} | #{msg}\n"
18
- end
19
-
20
- private
21
- def formatted_context_id
22
- context_id.ljust(Filum.config.context_id_length)
23
- end
24
-
25
- def context_id
26
- Thread.current[:context_id].to_s
27
- end
28
-
29
- def formatted_calling_file_and_line
30
- filename_length = Filum.config.filename_length
31
- truncated_filename_length = filename_length - 3
32
-
33
- _, file, line = calling_code.match(/([\w\.]+)\:(\d+)\:in /).to_a
34
- file = "#{file[0,truncated_filename_length]}..." if file.length >= filename_length
35
- "#{file}:#{line.ljust(3)}".ljust(filename_length + 4)
36
- end
37
-
38
- def calling_code
39
- caller[4]
40
- end
41
- end
42
14
  end
43
15
  end
@@ -1,3 +1,3 @@
1
1
  module Filum
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -34,8 +34,16 @@ module Filum
34
34
  end
35
35
 
36
36
  def test_info_string_is_correct
37
+ random_string = [*'a'..'z'].sample(10).join
38
+ Filum.logger.info "Foobar #{random_string}"
39
+ assert_logged(/Foobar #{random_string}$/)
40
+ end
41
+
42
+ def test_caller_line_is_correct
43
+ expected_file = 'logger_test.rb'
44
+ expected_line = __LINE__+1
37
45
  Filum.logger.info "Foobar"
38
- assert_logged(/Foobar$/)
46
+ assert_logged(/#{expected_file}:#{expected_line}/)
39
47
  end
40
48
 
41
49
  private
@@ -43,95 +51,4 @@ module Filum
43
51
  assert File.readlines(Filum.config.logfile).grep(regex).size == 1
44
52
  end
45
53
  end
46
-
47
- class LogFormatterTest < IntegrationTest
48
- def test_string_format
49
- formatter = Filum::Logger::Formatter.new
50
- severity = "SEV123"
51
- timestamp = "Timestamp123"
52
- msg = "My Message"
53
- context_id = "context_id"
54
- object_id = Thread.current.object_id
55
- file_and_line = "file_and_line"
56
- formatter.stubs(calling_file_and_line: file_and_line)
57
- Thread.current[:context_id] = context_id
58
-
59
- output = formatter.call(severity, timestamp, nil, msg)
60
- desired = "#{timestamp} thread_id-#{object_id} [#{context_id}] #{severity} | #{file_and_line} | #{msg}\n"
61
- assert_equal desired.strip.hex, output.strip.hex
62
- end
63
-
64
- def test_call_calls_formatted_context_id
65
- formatter = Filum::Logger::Formatter.new
66
- formatter.expects(:formatted_context_id)
67
- formatter.call("", "", "", "")
68
- end
69
-
70
- def test_formatted_context_id_uses_config
71
- Filum.config.context_id_length = 20
72
- context_id = "12345"
73
- Thread.current[:context_id] = context_id
74
- formatter = Filum::Logger::Formatter.new
75
- output = formatter.send(:formatted_context_id)
76
- assert_equal "#{context_id} ", output
77
- end
78
-
79
- def test_call_calls_formatted_calling_file_and_line
80
- formatter = Filum::Logger::Formatter.new
81
- formatter.expects(:formatted_calling_file_and_line)
82
- formatter.call("", "", "", "")
83
- end
84
-
85
- def test_call_should_not_truncate_context_id
86
- context_id = "context_id"
87
- Thread.current[:context_id] = context_id
88
- formatter = Filum::Logger::Formatter.new
89
- output = formatter.send(:formatted_context_id)
90
- assert_equal context_id, output
91
- end
92
-
93
- def test_call_should_return_fixed_width_context_id
94
- context_id = "1234"
95
- Thread.current[:context_id] = context_id
96
- formatter = Filum::Logger::Formatter.new
97
- output = formatter.send(:formatted_context_id)
98
- assert_equal "#{context_id} ", output
99
- end
100
-
101
- def test_calling_file_and_line_parses_correctly
102
- formatter = Filum::Logger::Formatter.new
103
- line = "/Users/iHiD/Projects/meducation/filum/lib/filum/logger.rb:30:in `formatted_calling_file_and_line'"
104
- formatter.stubs(calling_code: line)
105
- output = formatter.send(:formatted_calling_file_and_line)
106
- assert output =~ /logger\.rb:30\s*/
107
- end
108
-
109
- def test_formatted_calling_file_and_line_uses_config
110
- Filum.config.filename_length = 40
111
- filename = "abcdefghij"
112
- line = "/Users/iHiD/Projects/meducation/filum/lib/filum/#{filename}:30:in `formatted_calling_file_and_line'"
113
- formatter = Filum::Logger::Formatter.new
114
- formatter.stubs(calling_code: line)
115
- output = formatter.send(:formatted_calling_file_and_line)
116
- assert_equal "#{filename}:30 #{" " * 30}", output
117
- end
118
-
119
- def test_formatted_calling_file_and_line_should_truncate
120
- filename = "abcdefghijklmnopqrstuvwxyz1234"
121
- line = "/Users/iHiD/Projects/meducation/filum/lib/filum/#{filename}:30:in `formatted_calling_file_and_line'"
122
- formatter = Filum::Logger::Formatter.new
123
- formatter.stubs(calling_code: line)
124
- output = formatter.send(:formatted_calling_file_and_line)
125
- assert_equal "abcdefghijklmnopq...:30 ", output
126
- end
127
-
128
- def test_formatted_calling_file_and_line_should_pad
129
- filename = "foobar.txt"
130
- line = "/Users/iHiD/Projects/meducation/filum/lib/filum/#{filename}:30:in `formatted_calling_file_and_line'"
131
- formatter = Filum::Logger::Formatter.new
132
- formatter.stubs(calling_code: line)
133
- output = formatter.send(:formatted_calling_file_and_line)
134
- assert_equal "foobar.txt:30 ", output
135
- end
136
- end
137
54
  end
@@ -0,0 +1,96 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Filum
4
+
5
+ class LogFormatterTest < Minitest::Test
6
+
7
+ def test_string_format
8
+ formatter = Filum::LogFormatter.new
9
+ severity = "SEV123"
10
+ timestamp = "Timestamp123"
11
+ msg = "My Message"
12
+ context_id = "context_id"
13
+ object_id = Thread.current.object_id
14
+ file_and_line = "file_and_line"
15
+ formatter.stubs(calling_file_and_line: file_and_line)
16
+ Thread.current[:context_id] = context_id
17
+
18
+ output = formatter.call(severity, timestamp, nil, msg)
19
+ desired = "#{timestamp} thread_id-#{object_id} [#{context_id}] #{severity} | #{file_and_line} | #{msg}\n"
20
+ assert_equal desired.strip.hex, output.strip.hex
21
+ end
22
+
23
+ def test_call_calls_formatted_context_id
24
+ formatter = Filum::LogFormatter.new
25
+ formatter.expects(:formatted_context_id)
26
+ formatter.call("", "", "", "")
27
+ end
28
+
29
+ def test_formatted_context_id_uses_config
30
+ Filum.config.context_id_length = 20
31
+ context_id = "12345"
32
+ Thread.current[:context_id] = context_id
33
+ formatter = Filum::LogFormatter.new
34
+ output = formatter.send(:formatted_context_id)
35
+ assert_equal "#{context_id} ", output
36
+ end
37
+
38
+ def test_call_calls_formatted_calling_file_and_line
39
+ formatter = Filum::LogFormatter.new
40
+ formatter.expects(:formatted_calling_file_and_line)
41
+ formatter.call("", "", "", "")
42
+ end
43
+
44
+ def test_call_should_not_truncate_context_id
45
+ context_id = "context_id"
46
+ Thread.current[:context_id] = context_id
47
+ formatter = Filum::LogFormatter.new
48
+ output = formatter.send(:formatted_context_id)
49
+ assert_equal context_id, output
50
+ end
51
+
52
+ def test_call_should_return_fixed_width_context_id
53
+ context_id = "1234"
54
+ Thread.current[:context_id] = context_id
55
+ formatter = Filum::LogFormatter.new
56
+ output = formatter.send(:formatted_context_id)
57
+ assert_equal "#{context_id} ", output
58
+ end
59
+
60
+ def test_calling_file_and_line_parses_correctly
61
+ formatter = Filum::LogFormatter.new
62
+ line = "/Users/iHiD/Projects/meducation/filum/lib/filum/logger.rb:30:in `formatted_calling_file_and_line'"
63
+ formatter.stubs(calling_code: line)
64
+ output = formatter.send(:formatted_calling_file_and_line)
65
+ assert output =~ /logger\.rb:30\s*/
66
+ end
67
+
68
+ def test_formatted_calling_file_and_line_uses_config
69
+ Filum.config.filename_length = 40
70
+ filename = "abcdefghij"
71
+ line = "/Users/iHiD/Projects/meducation/filum/lib/filum/#{filename}:30:in `formatted_calling_file_and_line'"
72
+ formatter = Filum::LogFormatter.new
73
+ formatter.stubs(calling_code: line)
74
+ output = formatter.send(:formatted_calling_file_and_line)
75
+ assert_equal "#{filename}:30 #{" " * 30}", output
76
+ end
77
+
78
+ def test_formatted_calling_file_and_line_should_truncate
79
+ filename = "abcdefghijklmnopqrstuvwxyz1234"
80
+ line = "/Users/iHiD/Projects/meducation/filum/lib/filum/#{filename}:30:in `formatted_calling_file_and_line'"
81
+ formatter = Filum::LogFormatter.new
82
+ formatter.stubs(calling_code: line)
83
+ output = formatter.send(:formatted_calling_file_and_line)
84
+ assert_equal "abcdefghijklmnopq...:30 ", output
85
+ end
86
+
87
+ def test_formatted_calling_file_and_line_should_pad
88
+ filename = "foobar.txt"
89
+ line = "/Users/iHiD/Projects/meducation/filum/lib/filum/#{filename}:30:in `formatted_calling_file_and_line'"
90
+ formatter = Filum::LogFormatter.new
91
+ formatter.stubs(calling_code: line)
92
+ output = formatter.send(:formatted_calling_file_and_line)
93
+ assert_equal "foobar.txt:30 ", output
94
+ end
95
+ end
96
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MalcyL
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-11 00:00:00.000000000 Z
11
+ date: 2013-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,12 +97,14 @@ files:
97
97
  - lib/filum.rb
98
98
  - lib/filum/configuration.rb
99
99
  - lib/filum/filum_error.rb
100
+ - lib/filum/log_formatter.rb
100
101
  - lib/filum/logger.rb
101
102
  - lib/filum/version.rb
102
103
  - test/integration/integration_test.rb
103
104
  - test/integration/logger_test.rb
104
105
  - test/test_helper.rb
105
106
  - test/unit/configuration_test.rb
107
+ - test/unit/log_formatter_test.rb
106
108
  homepage: ''
107
109
  licenses:
108
110
  - AGPL3
@@ -132,4 +134,5 @@ test_files:
132
134
  - test/integration/logger_test.rb
133
135
  - test/test_helper.rb
134
136
  - test/unit/configuration_test.rb
137
+ - test/unit/log_formatter_test.rb
135
138
  has_rdoc: