|
| 1 | +-------------------------------------------------------------------------------- |
| 2 | +-- log.lua |
| 3 | +-- This file is a part of pk-test library |
| 4 | +-- Copyright (c) Alexander Gladysh <[email protected]> |
| 5 | +-- Copyright (c) Dmitry Potapov <[email protected]> |
| 6 | +-- See file `COPYRIGHT` for the license |
| 7 | +-------------------------------------------------------------------------------- |
| 8 | + |
| 9 | +local posix = require "posix" |
| 10 | + |
| 11 | +-------------------------------------------------------------------------------- |
| 12 | + |
| 13 | +local LOG_LEVEL, |
| 14 | + wrap_file_sink, |
| 15 | + make_common_logging_config |
| 16 | + = import 'lua-nucleo/log.lua' |
| 17 | + { |
| 18 | + 'LOG_LEVEL', |
| 19 | + 'wrap_file_sink', |
| 20 | + 'make_common_logging_config' |
| 21 | + } |
| 22 | + |
| 23 | +local create_common_logging_system, |
| 24 | + get_current_logsystem_date_microsecond |
| 25 | + = import 'pk-core/log.lua' |
| 26 | + { |
| 27 | + 'create_common_logging_system', |
| 28 | + 'get_current_logsystem_date_microsecond' |
| 29 | + } |
| 30 | + |
| 31 | +-------------------------------------------------------------------------------- |
| 32 | + |
| 33 | +local init_test_logging_system, |
| 34 | + update_test_logging_system_pid |
| 35 | +do |
| 36 | + local LOG_LEVEL_CONFIG = |
| 37 | + { |
| 38 | + [LOG_LEVEL.ERROR] = true; |
| 39 | + [LOG_LEVEL.LOG] = true; |
| 40 | + [LOG_LEVEL.DEBUG] = true; |
| 41 | + [LOG_LEVEL.SPAM] = true; |
| 42 | + } |
| 43 | + |
| 44 | + local LOG_MODULE_CONFIG = |
| 45 | + { |
| 46 | + -- Empty; everything is enabled by default. |
| 47 | + } |
| 48 | + |
| 49 | + local logging_system_id = "{TTTTT} " |
| 50 | + |
| 51 | + local get_logging_system_id = function() |
| 52 | + return logging_system_id |
| 53 | + end |
| 54 | + |
| 55 | + update_test_logging_system_pid = function() |
| 56 | + logging_system_id = "{"..("%05d"):format(posix.getpid("pid")).."} " |
| 57 | + end |
| 58 | + |
| 59 | + init_test_logging_system = function() |
| 60 | + local logging_config = make_common_logging_config( |
| 61 | + LOG_LEVEL_CONFIG, |
| 62 | + LOG_MODULE_CONFIG |
| 63 | + ) |
| 64 | + create_common_logging_system( |
| 65 | + get_logging_system_id, |
| 66 | + wrap_file_sink(io.stdout), |
| 67 | + logging_config, |
| 68 | + get_current_logsystem_date_microsecond |
| 69 | + ) |
| 70 | + end |
| 71 | +end |
| 72 | + |
| 73 | +-------------------------------------------------------------------------------- |
| 74 | + |
| 75 | +return |
| 76 | +{ |
| 77 | + init_test_logging_system = init_test_logging_system; |
| 78 | + update_test_logging_system_pid = update_test_logging_system_pid; |
| 79 | +} |
0 commit comments