Skip to content

Commit 136ade3

Browse files
committed
Do not hijack runner stderr for unified logging
This is ugly. Instead, let's redirect logs directly to the pipe created by the OutputBeautifier. No changelog because the feature was added by commit f8a1c10 ("Add logging to unified file"), which hasn't been released yet.
1 parent 8f87dd6 commit 136ade3

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

luatest/output_beautifier.lua

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,23 @@ end
5959
-- @string object.prefix String to prefix each output line with.
6060
-- @string[opt] object.color Color name for prefix.
6161
-- @string[opt] object.color_code Color code for prefix.
62-
-- @boolean[opt] object.runner Mark OutputBeautifier object is created for runner process.
6362
-- @return input object.
6463
function OutputBeautifier:new(object)
65-
checks('table', {prefix = 'string', color = '?string', color_code = '?string', runner = '?boolean'})
64+
checks('table', {prefix = 'string', color = '?string', color_code = '?string'})
6665
return self:from(object)
6766
end
6867

6968
function OutputBeautifier.mt:initialize()
7069
self.color_code = self.color_code or
7170
self.class.COLOR_BY_NAME[self.color] or
7271
OutputBeautifier:next_color_code()
73-
self.pipes = {stderr = ffi_io.create_pipe()}
74-
if not self.runner then
75-
self.pipes.stdout = ffi_io.create_pipe()
76-
end
72+
self.pipes = {stdout = ffi_io.create_pipe(), stderr = ffi_io.create_pipe()}
7773
self.stderr = ''
7874
end
7975

8076
-- Replace standard output descriptors with pipes.
81-
-- Stdout descriptor of the runner process will not be replaced
82-
-- because it is used for displaying all captured data from other processes.
8377
function OutputBeautifier.mt:hijack_output()
84-
if not self.runner then
85-
ffi_io.dup2_io(self.pipes.stdout[1], io.stdout)
86-
end
78+
ffi_io.dup2_io(self.pipes.stdout[1], io.stdout)
8779
ffi_io.dup2_io(self.pipes.stderr[1], io.stderr)
8880
end
8981

luatest/runner.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,14 @@ function Runner.run(args, options)
7272
local fh = fio.open(options.log_file, {'O_CREAT', 'O_WRONLY'}, tonumber('640', 8))
7373
rawset(_G, 'log_file', {fh = fh})
7474

75-
local output_beautifier = OutputBeautifier:new({prefix = log_prefix, runner = true})
75+
local output_beautifier = OutputBeautifier:new({prefix = log_prefix})
7676
output_beautifier:enable()
77-
output_beautifier:hijack_output()
7877

7978
-- `tee` copy logs to file and also to standard output, but we need
8079
-- process all captured data through the OutputBeatifier object.
81-
-- Data will be redirected back to stderr of the current process.
82-
-- `/dev/fd/2` is a symlink to `/proc/self/fd`, where `/proc/self` is
83-
-- a symlink to `/proc/<PID>`. So `/dev/fd/2` is equal to `/proc/<PID>/fd/2`
84-
-- and it means "stderr of the current process".
85-
log_cfg = string.format("| tee %s > /dev/fd/2", log_cfg)
80+
-- So we redirect stdout to the pipe created by OutputBeautifier.
81+
log_cfg = string.format("| tee %s > /dev/fd/%d",
82+
log_cfg, output_beautifier.pipes.stdout[1])
8683
end
8784
-- Logging cannot be initialized without configuring the `box` engine
8885
-- on a version less than 2.5.1 (see more details at [1]). Otherwise,

0 commit comments

Comments
 (0)