Skip to content

Commit 63b6c75

Browse files
committed
Do not pretty format log arguments
This is bad because it quotes all strings although most of the times we don't need it. This also makes `luatest.log` work differently from the built-in logger while we want them to be interchangeable. We don't need pretty-printing anymore because we don't log assertion arguments. If the caller needs pretty-printing, they can do it manually. This effectively reverts commit 15dbf75 ("Improve luatest.log function if a nil value is passed") and a good part of commit a005329 ("Add syntax sugar for more convenient logging").
1 parent 5a63cc9 commit 63b6c75

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
- Add logging to unified file (gh-324).
66
- Add memory leak detection during server process execution (gh-349).
7-
- Improve `luatest.log` function if a `nil` value is passed (gh-360).
87
- Added `assert_error_covers`.
98
- Add more logs (gh-326).
109
- Add `justrun` helper as a tarantool runner and output catcher (gh-365).
@@ -23,6 +22,7 @@
2322
- Strip useless `...` lines from error trace.
2423
- Fix error trace reporting for functions executed with `Server:exec()`
2524
(gh-396).
25+
- Remove pretty-printing of `luatest.log` arguments.
2626

2727
## 1.0.1
2828

luatest/log.lua

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
local tarantool_log = require('log')
22

33
local utils = require('luatest.utils')
4-
local pp = require('luatest.pp')
54

65
-- Utils for logging
76
local log = {}
87
local default_level = 'info'
98

109
local function _log(level, msg, ...)
11-
if not utils.version_current_ge_than(2, 5, 1) then
12-
return
10+
if utils.version_current_ge_than(2, 5, 1) then
11+
return tarantool_log[level](msg, ...)
1312
end
14-
local args = {}
15-
for i = 1, select('#', ...) do
16-
local v = select(i, ...)
17-
table.insert(args, pp.tostringlog(v))
18-
end
19-
return tarantool_log[level](msg, unpack(args))
2013
end
2114

2215
--- Extra wrapper for `__call` function

luatest/pp.lua

+9-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ local TABLE_TOSTRING_SEP_LEN = string.len(TABLE_TOSTRING_SEP)
2121

2222
-- Final function called in format_table() to format the resulting list of
2323
-- string describing the table.
24-
local function _table_tostring_format_result(tbl, result, indentLevel, printTableRefs, isLogLine)
24+
local function _table_tostring_format_result(tbl, result, indentLevel, printTableRefs)
2525
local dispOnMultLines = false
2626

2727
-- set dispOnMultLines to true if the maximum LINE_LENGTH would be exceeded with the values
@@ -46,7 +46,7 @@ local function _table_tostring_format_result(tbl, result, indentLevel, printTabl
4646
end
4747

4848
-- now reformat the result table (currently holding element strings)
49-
if dispOnMultLines and not isLogLine then
49+
if dispOnMultLines then
5050
local indentString = string.rep(" ", indentLevel - 1)
5151
result = {
5252
"{\n ",
@@ -77,7 +77,7 @@ function Formatter.mt:initialize(printTableRefs)
7777
self.recursionTable = {}
7878
end
7979

80-
function Formatter.mt:format_table(tbl, indentLevel, isLogLine)
80+
function Formatter.mt:format_table(tbl, indentLevel)
8181
indentLevel = indentLevel or 1
8282
self.recursionTable[tbl] = true
8383

@@ -133,16 +133,16 @@ function Formatter.mt:format_table(tbl, indentLevel, isLogLine)
133133
count = count + 1
134134
result[count] = entry
135135
end
136-
return _table_tostring_format_result(tbl, result, indentLevel, self.printTableRefs, isLogLine)
136+
return _table_tostring_format_result(tbl, result, indentLevel, self.printTableRefs)
137137
end
138138
end
139139

140-
function Formatter.mt:format(v, indentLevel, isLogLine)
140+
function Formatter.mt:format(v, indentLevel)
141141
local type_v = type(v)
142142
if "string" == type_v then
143143
return string.format("%q", v)
144144
elseif "table" == type_v then
145-
return self:format_table(v, indentLevel, isLogLine)
145+
return self:format_table(v, indentLevel)
146146
elseif "number" == type_v then
147147
-- eliminate differences in formatting between various Lua versions
148148
if v ~= v then
@@ -169,24 +169,18 @@ end
169169
--
170170
-- * string are enclosed with " by default, or with ' if string contains a "
171171
-- * tables are expanded to show their full content, with indentation in case of nested tables
172-
function pp.tostring(value, is_logline)
172+
function pp.tostring(value)
173173
local formatter = Formatter:new(pp.TABLE_REF_IN_ERROR_MSG)
174-
local result = formatter:format(value, nil, is_logline)
174+
local result = formatter:format(value)
175175
if formatter.recursionDetected and not pp.TABLE_REF_IN_ERROR_MSG then
176176
-- some table contain recursive references,
177177
-- so we must recompute the value by including all table references
178178
-- else the result looks like crap
179-
return Formatter:new(true):format(value, nil, is_logline)
179+
return Formatter:new(true):format(value)
180180
end
181181
return result
182182
end
183183

184-
-- This function helps with displaying `value` of any type without line breaks ('\n')
185-
-- for logging. It is a simple wrapper over the tostring() function.
186-
function pp.tostringlog(value)
187-
return pp.tostring(value, true)
188-
end
189-
190184
local function has_new_line(s)
191185
return (string.find(s, '\n', 1, true) ~= nil)
192186
end

0 commit comments

Comments
 (0)