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 +4 -4
- data/lib/spawning_logger.rb +7 -3
- data/lib/version.rb +1 -1
- data/test/spawning_logger_test.rb +17 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5180bc108488828c30fe2985510746039661769e
|
4
|
+
data.tar.gz: 1e3c97c4b6d10c7e95ecb75ab839db7084a6b19e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a80e2dcdf5c202e29be42ec051d72b086584c2fa37ace119a2e510ee6c871e2a3fe58616b7c66c25a869006ce63ce30d95a64ee20869ccb97e559d5749e23725
|
7
|
+
data.tar.gz: 92ed6206c004d1bc707e3096343e7b8cf6d581a7edfb8747e7b705f3b1d80a5c3eef5575896b8e7b9c0f709560cdc4966057b447710d017d8c4ba59180eb418a
|
data/lib/spawning_logger.rb
CHANGED
@@ -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,
|
109
|
+
def initialize(file_path, debug = false)
|
110
110
|
file_path = File.expand_path(file_path)
|
111
111
|
|
112
|
-
@
|
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
|
-
|
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
|
|
data/lib/version.rb
CHANGED
@@ -4,16 +4,18 @@ require_relative "../lib/spawning_logger"
|
|
4
4
|
class SpawningLoggerTest < MiniTest::Test
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@
|
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(@
|
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(@
|
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(@
|
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
|
-
|
60
|
-
|
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 =
|
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.
|
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-
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|