From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 7822D6EC58; Thu, 27 May 2021 10:53:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7822D6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1622102018; bh=LswwpYULbEjEsC09u4qoe+Gih4rxfo0NnRySbiVU1AY=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=HPFbo21SHT0ssFFOK2zOpMc7ticz3G2irEJK1G5/QpdJml5kvCLwbUONXiVblF+MC gtlqrOJVfUejulsQif/NtiwJgf0sXfEypj6+poAAO2eG3K1FuTDISkWFV1uUirZbB7 4DnrnhI3E4v9yM9RQW0Nv2hB0iqzyW0REqnk40KM= Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 7A3FF6EC58 for ; Thu, 27 May 2021 10:53:36 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7A3FF6EC58 Received: by mail-lj1-f176.google.com with SMTP id s25so5086324ljo.11 for ; Thu, 27 May 2021 00:53:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=FC8S9pjC4a2Xood5Xl+n14DB+UmMfBxvNNYSPwN+UFg=; b=kOiXUvuDbWWWrLY86m44hSsM+slgfXATisiad2oG8+2dajIvLsVCMoo0SIRg0m6GJs f+qj9PxttvNsuc18VvzI0NRtd4B4kqH6D0yyAjcOxBeihRzYQhK2NZ4SbzDf8KVcs4qW Dpr/QpGDZ0KwRZW5i1ZjAnADR8fHMQLHIqJWkOPrQRcwOTQ4Kfgx/9DIfhIfOUuiEyH8 bE3qDpWUDm88ObcAy9LMPeBjBxZa4CXm6Bm6jg4ttz2U2xRo48HSMq614Ryqv5OCmmGl VqyKg99Fj48DNIX48tuco70f5K9VwxM8CNqwrPKwKF7GytfMqMB6IZJZJvG8MerpG/ti eUaQ== X-Gm-Message-State: AOAM5323qckkaPKQqYWNmfDcn31ZixPOdQJ5gGQCIHf6Dl/ZSPKjbXfb Adv5ID34FB4/Z+SnihR/dHoFsABuqlw= X-Google-Smtp-Source: ABdhPJxC32rc0aMckzef4LesshAX5ZetOB74huieHddIdneO4e7bttmQRcXVmdBdkv5CJDU5eofdwA== X-Received: by 2002:a2e:a7cb:: with SMTP id x11mr1581524ljp.143.1622102014841; Thu, 27 May 2021 00:53:34 -0700 (PDT) Received: from grain.localdomain ([5.18.171.94]) by smtp.gmail.com with ESMTPSA id o5sm146123ljj.103.2021.05.27.00.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 00:53:33 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id 5EBA55A0042; Thu, 27 May 2021 10:53:32 +0300 (MSK) Date: Thu, 27 May 2021 10:53:32 +0300 To: Alexander Turenko Message-ID: References: <20210507111305.564935-1-gorcunov@gmail.com> <20210526220454.twurat7647tcx4be@tkn_work_nb> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210526220454.twurat7647tcx4be@tkn_work_nb> User-Agent: Mutt/2.0.7 (2021-05-04) Subject: Re: [Tarantool-patches] [PATCH] lua/log: accept symbolic logging levels X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: tml Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Thu, May 27, 2021 at 01:04:54AM +0300, Alexander Turenko wrote: > Sorry for the late response. > > Looks nice! LGTM. > > If you'll have a free time, it would be good to add a simple test case: > just to automatically verify it for regressions in a future. > Thanks! I force pushed an update where a test added (we can extend it in future). branch gorcunov/gh-5882-logger-strings issue https://github.com/tarantool/tarantool/issues/5882 --- From: Cyrill Gorcunov Date: Fri, 7 May 2021 13:59:43 +0300 Subject: [PATCH] lua/log: accept symbolic logging levels Currently `log` module accepts only numeric values of logging levels. I turn `box.cfg` interface supports symbolic names (such as 'fatal', 'crit' and etc). Thus we should support the same in `log` module. Closes #5882 Reported-by: Alexander Turenko Acked-by: Alexander Turenko Acked-by: Serge Petrenko Signed-off-by: Cyrill Gorcunov --- changelogs/unreleased/gh-5882-log-levels.md | 13 ++++++++ src/lua/log.lua | 6 ++++ test/app-tap/logmod.test.lua | 36 +++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 changelogs/unreleased/gh-5882-log-levels.md create mode 100755 test/app-tap/logmod.test.lua diff --git a/changelogs/unreleased/gh-5882-log-levels.md b/changelogs/unreleased/gh-5882-log-levels.md new file mode 100644 index 000000000..08f9595be --- /dev/null +++ b/changelogs/unreleased/gh-5882-log-levels.md @@ -0,0 +1,13 @@ +## feature/lua/log + + * Implemented support of symbolic log levels representation + in `log` module (gh-5882). Now it is possible to specify + levels the same way as in `box.cfg{}` call. For example + instead of + ``` Lua + require('log').cfg{level = 6} + ``` + One can use + ``` Lua + require('log').cfg{level = 'verbose'} + ``` diff --git a/src/lua/log.lua b/src/lua/log.lua index 62ea61f2d..788560722 100644 --- a/src/lua/log.lua +++ b/src/lua/log.lua @@ -499,6 +499,12 @@ local function load_cfg(self, cfg) local m = "log.cfg: \'%s\' %s" error(m:format('level', msg)) end + -- Convert level to a numeric value since + -- low level api operates with numbers only. + if type(cfg.level) == 'string' then + assert(log_level_keys[cfg.level] ~= nil) + cfg.level = log_level_keys[cfg.level] + end end if cfg.nonblock ~= nil then diff --git a/test/app-tap/logmod.test.lua b/test/app-tap/logmod.test.lua new file mode 100755 index 000000000..68508ce5b --- /dev/null +++ b/test/app-tap/logmod.test.lua @@ -0,0 +1,36 @@ +#!/usr/bin/env tarantool + +local test = require('tap').test('log') +local log = require('log') + +test:plan(8) + +log.log_format('plain') + +-- Test symbolic names for loglevels +_, err = pcall(log.cfg, {level='fatal'}) +test:ok(err == nil and log.cfg.level == 0, 'both got fatal') + +_, err = pcall(log.cfg, {level='syserror'}) +test:ok(err == nil and log.cfg.level == 1, 'got syserror') + +_, err = pcall(log.cfg, {level='error'}) +test:ok(err == nil and log.cfg.level == 2, 'got error') + +_, err = pcall(log.cfg, {level='crit'}) +test:ok(err == nil and log.cfg.level == 3, 'got crit') + +_, err = pcall(log.cfg, {level='warn'}) +test:ok(err == nil and log.cfg.level == 4, 'got warn') + +_, err = pcall(log.cfg, {level='info'}) +test:ok(err == nil and log.cfg.level == 5, 'got info') + +_, err = pcall(log.cfg, {level='verbose'}) +test:ok(err == nil and log.cfg.level == 6, 'got verbose') + +_, err = pcall(log.cfg, {level='debug'}) +test:ok(err == nil and log.cfg.level == 7, 'got debug') + +test:check() +os.exit() -- 2.31.1