From 82077aff251c9d13e1aac4608ba7bf0a58ea5712 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 27 Sep 2018 18:55:33 +0200 Subject: [PATCH] Add timestamping log option to config file. --- cdist/configuration.py | 2 + cdist/test/configuration/__init__.py | 112 +++++++++++++++++++++++++++ docs/src/cdist-configuration.rst | 4 + docs/src/man1/cdist.rst | 4 + 4 files changed, 122 insertions(+) diff --git a/cdist/configuration.py b/cdist/configuration.py index 8df43f9f..f05a5963 100644 --- a/cdist/configuration.py +++ b/cdist/configuration.py @@ -261,6 +261,7 @@ _ARG_OPTION_MAPPING = { 'verbose': 'verbosity', 'use_archiving': 'archiving', 'save_output_streams': 'save_output_streams', + 'timestamp': 'timestamp', } @@ -304,6 +305,7 @@ class Configuration(metaclass=Singleton): 'archiving': ArchivingOption(), 'save_output_streams': BooleanOption('save_output_streams', default_overrides=False), + 'timestamp': BooleanOption('timestamp'), }, } diff --git a/cdist/test/configuration/__init__.py b/cdist/test/configuration/__init__.py index 3319d320..182868a6 100644 --- a/cdist/test/configuration/__init__.py +++ b/cdist/test/configuration/__init__.py @@ -1296,6 +1296,118 @@ class ConfigurationTestCase(test.CdistTestCase): self.fail("Exception should not have been raised: {}".format( e)) + def test_configuration_timestamping_log_1(self): + config = newConfigParser() + config['GLOBAL'] = { + 'timestamp': 'True', + } + + global_config_file = os.path.join(fixtures, 'cdist-global.cfg') + with open(global_config_file, 'w') as f: + config.write(f) + + expected_config_dict = { + 'GLOBAL': { + 'timestamp': True, + 'verbosity': 0, + }, + } + + config_files = (global_config_file, ) + + # bypass singleton so we can test further + cc.Configuration.instance = None + + args = argparse.Namespace() + args.timestamp = True + configuration = cc.Configuration(args, env=None, + config_files=config_files) + self.assertEqual(configuration.config, expected_config_dict) + + def test_configuration_timestamping_log_2(self): + config = newConfigParser() + config['GLOBAL'] = { + 'timestamp': 'False', + } + + global_config_file = os.path.join(fixtures, 'cdist-global.cfg') + with open(global_config_file, 'w') as f: + config.write(f) + + expected_config_dict = { + 'GLOBAL': { + 'timestamp': True, + 'verbosity': 0, + }, + } + + config_files = (global_config_file, ) + + # bypass singleton so we can test further + cc.Configuration.instance = None + + args = argparse.Namespace() + args.timestamp = True + configuration = cc.Configuration(args, env=None, + config_files=config_files) + self.assertEqual(configuration.config, expected_config_dict) + + def test_configuration_timestamping_log_3(self): + config = newConfigParser() + config['GLOBAL'] = { + 'timestamp': 'False', + } + + global_config_file = os.path.join(fixtures, 'cdist-global.cfg') + with open(global_config_file, 'w') as f: + config.write(f) + + expected_config_dict = { + 'GLOBAL': { + 'timestamp': False, + 'verbosity': 0, + }, + } + + config_files = (global_config_file, ) + + # bypass singleton so we can test further + cc.Configuration.instance = None + + args = argparse.Namespace() + args.timestamp = False + configuration = cc.Configuration(args, env=None, + config_files=config_files) + self.assertEqual(configuration.config, expected_config_dict) + + def test_configuration_timestamping_log_4(self): + config = newConfigParser() + config['GLOBAL'] = { + 'timestamp': 'True', + } + + global_config_file = os.path.join(fixtures, 'cdist-global.cfg') + with open(global_config_file, 'w') as f: + config.write(f) + + expected_config_dict = { + 'GLOBAL': { + 'timestamp': False, + 'verbosity': 0, + }, + } + + config_files = (global_config_file, ) + + # bypass singleton so we can test further + cc.Configuration.instance = None + + args = argparse.Namespace() + args.timestamp = False + configuration = cc.Configuration(args, env=None, + config_files=config_files) + self.assertEqual(configuration.config, expected_config_dict) + if __name__ == "__main__": import unittest diff --git a/docs/src/cdist-configuration.rst b/docs/src/cdist-configuration.rst index cf1e373b..4c9b4d33 100644 --- a/docs/src/cdist-configuration.rst +++ b/docs/src/cdist-configuration.rst @@ -94,6 +94,10 @@ The possible keywords and their meanings are as follows: It recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'. +:strong:`timestamp` + Timestamp log messages with the current local date and time + in the format: YYYYMMDDHHMMSS.us. + :strong:`verbosity` Set verbosity level. Valid values are: 'ERROR', 'WARNING', 'INFO', 'VERBOSE', 'DEBUG', 'TRACE' and 'OFF'. diff --git a/docs/src/man1/cdist.rst b/docs/src/man1/cdist.rst index 0a628660..3a74f1ef 100644 --- a/docs/src/man1/cdist.rst +++ b/docs/src/man1/cdist.rst @@ -521,6 +521,10 @@ The possible keywords and their meanings are as follows: It recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'. +:strong:`timestamp` + Timestamp log messages with the current local date and time + in the format: YYYYMMDDHHMMSS.us. + :strong:`verbosity` Set verbosity level. Valid values are: 'ERROR', 'WARNING', 'INFO', 'VERBOSE', 'DEBUG', 'TRACE' and 'OFF'.