plugins/python/regress: add a test and example of using the python logger
This commit is contained in:

committed by
Todd C. Miller

parent
c039a99c10
commit
6c9515496d
@@ -1,5 +1,7 @@
|
||||
import sudo
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
class DebugDemoPlugin(sudo.Plugin):
|
||||
"""
|
||||
@@ -61,6 +63,15 @@ class DebugDemoPlugin(sudo.Plugin):
|
||||
sudo.debug(sudo.DEBUG.INFO, "My demo purpose plugin shows "
|
||||
"this INFO level debug message")
|
||||
|
||||
# You can also use python log system, because sudo sets its log handler
|
||||
# on the root logger.
|
||||
# Note that the level of python logging is separate than the one set in
|
||||
# sudo.conf. If using the python logger, each will have effect.
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.error("Python log system shows this ERROR level debug message")
|
||||
logger.info("Python log system shows this INFO level debug message")
|
||||
|
||||
# If you raise the level to info or below, the call of the debug
|
||||
# will also be logged.
|
||||
# An example output you will see in the debug log file:
|
||||
|
Reference in New Issue
Block a user