filum 1.0.2 → 1.0.3

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
- NDJkNDNlYTU1YjkyMjM0ZTVjZDAxYjUwNGM0YmIzYmZhZjg4NDg3Yg==
4
+ NDM1NGQzMzc1YzgzN2RhNWEyMjkwYmM3MGRkOTAyM2E1OWExNmQzMQ==
5
5
  data.tar.gz: !binary |-
6
- ZjAxNDg3NDQwNzk3YThmZmM1NjllMjc1ZjI5NjEwNGM1NDcxNjUyZA==
6
+ MmIyNzE3ZTg4MmNjZmI4ODliYmQwZGViYWRkZjUzMDlkM2U4OTk5OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjBhNTM3NDk1ODQ4MDU1OTZmYTYxZTNjYjY5MTFmNWRmNzhkNmU5MzY2MzAy
10
- ZGYyMzViNDhlZmRiMDc3MjMwY2E4ZmFlZDNlODU1ZjhjZmZhOGQwYzc1MmVi
11
- MjQ2YjVhOTI1YTkyZDI4NDUzNGQ3MDg3YTQ1ZTcyYmM4OTE4NTM=
9
+ YjUyYWY5NjM1ZGQzMjg3MzBkZTNiODI0N2MyODZhOWMzMGY1OTFkY2E1ZWU5
10
+ OGRiZTg4NTMwOGZmMTdhNWUwMGJlZGZjZGI5ZjE4Nzk0YTQ0M2U2ODYzOWFk
11
+ ODJhNjIxZDFlMDM0YTI3NTIyY2E5NzQyYjhkMTc2OWZmZDQ1Njc=
12
12
  data.tar.gz: !binary |-
13
- ZmUwYzliYjU3Yzc3MDdkNDkwYjUzMzg1MzgyMjc1NDE3NzYzMzM5MmFmNTlj
14
- ZTJlMGU2ZjIwNDNiMWY0ODJiOWY1NzViM2ZhYjM5MGFiZmI2NmQ1YWJkZTZl
15
- YjFmNWMzNTc4OGI2MzY4ZTE2YTI4ZGM0M2NhY2YyYjNiNGU1Y2E=
13
+ ZmQzNTlkZGE0OWY3OGZlMjMzN2ZhY2FhMmU2MzMzZmUyZGJmZjRjZmI1NTY5
14
+ ZjZhZTE1MjQ1NDA3YTFkYzI2NTU0YzQ1NDA2NTY3Y2RlZDAxMGRlYjRhYjNi
15
+ OTZlOTdjZTJhMGYxZjhkY2UwNzI2YWI4NWY4OTEzNjI4ZmFlNjE=
@@ -1,3 +1,6 @@
1
+ 1.0.3 / 2013-12-17
2
+ [FEATURE] Tidy up formatting to have positional padding
3
+
1
4
  1.0.2 / 2013-12-16
2
5
  [FEATURE] By default, rotate logs daily
3
6
 
@@ -3,7 +3,7 @@ require 'logger'
3
3
  module Filum
4
4
  class LogFormatter < Logger::Formatter
5
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"
6
+ "#{timestamp} #{formatted_thread_id} [#{formatted_context_id}] #{severity.to_s.ljust(5)} | #{formatted_calling_file_and_line} | #{msg}\n"
7
7
  end
8
8
 
9
9
  private
@@ -23,9 +23,17 @@ module Filum
23
23
  file = "#{file[0,truncated_filename_length]}..." if file.length >= filename_length
24
24
  "#{file}:#{line.ljust(3)}".ljust(filename_length + 4)
25
25
  end
26
+
27
+ def formatted_thread_id
28
+ "t-#{thread_id}".ljust(12)
29
+ end
26
30
 
27
31
  def calling_code
28
32
  caller[5]
29
33
  end
34
+
35
+ def thread_id
36
+ Thread.current.object_id
37
+ end
30
38
  end
31
39
  end
@@ -1,3 +1,3 @@
1
1
  module Filum
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -4,7 +4,7 @@ module Filum
4
4
 
5
5
  class LogFormatterTest < Minitest::Test
6
6
 
7
- def test_string_format
7
+ def test_string_format_contains_correct_when_padding_stripped_out
8
8
  formatter = Filum::LogFormatter.new
9
9
  severity = "SEV123"
10
10
  timestamp = "Timestamp123"
@@ -12,12 +12,37 @@ module Filum
12
12
  context_id = "context_id"
13
13
  object_id = Thread.current.object_id
14
14
  file_and_line = "file_and_line"
15
- formatter.stubs(calling_file_and_line: file_and_line)
15
+ formatter.stubs(formatted_calling_file_and_line: file_and_line)
16
16
  Thread.current[:context_id] = context_id
17
17
 
18
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
19
+ desired = "#{timestamp} t-#{object_id} [#{context_id}] #{severity} | #{file_and_line} | #{msg}\n"
20
+ assert_equal desired, output.gsub(/[ ]+/, ' ')
21
+ end
22
+
23
+ def test_severity_should_pad_to_5_chars
24
+ formatter = Filum::LogFormatter.new
25
+ severity = "SEV"
26
+ timestamp = "Timestamp123"
27
+ msg = "My Message"
28
+ output = formatter.call(severity, timestamp, nil, msg)
29
+ actual_severity_field = output.match(/SEV\s+\|/)[0]
30
+ assert_equal "SEV |", actual_severity_field
31
+ end
32
+
33
+ def test_can_format_with_nil_severity
34
+ formatter = Filum::LogFormatter.new
35
+ formatter.call(nil, "timestamp", nil, "msg")
36
+ end
37
+
38
+ def test_can_format_with_nil_timestamp
39
+ formatter = Filum::LogFormatter.new
40
+ formatter.call("SEV", nil, nil, "msg")
41
+ end
42
+
43
+ def test_can_format_with_nil_msg
44
+ formatter = Filum::LogFormatter.new
45
+ formatter.call("SEV", "timestamp", nil, nil)
21
46
  end
22
47
 
23
48
  def test_call_calls_formatted_context_id
@@ -92,5 +117,26 @@ module Filum
92
117
  output = formatter.send(:formatted_calling_file_and_line)
93
118
  assert_equal "foobar.txt:30 ", output
94
119
  end
120
+
121
+ def test_call_calls_formatted_thread_id
122
+ formatter = Filum::LogFormatter.new
123
+ formatter.expects(:formatted_thread_id)
124
+ formatter.call("", "", "", "")
125
+ end
126
+
127
+ def test_formatted_thread_id_should_pad
128
+ formatter = Filum::LogFormatter.new
129
+ formatter.stubs(thread_id: "0123456")
130
+ output = formatter.send(:formatted_thread_id)
131
+ assert_equal "t-0123456 ", output
132
+ end
133
+
134
+ def test_formatted_thread_id_should_overflow_not_trim
135
+ formatter = Filum::LogFormatter.new
136
+ formatter.stubs(thread_id: "01234567890")
137
+ output = formatter.send(:formatted_thread_id)
138
+ assert_equal "t-01234567890", output
139
+ end
140
+
95
141
  end
96
142
  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.2
4
+ version: 1.0.3
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-16 00:00:00.000000000 Z
11
+ date: 2013-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler