Some more logging stuff...
This commit is contained in:
parent
60d4cd9dd8
commit
e665933bfb
9 changed files with 34 additions and 21 deletions
|
|
@ -34,7 +34,7 @@ from linspector.core.monitors import Monitors
|
|||
|
||||
# i currently only increase the 3rd number because the goal is that 0.19 will become the first
|
||||
# stable version.
|
||||
__version__ = '0.19.29.dev1'
|
||||
__version__ = '0.19.30.dev1'
|
||||
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
||||
|
||||
logger = logging.getLogger('linspector')
|
||||
|
|
@ -61,6 +61,9 @@ def parse_args():
|
|||
parser.add_argument('-s', '--stdout', default=False, dest='stdout', action='store_true',
|
||||
help='log to stdout')
|
||||
|
||||
parser.add_argument('-V', '--verbose', default=False, dest='verbose', action='store_true',
|
||||
help='log in debug mode')
|
||||
|
||||
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + str(__version__))
|
||||
|
||||
return parser.parse_args()
|
||||
|
|
@ -79,9 +82,13 @@ def main():
|
|||
tasks = {}
|
||||
|
||||
if args.stdout:
|
||||
# setting pre initialization default log level to INFO. this changes after initialization
|
||||
# of the configuration. maybe there are better solutions...?
|
||||
logger.setLevel(logging.INFO)
|
||||
if args.verbose:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
else:
|
||||
# setting pre initialization default log level to INFO. this changes after
|
||||
# initialization of the configuration. maybe there are better solutions...?
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
stdout_formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s')
|
||||
stdout_handler = logging.StreamHandler(sys.stdout)
|
||||
stdout_handler.setFormatter(stdout_formatter)
|
||||
|
|
@ -89,7 +96,7 @@ def main():
|
|||
|
||||
try:
|
||||
configuration = Configuration(args.configuration_path, environment)
|
||||
#configuration.dump_to_ini()
|
||||
logger.debug('configuration dump: ' + configuration.dump_to_ini())
|
||||
except Exception as err:
|
||||
logger.critical('[linspector] configuration error: {0}'.format(err))
|
||||
sys.exit(1)
|
||||
|
|
@ -103,15 +110,14 @@ def main():
|
|||
logging.Formatter('[%(asctime)s]:[%(levelname)s]:[%(name)s]:%(message)s')
|
||||
|
||||
if configuration.get_option('linspector', 'log_file_size'):
|
||||
log_file_size_mb = int(configuration.get_option('linspector', 'log_file_size'))
|
||||
b = 1000000
|
||||
log_file_size_bytes = int(log_file_size_mb * b)
|
||||
log_file_size_mb = float(configuration.get_option('linspector', 'log_file_size'))
|
||||
log_file_size_bytes = float(log_file_size_mb * 1000000)
|
||||
elif configuration.get_option('linspector', 'log_file_size_bytes'):
|
||||
log_file_size_bytes = int(configuration.get_option('linspector',
|
||||
'log_file_size_bytes'))
|
||||
log_file_size_bytes = float(configuration.get_option('linspector',
|
||||
'log_file_size_bytes'))
|
||||
else:
|
||||
# default log file size is 10MB
|
||||
log_file_size_bytes = 10485760
|
||||
log_file_size_bytes = float(10485760)
|
||||
|
||||
if configuration.get_option('linspector', 'log_file_count'):
|
||||
log_file_count = int(configuration.get_option('linspector', 'log_file_count'))
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@ error_receivers = admin@example.com
|
|||
; available log levels are: "error", "warning", "info" and "debug".
|
||||
log_level= debug
|
||||
log_file = ~/code/linspector/linspector/log/linspector.log
|
||||
; number of log files to be kept.
|
||||
; number of log files to be kept. i recommend to use the lowest sensible value for keeping performance hight. so set
|
||||
; the size of the log file higher to increase the log history.
|
||||
log_file_count = 50
|
||||
; log file size in megabytes as int.
|
||||
; log file size in megabytes as float.
|
||||
log_file_size = 1
|
||||
; log file size in bytes as int. you can set to bytes if you want to set a value lower then 1 megabyte. but it will
|
||||
; only be used when log_file_size is not set.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ service = net.fritzboxuplink
|
|||
hosts = 192.168.0.1,192.168.23.24,@group1,@testgroup1
|
||||
interval = 60
|
||||
|
||||
; optional options when using notifications, plugins, services or tasks:
|
||||
; optional options when using notifications, plugins, services or tasks. btw. they still can be a required argument by
|
||||
; a corresponding notification, plugin, service or task. they will need to check required args by themself and throw an
|
||||
; exception if something fails. linspector never knows about required args:
|
||||
[args]
|
||||
; notifications separated by ','. no whitespaces allowed. the case is not important.
|
||||
notifications = sms,emaiL
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[monitor]
|
||||
description = Test10
|
||||
service = misc.dummy
|
||||
interval = 60
|
||||
interval = 120
|
||||
hosts = 192.168.10.10
|
||||
|
||||
[args]
|
||||
|
|
|
|||
|
|
@ -5,3 +5,4 @@ interval = 10
|
|||
hosts = 192.168.10.10
|
||||
|
||||
[args]
|
||||
test_dummy_arg = nothing
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
[monitor]
|
||||
description = Test3
|
||||
service = misc.dummy
|
||||
interval = 120
|
||||
interval = 5
|
||||
hosts = 192.168.10.10
|
||||
|
||||
[args]
|
||||
foo = bar
|
||||
|
|
|
|||
|
|
@ -50,16 +50,18 @@ class Configuration:
|
|||
source_section_option))
|
||||
|
||||
def dump_to_ini(self):
|
||||
dump = ''
|
||||
i = 0
|
||||
for section in self.__configuration.sections():
|
||||
if i < 1:
|
||||
print('[' + section + ']')
|
||||
dump = dump + '[' + section + ']\n'
|
||||
else:
|
||||
print('\n[' + section + ']')
|
||||
dump = dump + '\n[' + section + ']\n'
|
||||
options = self.__configuration.options(section)
|
||||
for option in options:
|
||||
print(option + " = " + self.__configuration.get(section, option))
|
||||
dump = dump + option + " = " + self.__configuration.get(section, option) + '\n'
|
||||
i = 1
|
||||
return dump
|
||||
|
||||
def get_configuration_path(self):
|
||||
return self.__configuration_path
|
||||
|
|
|
|||
|
|
@ -19,6 +19,6 @@ class DummyService(Service):
|
|||
self.__environment = environment
|
||||
|
||||
def execute(self, **kwargs):
|
||||
log('debug', 'DummyService object ' + str(self))
|
||||
log('debug', 'DummyService object ' + str(self) + ' using kwargs: ' + str(kwargs))
|
||||
#log('debug', 'dummy object @' + str(self) + str(self.__kwargs['foo']))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -21,5 +21,5 @@ class FritzboxUplinkService(Service):
|
|||
self.__environment = environment
|
||||
|
||||
def execute(self, **kwargs):
|
||||
log('debug', 'FritzboxUplinkService object ' + str(self))
|
||||
log('debug', 'FritzboxUplinkService object ' + str(self) + ' using kwargs: ' + str(kwargs))
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue