Skip to content
Snippets Groups Projects
Commit 8ea35a34 authored by Mergen Imeev's avatar Mergen Imeev Committed by Alexander Turenko
Browse files

config: log section for instance config

This section describes the instance log configuration.

Part of #8778

NO_DOC=will be added later
NO_CHANGELOG=will be added later
parent ddb530c0
No related branches found
No related tags found
No related merge requests found
......@@ -169,6 +169,104 @@ return schema.new('instance_config', schema.record({
}),
}),
}),
log = schema.record({
-- The logger destination is handled separately in the
-- box_cfg applier, so there are no explicit box_cfg and
-- box_cfg_nondynamic annotations.
--
-- The reason is that there is no direct-no-transform
-- mapping from, say, `log.file` to `box_cfg.log`.
-- The applier should add the `file:` prefix.
to = schema.enum({
'stderr',
'file',
'pipe',
'syslog',
}, {
default = 'stderr',
}),
file = schema.scalar({
type = 'string',
default = '{{ instance_name }}.log',
}),
pipe = schema.scalar({
type = 'string',
default = box.NULL,
}),
syslog = schema.record({
identity = schema.scalar({
type = 'string',
default = 'tarantool',
}),
facility = schema.scalar({
type = 'string',
default = 'local7',
}),
server = schema.scalar({
type = 'string',
-- The logger tries /dev/log and then
-- /var/run/syslog if no server is provided.
default = box.NULL,
}),
}),
nonblock = schema.scalar({
type = 'boolean',
box_cfg = 'log_nonblock',
box_cfg_nondynamic = true,
default = false,
}),
level = schema.scalar({
type = 'number, string',
box_cfg = 'log_level',
default = 5,
allowed_values = {
0, 'fatal',
1, 'syserror',
2, 'error',
3, 'crit',
4, 'warn',
5, 'info',
6, 'verbose',
7, 'debug',
},
}),
format = schema.enum({
'plain',
'json',
}, {
box_cfg = 'log_format',
default = 'plain',
}),
-- box.cfg({log_modules = <...>}) replaces the previous
-- value without any merging.
--
-- If a key in this map is removed in the provided
-- configuration, then it will be removed in the actually
-- applied configuration.
--
-- It is exactly what we need there to make the
-- configuration independent of previously applied values.
modules = schema.map({
key = schema.scalar({
type = 'string',
}),
value = schema.scalar({
type = 'number, string',
}),
box_cfg = 'log_modules',
-- TODO: This default doesn't work now. It needs
-- support of non-scalar schema nodes in
-- <schema object>:map().
default = box.NULL,
}),
}, {
validate = function(log, w)
if log.to == 'pipe' and log.pipe == nil then
w.error('The pipe logger is set by the log.to parameter but ' ..
'the command is not set (log.pipe parameter)')
end
end,
}),
}, {
-- Any configuration data should contain a version of the
-- config schema for which it is written.
......
......@@ -135,3 +135,60 @@ g.test_fiber = function()
local res = instance_config:apply_default({}).fiber
t.assert_equals(res, exp)
end
g.test_log = function()
local iconfig = {
log = {
to = 'stderr',
file = 'one',
pipe = 'two',
syslog = {
identity = 'three',
facility = 'four',
server = 'five',
},
nonblock = true,
level = 'debug',
format = 'json',
modules = {
seven = 'debug',
},
},
}
instance_config:validate(iconfig)
validate_fields(iconfig.log, instance_config.schema.fields.log)
iconfig = {
log = {
level = 5,
},
}
instance_config:validate(iconfig)
iconfig = {
log = {
to = 'pipe',
},
}
local err = '[instance_config] log: The pipe logger is set by the log.to '..
'parameter but the command is not set (log.pipe parameter)'
t.assert_error_msg_equals(err, function()
instance_config:validate(iconfig)
end)
local exp = {
to = 'stderr',
file = '{{ instance_name }}.log',
pipe = box.NULL,
syslog = {
identity = 'tarantool',
facility = 'local7',
server = box.NULL,
},
nonblock = false,
level = 5,
format = 'plain',
}
local res = instance_config:apply_default({}).log
t.assert_equals(res, exp)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment