spawning-logger 0.0.5 → 0.0.6

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11f4ef981ac63f9e56325a07b600f0c910365e95
4
- data.tar.gz: d155eb095e22684f4b220232c82ae24119b342da
3
+ metadata.gz: 5180bc108488828c30fe2985510746039661769e
4
+ data.tar.gz: 1e3c97c4b6d10c7e95ecb75ab839db7084a6b19e
5
5
  SHA512:
6
- metadata.gz: cb6c890b058918d0c8b9cfa8caaa87fabe3bf25d2b1d12b2d11154f3ef95ed876fe1ea7e500176cfa33a32457d2211e5d7e19f1bcd0055c1377c533369f93e62
7
- data.tar.gz: 40f02dacfe6565478fd48d6b16058593fcc3e3a67f91cc11207299e86b77b7915c2f84043a399252de10f5100a23a2946905d0c19703e6075080a80f2626d483
6
+ metadata.gz: a80e2dcdf5c202e29be42ec051d72b086584c2fa37ace119a2e510ee6c871e2a3fe58616b7c66c25a869006ce63ce30d95a64ee20869ccb97e559d5749e23725
7
+ data.tar.gz: 92ed6206c004d1bc707e3096343e7b8cf6d581a7edfb8747e7b705f3b1d80a5c3eef5575896b8e7b9c0f709560cdc4966057b447710d017d8c4ba59180eb418a
@@ -106,11 +106,14 @@ class SpawningLogger < ::Logger
106
106
  end
107
107
 
108
108
  # creates the logfile inside a subdir (optional).
109
- def initialize(file_path, subdir = nil)
109
+ def initialize(file_path, debug = false)
110
110
  file_path = File.expand_path(file_path)
111
111
 
112
- @log_dir = File.dirname(file_path)
112
+ @log_base_dir = File.dirname(file_path)
113
+
114
+ @log_dir = @log_base_dir
113
115
  @log_dir = File.join(@log_dir, @@subdir) unless @@subdir.nil?
116
+
114
117
  FileUtils.mkdir_p(@log_dir) if !Dir.exist?(@log_dir)
115
118
 
116
119
  @file_name = File.basename(file_path)
@@ -157,7 +160,8 @@ class SpawningLogger < ::Logger
157
160
  # add extension
158
161
  file_name = file_basename + File.extname(@file_name)
159
162
 
160
- file_path = File.join(@log_dir, file_name)
163
+ # use base dir without subdir, because child logger adds it itself
164
+ file_path = File.join(@log_base_dir, file_name)
161
165
  self.class.new(file_path)
162
166
  end
163
167
 
@@ -1,5 +1,5 @@
1
1
  require 'logger'
2
2
 
3
3
  class SpawningLogger < ::Logger
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
@@ -4,16 +4,18 @@ require_relative "../lib/spawning_logger"
4
4
  class SpawningLoggerTest < MiniTest::Test
5
5
 
6
6
  def setup
7
- @log_dir = Dir.mktmpdir('spawning_logger_test')
7
+ @log_base_dir = Dir.mktmpdir('spawning_logger_test')
8
+ @log_dir = File.join(@log_base_dir, 'test_subdir')
9
+
8
10
  @logfile_name = 'test_file.log'
9
- @logfile_path = File.join(@log_dir, @logfile_name)
11
+ @logfile_path = File.join(@log_base_dir, @logfile_name)
10
12
  @child_id = 'childid'
11
13
 
12
14
  reset_logger_config
13
15
  end
14
16
 
15
17
  def teardown
16
- FileUtils.remove_entry(@log_dir)
18
+ FileUtils.remove_entry(@log_base_dir)
17
19
  reset_logger_config
18
20
  end
19
21
 
@@ -23,9 +25,9 @@ class SpawningLoggerTest < MiniTest::Test
23
25
  SpawningLogger.configure do |config|
24
26
  config.subdir = subdir
25
27
  end
26
- SpawningLogger.new(@logfile_path)
28
+ SpawningLogger.new(@logfile_path, true)
27
29
 
28
- expected_dir = File.join(@log_dir, subdir)
30
+ expected_dir = File.join(@log_base_dir, subdir)
29
31
  expected_file = File.join(expected_dir, @logfile_name)
30
32
 
31
33
  assert File.exist?(expected_file)
@@ -33,6 +35,8 @@ class SpawningLoggerTest < MiniTest::Test
33
35
  end
34
36
 
35
37
  def test_spawn_interface_yields_logger_for_child_id
38
+ logger = SpawningLogger.new(@logfile_path)
39
+ logger.spawn('childid')
36
40
  assert_creates_log_file('test_file_childid.log')
37
41
  end
38
42
 
@@ -41,6 +45,9 @@ class SpawningLoggerTest < MiniTest::Test
41
45
  config.child_prefix = 'childprefix'
42
46
  end
43
47
 
48
+ logger = SpawningLogger.new(@logfile_path)
49
+ logger.spawn('childid')
50
+
44
51
  assert_creates_log_file('test_file_childprefix_childid.log')
45
52
  end
46
53
 
@@ -56,8 +63,10 @@ class SpawningLoggerTest < MiniTest::Test
56
63
  logger = SpawningLogger.new(@logfile_path)
57
64
  logger.self_and_spawn("childid", :error, "test_self_and_spawn_calls_both")
58
65
 
59
- # make sure log message shows up in main logfile and in spawned logfile
60
- [@logfile_path, File.join(@log_dir, 'test_file_childid.log')].each do |path|
66
+ parent_path = File.join(@log_dir, @logfile_name)
67
+ child_path = File.join(@log_dir, 'test_file_childid.log')
68
+
69
+ [parent_path, child_path].each do |path|
61
70
  result = File.read(path)
62
71
  assert_match(/test_self_and_spawn_calls_both/, result)
63
72
  end
@@ -81,11 +90,6 @@ class SpawningLoggerTest < MiniTest::Test
81
90
  protected
82
91
 
83
92
  def assert_creates_log_file(file_name)
84
- logger = SpawningLogger.new(@logfile_path)
85
- child_logger = logger.spawn(@child_id)
86
-
87
- assert_kind_of(::Logger, child_logger)
88
-
89
93
  expected_path = File.join(@log_dir, file_name)
90
94
  assert File.exist?(expected_path)
91
95
  end
@@ -93,7 +97,7 @@ class SpawningLoggerTest < MiniTest::Test
93
97
  def reset_logger_config
94
98
  SpawningLogger.configure do |config|
95
99
  config.child_prefix = nil
96
- config.subdir = nil
100
+ config.subdir = 'test_subdir'
97
101
  end
98
102
  end
99
103
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spawning-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Seeger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-07 00:00:00.000000000 Z
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake