forked from ungleich-public/cdist
Add timestamping log option to config file.
This commit is contained in:
parent
e404ff4836
commit
82077aff25
4 changed files with 122 additions and 0 deletions
|
@ -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'),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'.
|
||||
|
|
|
@ -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'.
|
||||
|
|
Loading…
Reference in a new issue