Merge pull request #692 from darko-poljak/log-timestamping-config

Add timestamping log option to config file.
This commit is contained in:
Darko Poljak 2018-09-28 14:22:59 +02:00 committed by GitHub
commit f705fe8fc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 0 deletions

View file

@ -261,6 +261,7 @@ _ARG_OPTION_MAPPING = {
'verbose': 'verbosity', 'verbose': 'verbosity',
'use_archiving': 'archiving', 'use_archiving': 'archiving',
'save_output_streams': 'save_output_streams', 'save_output_streams': 'save_output_streams',
'timestamp': 'timestamp',
} }
@ -304,6 +305,7 @@ class Configuration(metaclass=Singleton):
'archiving': ArchivingOption(), 'archiving': ArchivingOption(),
'save_output_streams': BooleanOption('save_output_streams', 'save_output_streams': BooleanOption('save_output_streams',
default_overrides=False), default_overrides=False),
'timestamp': BooleanOption('timestamp'),
}, },
} }

View file

@ -1296,6 +1296,118 @@ class ConfigurationTestCase(test.CdistTestCase):
self.fail("Exception should not have been raised: {}".format( self.fail("Exception should not have been raised: {}".format(
e)) 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__": if __name__ == "__main__":
import unittest import unittest

View file

@ -94,6 +94,10 @@ The possible keywords and their meanings are as follows:
It recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' It recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false'
and '1'/'0'. and '1'/'0'.
:strong:`timestamp`
Timestamp log messages with the current local date and time
in the format: YYYYMMDDHHMMSS.us.
:strong:`verbosity` :strong:`verbosity`
Set verbosity level. Valid values are: Set verbosity level. Valid values are:
'ERROR', 'WARNING', 'INFO', 'VERBOSE', 'DEBUG', 'TRACE' and 'OFF'. 'ERROR', 'WARNING', 'INFO', 'VERBOSE', 'DEBUG', 'TRACE' and 'OFF'.

View file

@ -521,6 +521,10 @@ The possible keywords and their meanings are as follows:
It recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' It recognizes boolean values from 'yes'/'no', 'on'/'off', 'true'/'false'
and '1'/'0'. and '1'/'0'.
:strong:`timestamp`
Timestamp log messages with the current local date and time
in the format: YYYYMMDDHHMMSS.us.
:strong:`verbosity` :strong:`verbosity`
Set verbosity level. Valid values are: Set verbosity level. Valid values are:
'ERROR', 'WARNING', 'INFO', 'VERBOSE', 'DEBUG', 'TRACE' and 'OFF'. 'ERROR', 'WARNING', 'INFO', 'VERBOSE', 'DEBUG', 'TRACE' and 'OFF'.