-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e97085d
commit a1d5352
Showing
8 changed files
with
393 additions
and
11 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
doc/code_snippets/test/logging/log_existing_c_modules_test.lua
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 fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local g = t.group() | ||
|
||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
workdir = fio.cwd() .. '/tmp', | ||
box_cfg = { log_level = 'warn', | ||
log_modules = { tarantool = 'info' } } | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
ffi = require('ffi') | ||
|
||
-- Prints 'info' messages -- | ||
ffi.C._say(ffi.C.S_INFO, nil, 0, nil, 'Info message from C module') | ||
--[[ | ||
[6024] main/103/interactive I> Info message from C module | ||
--- | ||
... | ||
--]] | ||
|
||
-- Swallows 'debug' messages -- | ||
ffi.C._say(ffi.C.S_DEBUG, nil, 0, nil, 'Debug message from C module') | ||
--[[ | ||
--- | ||
... | ||
--]] | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
local function find_in_log(cg, str, must_be_present) | ||
t.helpers.retrying({ timeout = 0.3, delay = 0.1 }, function() | ||
local found = cg.server:grep_log(str) ~= nil | ||
t.assert(found == must_be_present) | ||
end) | ||
end | ||
|
||
g.test_log_contains_messages = function(cg) | ||
find_in_log(cg, 'Info message from C module', true) | ||
find_in_log(cg, 'Debug message from C module', false) | ||
end |
56 changes: 56 additions & 0 deletions
56
doc/code_snippets/test/logging/log_existing_modules_test.lua
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,56 @@ | ||
local fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local g = t.group() | ||
|
||
local run_before_cfg = [[ | ||
module1 = require('test.logging.module1') | ||
module2 = require('test.logging.module2') | ||
]] | ||
|
||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
env = { | ||
['TARANTOOL_RUN_BEFORE_BOX_CFG'] = run_before_cfg, | ||
}, | ||
workdir = fio.cwd() .. '/tmp', | ||
box_cfg = { log_modules = { | ||
['test.logging.module1'] = 'verbose', | ||
['test.logging.module2'] = 'error' } | ||
} | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
-- Prints 'info' messages -- | ||
module1.say_hello() | ||
--[[ | ||
[92617] main/103/interactive/test.logging.module1 I> Info message from module1 | ||
--- | ||
... | ||
--]] | ||
|
||
-- Swallows 'info' messages -- | ||
module2.say_hello() | ||
--[[ | ||
--- | ||
... | ||
--]] | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
local function find_in_log(cg, str, must_be_present) | ||
t.helpers.retrying({ timeout = 0.3, delay = 0.1 }, function() | ||
local found = cg.server:grep_log(str) ~= nil | ||
t.assert(found == must_be_present) | ||
end) | ||
end | ||
|
||
g.test_log_contains_messages = function(cg) | ||
find_in_log(cg, 'Info message from module1', true) | ||
find_in_log(cg, 'Info message from module2', false) | ||
end |
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,61 @@ | ||
local fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local g = t.group() | ||
|
||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
workdir = fio.cwd() .. '/tmp', | ||
box_cfg = { log_level = 'warn', | ||
log_modules = { | ||
module1 = 'verbose', | ||
module2 = 'error' } | ||
} | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
-- Creates new loggers -- | ||
module1_log = require('log').new('module1') | ||
module2_log = require('log').new('module2') | ||
|
||
-- Prints 'info' messages -- | ||
module1_log.info('Info message from module1') | ||
--[[ | ||
[16300] main/103/interactive/module1 I> Info message from module1 | ||
--- | ||
... | ||
--]] | ||
|
||
-- Swallows 'debug' messages -- | ||
module1_log.debug('Debug message from module1') | ||
--[[ | ||
--- | ||
... | ||
--]] | ||
|
||
-- Swallows 'info' messages -- | ||
module2_log.info('Info message from module2') | ||
--[[ | ||
--- | ||
... | ||
--]] | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
local function find_in_log(cg, str, must_be_present) | ||
t.helpers.retrying({ timeout = 0.3, delay = 0.1 }, function() | ||
local found = cg.server:grep_log(str) ~= nil | ||
t.assert(found == must_be_present) | ||
end) | ||
end | ||
|
||
g.test_log_contains_messages = function(cg) | ||
find_in_log(cg, 'Info message from module1', true) | ||
find_in_log(cg, 'Debug message from module1', false) | ||
find_in_log(cg, 'Info message from module2', false) | ||
end |
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,47 @@ | ||
local fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local g = t.group() | ||
|
||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
workdir = fio.cwd() .. '/tmp', | ||
box_cfg = { log_level = 'warn' } | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
log = require('log') | ||
|
||
-- Prints 'warn' messages -- | ||
log.warn('Warning message') | ||
--[[ | ||
2023-07-20 11:03:57.029 [16300] main/103/interactive/tarantool [C]:-1 W> Warning message | ||
--- | ||
... | ||
--]] | ||
|
||
-- Swallows 'debug' messages -- | ||
log.debug('Debug message') | ||
--[[ | ||
--- | ||
... | ||
--]] | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
local function find_in_log(cg, str, must_be_present) | ||
t.helpers.retrying({ timeout = 0.3, delay = 0.1 }, function() | ||
local found = cg.server:grep_log(str) ~= nil | ||
t.assert(found == must_be_present) | ||
end) | ||
end | ||
|
||
g.test_log_contains_messages = function(cg) | ||
find_in_log(cg, 'Warning message', true) | ||
find_in_log(cg, 'Debug message', false) | ||
end |
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,6 @@ | ||
return { | ||
say_hello = function() | ||
local log = require('log') | ||
log.info('Info message from module1') | ||
end | ||
} |
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,6 @@ | ||
return { | ||
say_hello = function() | ||
local log = require('log') | ||
log.info('Info message from module2') | ||
end | ||
} |
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
Oops, something went wrong.