normalize bool conversion, introduced common helper function `_as_bool`

pull/2133/head
sebres 7 years ago
parent 60b36c4213
commit 1b4ba602ba

@ -29,7 +29,7 @@ import os
from ConfigParser import NoOptionError, NoSectionError
from .configparserinc import sys, SafeConfigParserWithIncludes, logLevel
from ..helpers import getLogger, _merge_dicts, substituteRecursiveTags
from ..helpers import getLogger, _as_bool, _merge_dicts, substituteRecursiveTags
# Gets the instance of the logger.
logSys = getLogger(__name__)
@ -339,7 +339,7 @@ class DefinitionInitConfigReader(ConfigReader):
def _convert_to_boolean(self, value):
return value.lower() in ("1", "yes", "true", "on")
return _as_bool(value)
def getCombOption(self, optname):
"""Get combined definition option (as string) using pre-set and init

@ -244,6 +244,10 @@ else:
return uni_decode(x, enc, 'replace')
def _as_bool(val):
return bool(val) if not isinstance(val, basestring) \
else val.lower() in ('1', 'on', 'true', 'yes')
#
# Following function used for parse options from parameter (e.g. `name[p1=0, p2="..."][p3='...']`).
#

@ -37,7 +37,8 @@ from .filter import FileFilter, JournalFilter
from .transmitter import Transmitter
from .asyncserver import AsyncServer, AsyncServerException
from .. import version
from ..helpers import getLogger, extractOptions, str2LogLevel, getVerbosityFormat, excepthook
from ..helpers import getLogger, _as_bool, extractOptions, str2LogLevel, \
getVerbosityFormat, excepthook
# Gets the instance of the logger.
logSys = getLogger(__name__)
@ -313,7 +314,7 @@ class Server:
# Filter
def setIgnoreSelf(self, name, value):
self.__jails[name].filter.ignoreSelf = value
self.__jails[name].filter.ignoreSelf = _as_bool(value)
def getIgnoreSelf(self, name):
return self.__jails[name].filter.ignoreSelf
@ -628,11 +629,11 @@ class Server:
# If handler don't already add date to the message:
addtime = logOptions.get('datetime')
if addtime is not None:
addtime = addtime in ('1', 'on', 'true', 'yes')
addtime = _as_bool(addtime)
else:
addtime = systarget not in ("SYSLOG", "SYSOUT")
if padding is not None:
padding = padding in ('1', 'on', 'true', 'yes')
padding = _as_bool(padding)
else:
padding = True
# If log-format is redefined in options:

Loading…
Cancel
Save