mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add "profile" loglevel
This commit is contained in:
parent
5560cb662b
commit
5a2b94ce39
2 changed files with 17 additions and 1 deletions
|
@ -17,6 +17,15 @@ import sys
|
|||
import logging
|
||||
|
||||
|
||||
class LoggingProfileMixIn(object):
|
||||
'''
|
||||
Simple mix-in class to add a trace method to python's logging.
|
||||
'''
|
||||
|
||||
def profile(self, msg, *args, **kwargs):
|
||||
self.log(getattr(logging, 'PROFILE', 15), msg, *args, **kwargs)
|
||||
|
||||
|
||||
class LoggingTraceMixIn(object):
|
||||
'''
|
||||
Simple mix-in class to add a trace method to python's logging.
|
||||
|
@ -45,7 +54,7 @@ class LoggingMixInMeta(type):
|
|||
the bases.
|
||||
'''
|
||||
def __new__(mcs, name, bases, attrs):
|
||||
include_trace = include_garbage = True
|
||||
include_profile = include_trace = include_garbage = True
|
||||
bases = list(bases)
|
||||
if name == 'SaltLoggingClass':
|
||||
for base in bases:
|
||||
|
@ -53,6 +62,8 @@ class LoggingMixInMeta(type):
|
|||
include_trace = False
|
||||
if hasattr(base, 'garbage'):
|
||||
include_garbage = False
|
||||
if include_profile:
|
||||
bases.append(LoggingProfileMixIn)
|
||||
if include_trace:
|
||||
bases.append(LoggingTraceMixIn)
|
||||
if include_garbage:
|
||||
|
|
|
@ -30,6 +30,7 @@ from salt.ext.six.moves.urllib.parse import urlparse # pylint: disable=import-e
|
|||
|
||||
# Let's define these custom logging levels before importing the salt.log.mixins
|
||||
# since they will be used there
|
||||
PROFILE = logging.PROFILE = 15
|
||||
TRACE = logging.TRACE = 5
|
||||
GARBAGE = logging.GARBAGE = 1
|
||||
QUIET = logging.QUIET = 1000
|
||||
|
@ -47,6 +48,7 @@ LOG_LEVELS = {
|
|||
'critical': logging.CRITICAL,
|
||||
'garbage': GARBAGE,
|
||||
'info': logging.INFO,
|
||||
'profile': PROFILE,
|
||||
'quiet': QUIET,
|
||||
'trace': TRACE,
|
||||
'warning': logging.WARNING,
|
||||
|
@ -60,6 +62,7 @@ LOG_COLORS = {
|
|||
'ERROR': TextFormat('bold', 'red'),
|
||||
'WARNING': TextFormat('bold', 'yellow'),
|
||||
'INFO': TextFormat('bold', 'green'),
|
||||
'PROFILE': TextFormat('bold', 'cyan'),
|
||||
'DEBUG': TextFormat('bold', 'cyan'),
|
||||
'TRACE': TextFormat('bold', 'magenta'),
|
||||
'GARBAGE': TextFormat('bold', 'blue'),
|
||||
|
@ -71,6 +74,7 @@ LOG_COLORS = {
|
|||
'ERROR': TextFormat('red'),
|
||||
'WARNING': TextFormat('yellow'),
|
||||
'INFO': TextFormat('green'),
|
||||
'PROFILE': TextFormat('bold', 'cyan'),
|
||||
'DEBUG': TextFormat('cyan'),
|
||||
'TRACE': TextFormat('magenta'),
|
||||
'GARBAGE': TextFormat('blue'),
|
||||
|
@ -328,6 +332,7 @@ if logging.getLoggerClass() is not SaltLoggingClass:
|
|||
|
||||
logging.setLoggerClass(SaltLoggingClass)
|
||||
logging.addLevelName(QUIET, 'QUIET')
|
||||
logging.addLevelName(PROFILE, 'PROFILE')
|
||||
logging.addLevelName(TRACE, 'TRACE')
|
||||
logging.addLevelName(GARBAGE, 'GARBAGE')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue