1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-24 02:14:20 +01:00

adding the possibility to log to stdout

This commit is contained in:
kakwa 2019-02-10 18:12:45 +01:00
parent 57bcaaed66
commit e6bcf9d97d
4 changed files with 30 additions and 4 deletions

View File

@ -28,6 +28,14 @@ request.show_tracebacks = False
## error and ldapcherry log file ## error and ldapcherry log file
#log.error_file = '/tmp/ldapcherry_error.log' #log.error_file = '/tmp/ldapcherry_error.log'
#####################################
# configuration to log to stdout #
#####################################
## logger stdout for access log
#log.access_handler = 'stdout'
## logger stdout for error and ldapcherry log
#log.error_handler = 'stdout'
##################################### #####################################
# configuration to log in syslog # # configuration to log in syslog #
##################################### #####################################

View File

@ -445,16 +445,16 @@ Logging
LdapCherry has two loggers, one for errors and applicative actions (login, del/add, logout...) and one for access logs. LdapCherry has two loggers, one for errors and applicative actions (login, del/add, logout...) and one for access logs.
Each logger can be configured to log to syslog, file or be disabled. Each logger can be configured to log to **syslog**, **file**, **stdout** or be disabled.
Logging parameters: Logging parameters:
+--------------------+---------+---------------------------------+-------------------------------------------------+----------------------------------------+ +--------------------+---------+---------------------------------+-------------------------------------------------+----------------------------------------+
| Parameter | Section | Description | Values | Comment | | Parameter | Section | Description | Values | Comment |
+====================+=========+=================================+=================================================+========================================+ +====================+=========+=================================+=================================================+========================================+
| log.access_handler | global | Logger type for access log | 'syslog', 'file', 'none' | | | log.access_handler | global | Logger type for access log | 'syslog', 'file', 'stdout', 'none' | |
+--------------------+---------+---------------------------------+-------------------------------------------------+----------------------------------------+ +--------------------+---------+---------------------------------+-------------------------------------------------+----------------------------------------+
| log.error_handler | global | Logger type for applicative log | 'syslog', 'file', 'none' | | | log.error_handler | global | Logger type for applicative log | 'syslog', 'file', 'stdout', 'none' | |
+--------------------+---------+---------------------------------+-------------------------------------------------+----------------------------------------+ +--------------------+---------+---------------------------------+-------------------------------------------------+----------------------------------------+
| log.access_file | global | log file for access log | path to log file | only used if log.access_handler='file' | | log.access_file | global | log file for access log | path to log file | only used if log.access_handler='file' |
+--------------------+---------+---------------------------------+-------------------------------------------------+----------------------------------------+ +--------------------+---------+---------------------------------+-------------------------------------------------+----------------------------------------+

View File

@ -285,6 +285,15 @@ class LdapCherry(object):
handler.setFormatter(syslog_formatter) handler.setFormatter(syslog_formatter)
cherrypy.log.access_log.addHandler(handler) cherrypy.log.access_log.addHandler(handler)
# if stdout, open a logger on stdout
elif access_handler == 'stdout':
cherrypy.log.access_log.handlers = []
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(
'ldapcherry.access - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
cherrypy.log.access_log.addHandler(handler)
# if file, we keep the default # if file, we keep the default
elif access_handler == 'file': elif access_handler == 'file':
pass pass
@ -330,6 +339,15 @@ class LdapCherry(object):
handler.setFormatter(syslog_formatter) handler.setFormatter(syslog_formatter)
cherrypy.log.error_log.addHandler(handler) cherrypy.log.error_log.addHandler(handler)
# if stdout, open a logger on stdout
elif error_handler == 'stdout':
cherrypy.log.error_log.handlers = []
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(
'ldapcherry.app - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
cherrypy.log.error_log.addHandler(handler)
# if file, we keep the default # if file, we keep the default
elif error_handler == 'file': elif error_handler == 'file':
pass pass

View File

@ -152,7 +152,7 @@ class TestError(object):
def testLog(self): def testLog(self):
app = LdapCherry() app = LdapCherry()
cfg = { 'global' : {}} cfg = { 'global' : {}}
for t in ['none', 'file', 'syslog']: for t in ['none', 'file', 'syslog', 'stdout']:
cfg['global']['log.access_handler']=t cfg['global']['log.access_handler']=t
cfg['global']['log.error_handler']=t cfg['global']['log.error_handler']=t
app._set_access_log(cfg, logging.DEBUG) app._set_access_log(cfg, logging.DEBUG)