本文整理汇总了Python中twisted.logger.globalLogBeginner.beginLoggingTo方法的典型用法代码示例。如果您正苦于以下问题:Python globalLogBeginner.beginLoggingTo方法的具体用法?Python globalLogBeginner.beginLoggingTo怎么用?Python globalLogBeginner.beginLoggingTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.logger.globalLogBeginner
的用法示例。
在下文中一共展示了globalLogBeginner.beginLoggingTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from twisted.logger import globalLogBeginner [as 别名]
# 或者: from twisted.logger.globalLogBeginner import beginLoggingTo [as 别名]
def init(debug=False):
debug_enabled = debug or os.environ.get('DEBUG', False)
logging_level = logging.DEBUG if debug_enabled else logging.INFO
logging.basicConfig(level=logging_level,
format='%(asctime)s [%(name)s] %(levelname)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
filemode='a')
logging.getLogger('gnupg').setLevel(logging.WARN)
logging.getLogger('gnupg').addFilter(PrivateKeyFilter())
def formatter(event):
try:
event['log_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(event['log_time']))
event['log_level'] = event['log_level'].name.upper()
event['log_format'] = str(event['log_format']) + '\n' if event.get('log_format') else ''
logstring = u'{log_time} [{log_namespace}] {log_level} ' + event['log_format']
return logstring.format(**event)
except Exception as e:
return "Error while formatting log event: {!r}\nOriginal event: {!r}\n".format(e, event)
observers = [FileLogObserver(sys.stdout, formatter)]
globalLogBeginner.beginLoggingTo(observers)
示例2: start_logging
# 需要导入模块: from twisted.logger import globalLogBeginner [as 别名]
# 或者: from twisted.logger.globalLogBeginner import beginLoggingTo [as 别名]
def start_logging(out=_stdout, level='info'):
"""
Start logging to the file-like object in ``out``. By default, this
is stdout.
"""
global _loggers, _observer, _log_level, _started_logging
if level not in log_levels:
raise RuntimeError(
"Invalid log level '{0}'; valid are: {1}".format(
level, ', '.join(log_levels)
)
)
if _started_logging:
return
_started_logging = True
_log_level = level
set_global_log_level(_log_level)
if out:
_observer = _LogObserver(out)
_observers = []
if _observer:
_observers.append(_observer)
globalLogBeginner.beginLoggingTo(_observers)
示例3: init_logging
# 需要导入模块: from twisted.logger import globalLogBeginner [as 别名]
# 或者: from twisted.logger.globalLogBeginner import beginLoggingTo [as 别名]
def init_logging(configuration, program_name):
"""Given a basic configuration, set up logging."""
logging.init_app_logging(configuration.log_dir, configuration.log_level,
progname=program_name,
quiet=configuration.quiet)
# Initialize twisted logging, even if we don't explicitly use it,
# because of leaky logs https://twistedmatrix.com/trac/ticket/8164
globalLogBeginner.beginLoggingTo(
[lambda _: None], redirectStandardIO=False, discardBuffer=True)
示例4: twlog
# 需要导入模块: from twisted.logger import globalLogBeginner [as 别名]
# 或者: from twisted.logger.globalLogBeginner import beginLoggingTo [as 别名]
def twlog():
from sys import stdout
from twisted.logger import globalLogBeginner
from twisted.logger import textFileLogObserver
globalLogBeginner.beginLoggingTo([textFileLogObserver(stdout)])