forked from tarantool/luatest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We improved `luatest.log` module for convenient logging and refactored it: local t = require('luatest.log') t.log('Info log: %s', 'foo') t.log.warn('Warn log from %s', 'foo') The following functions of the `luatest.log` module are presented: t.log.error(msg[, args]) t.log.warn(msg[, args]) t.log.info(msg[, args]) t.log.verbose(msg[, args]) t.log.debug(msg[, args]) t.log() - syntax sugar for t.log.info(...) Follows tarantool#326
- Loading branch information
1 parent
f8a1c10
commit a9ff637
Showing
3 changed files
with
49 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
local tarantool_log = require('log') | ||
|
||
local utils = require('luatest.utils') | ||
local pp = require('luatest.pp') | ||
|
||
-- Utils for logging | ||
local log = {} | ||
|
||
|
||
local function _log(level, msg, ...) | ||
if not utils.version_current_ge_than(2, 5, 1) then | ||
return | ||
end | ||
local args = {...} | ||
for k, v in pairs(args) do | ||
args[k] = pp.tostringlog(v) | ||
end | ||
return tarantool_log[level](msg, unpack(args)) | ||
end | ||
|
||
local function log_info(t, msg, ...) | ||
return _log('info', msg, ...) | ||
end | ||
|
||
function log.info(msg, ...) | ||
print('here', msg, (...)) | ||
return _log('info', msg, ...) | ||
end | ||
|
||
function log.verbose(msg, ...) | ||
return _log('verbose', msg, ...) | ||
end | ||
|
||
function log.debug(msg, ...) | ||
return _log('info', msg, ...) | ||
end | ||
|
||
function log.warn(msg, ...) | ||
return _log('warn', msg, ...) | ||
end | ||
|
||
function log.error(msg, ...) | ||
return _log('error', msg, ...) | ||
end | ||
|
||
setmetatable(log, {__call = log_info}) | ||
|
||
return log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters