本文整理汇总了Python中twisted.logger.globalLogBeginner.beginLoggingTo函数的典型用法代码示例。如果您正苦于以下问题:Python beginLoggingTo函数的具体用法?Python beginLoggingTo怎么用?Python beginLoggingTo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了beginLoggingTo函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: startLogging
def startLogging(settings, stream=None, level=LogLevel.debug):
global predicate
fileObserver = logObserver(stream)
predicate = LogLevelFilterPredicate(defaultLogLevel=level)
if settings.options.debug_mqtt:
predicate.setLogLevelForNamespace('kotori.daq.services.mig', LogLevel.debug)
predicate.setLogLevelForNamespace('kotori.daq.application.mqttkit', LogLevel.debug)
if settings.options.debug_mqtt_driver:
predicate.setLogLevelForNamespace('kotori.daq.intercom.mqtt', LogLevel.debug)
predicate.setLogLevelForNamespace('mqtt', LogLevel.debug)
predicate.setLogLevelForNamespace('paho.mqtt', LogLevel.debug)
else:
predicate.setLogLevelForNamespace('kotori.daq.intercom.mqtt', LogLevel.info)
predicate.setLogLevelForNamespace('mqtt', LogLevel.info)
predicate.setLogLevelForNamespace('paho.mqtt', LogLevel.info)
if settings.options.debug_influx:
predicate.setLogLevelForNamespace('kotori.daq.storage.influx', LogLevel.debug)
if settings.options.debug_io:
predicate.setLogLevelForNamespace('kotori.io', LogLevel.debug)
observers = [ FilteringLogObserver(observer=fileObserver, predicates=[predicate]) ]
globalLogBeginner.beginLoggingTo(observers)
开发者ID:hiveeyes,项目名称:kotori,代码行数:27,代码来源:logger.py
示例2: run
def run(self):
self.factory = HTTPFactory(
self.channel_layer,
self.action_logger,
timeout=self.http_timeout,
websocket_timeout=self.websocket_timeout,
ping_interval=self.ping_interval,
ws_protocols=self.ws_protocols,
root_path=self.root_path,
)
# Redirect the Twisted log to nowhere
globalLogBeginner.beginLoggingTo([lambda _: None], redirectStandardIO=False, discardBuffer=True)
# Listen on a socket
if self.unix_socket:
reactor.listenUNIX(self.unix_socket, self.factory)
elif self.file_descriptor:
# socket returns the same socket if supplied with a fileno
sock = socket.socket(fileno=self.file_descriptor)
reactor.adoptStreamPort(self.file_descriptor, sock.family, self.factory)
else:
reactor.listenTCP(self.port, self.factory, interface=self.host)
if "twisted" in self.channel_layer.extensions:
logging.info("Using native Twisted mode on channel layer")
reactor.callLater(0, self.backend_reader_twisted)
else:
logging.info("Using busy-loop synchronous mode on channel layer")
reactor.callLater(0, self.backend_reader_sync)
reactor.callLater(2, self.timeout_checker)
reactor.run(installSignalHandlers=self.signal_handlers)
开发者ID:bibinjose22,项目名称:daphne,代码行数:30,代码来源:server.py
示例3: main
def main(reactor, *argv):
import argparse
a = argparse.ArgumentParser()
a.add_argument('number', type=int)
a.add_argument('subprocess', nargs='+')
args = a.parse_args(argv)
globalLogBeginner.beginLoggingTo([jsonFileLogObserver(sys.stdout)])
executablePath = distutils.spawn.find_executable(args.subprocess[0])
args.subprocess[0] = executablePath
collection = ProcessCollection()
reactor.addSystemEventTrigger("before", "shutdown", collection.stop)
processes = [RespawningProcess(reactor,
executablePath, args.subprocess,
usePTY=True)
for _ in xrange(args.number)]
collection.addProcesses(processes)
collection.start()
terminationDeferred = defer.Deferred()
stdio.StandardIO(FireOnInput(terminationDeferred))
return terminationDeferred
开发者ID:mrwsr,项目名称:solr_management,代码行数:29,代码来源:multi.py
示例4: start_logging
def start_logging(out=None, level='info'):
"""
Start logging to the file-like object in ``out``. By default, this
is stdout.
"""
global _loggers, _observer, _log_level
if level not in log_levels:
raise RuntimeError(
"Invalid log level '{0}'; valid are: {1}".format(
level, ', '.join(log_levels)
)
)
if _loggers is None:
return
if out is None:
out = _stdout
if _loggers is not None:
for ref in _loggers:
instance = ref()
if instance:
instance._set_log_level(level)
_loggers = None
_log_level = level
_observer = _LogObserver(out)
if _NEW_LOGGER:
globalLogBeginner.beginLoggingTo([_observer])
else:
from twisted.python import log
log.startLogging(out)
开发者ID:deshi-basara,项目名称:libreXC,代码行数:34,代码来源:tx.py
示例5: start_logging
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)
if _NEW_LOGGER:
_observers = []
if _observer:
_observers.append(_observer)
globalLogBeginner.beginLoggingTo(_observers)
else:
assert out, "out needs to be given a value if using Twisteds before 15.2"
from twisted.python import log
log.startLogging(out)
开发者ID:Blockshare,项目名称:Django-LandingPage-Template,代码行数:34,代码来源:tx.py
示例6: start_logging
def start_logging(level=LogLevel.info):
observers = []
predicate = LogLevelFilterPredicate(defaultLogLevel=level)
observers.append(FilteringLogObserver(observer=textFileLogObserver(sys.stdout), predicates=[predicate]))
globalLogBeginner.beginLoggingTo(observers)
开发者ID:maxpowa,项目名称:chord,代码行数:7,代码来源:util.py
示例7: run
def run(self):
self.factory = HTTPFactory(
self.channel_layer,
self.action_logger,
timeout=self.http_timeout,
websocket_timeout=self.websocket_timeout,
ping_interval=self.ping_interval,
ping_timeout=self.ping_timeout,
ws_protocols=self.ws_protocols,
root_path=self.root_path,
proxy_forwarded_address_header=self.proxy_forwarded_address_header,
proxy_forwarded_port_header=self.proxy_forwarded_port_header
)
if self.verbosity <= 1:
# Redirect the Twisted log to nowhere
globalLogBeginner.beginLoggingTo([lambda _: None], redirectStandardIO=False, discardBuffer=True)
else:
globalLogBeginner.beginLoggingTo([STDLibLogObserver(__name__)])
# Disabled deliberately for the moment as it's worse performing
if "twisted" in self.channel_layer.extensions and False:
logger.info("Using native Twisted mode on channel layer")
reactor.callLater(0, self.backend_reader_twisted)
else:
logger.info("Using busy-loop synchronous mode on channel layer")
reactor.callLater(0, self.backend_reader_sync)
reactor.callLater(2, self.timeout_checker)
for socket_description in self.endpoints:
logger.info("Listening on endpoint %s" % socket_description)
# Twisted requires str on python2 (not unicode) and str on python3 (not bytes)
ep = serverFromString(reactor, str(socket_description))
ep.listen(self.factory)
reactor.run(installSignalHandlers=self.signal_handlers)
开发者ID:SmartImpulse,项目名称:daphne,代码行数:35,代码来源:server.py
示例8: main
def main(reactor, *argv):
argument_parser = argparse.ArgumentParser()
argument_parser.add_argument('solr_url')
argument_parser.add_argument('json_docs')
args = argument_parser.parse_args(argv)
globalLogBeginner.beginLoggingTo([jsonFileLogObserver(sys.stdout)])
return replay(args.json_docs, args.solr_url)
开发者ID:mrwsr,项目名称:solr_management,代码行数:10,代码来源:replay.py
示例9: create_server
def create_server(
host="localhost", port=5000, debug=False,
observer_name="twisted", flask_app=None
):
"""
Create and setup twisted server
(only need to do a reactor.run() after)
:param host: Host address to bind to (default: localhost)
:type host: str
:param port: Port to bind to (default: 5000)
:type port: int
:param debug: Should use debug mode (default: False)
:type debug: bool
:param observer_name: Name of twisted observer to log to stdlib
(default: twisted)
if None -> do not create observer
:type observer_name: None | str
:param flask_app: Flask object to be served (default: None)
if None -> use imported app
:type flask_app: flask.Flask
:rtype: None
"""
if observer_name is not None:
observer = STDLibLogObserver(name=observer_name)
globalLogBeginner.beginLoggingTo([observer])
if flask_app is None:
flask_app = create_app(debug=debug)
# Create a Twisted Web resource for our WebSocket server
ws_factory = WebSocketServerFactory(
u"ws://{}:{}".format(host, port)
)
ws_factory.protocol = PluginServerProtocol
# Needed if Hixie76 is to be supported
# ws_factory.setProtocolOptions(allowHixie76=True)
ws_resource = WebSocketResource(ws_factory)
# Create a Twisted Web WSGI resource for our Flask server
wsgi_resource = WSGIResource(reactor, reactor.getThreadPool(), flask_app)
# Create a root resource serving everything via WSGI/Flask, but
# The path "/ws" served by our webocket
root_resource = WSGIRootResource(wsgi_resource, {'ws': ws_resource})
# Create a Twisted Web Site and run everything
site = Site(root_resource)
# Needed if Hixie76 is to be supported
# site.protocol = HTTPChannelHixie76Aware
reactor.listenTCP(port, site)
开发者ID:the01,项目名称:paps-settings,代码行数:52,代码来源:server.py
示例10: startLogging
def startLogging(console=True, filepath=None):
'''
Starts the global Twisted logger subsystem with maybe
stdout and/or a file specified in the config file
'''
global logLevelFilterPredicate
observers = []
if console:
observers.append( FilteringLogObserver(observer=textFileLogObserver(sys.stdout),
predicates=[logLevelFilterPredicate] ))
if filepath is not None and filepath != "":
observers.append( FilteringLogObserver(observer=textFileLogObserver(open(filepath,'a')),
predicates=[logLevelFilterPredicate] ))
globalLogBeginner.beginLoggingTo(observers)
开发者ID:yuregir,项目名称:AGR,代码行数:16,代码来源:sensormanager.py
示例11: go
def go(self, reactor):
data = Data("Hello world\n", "text/plain")
data.putChild("", data)
factory = Site(data)
# TODO: adoptStreamConnection should really support AF_UNIX
protocol = ConnectionFromManager(reactor, factory)
skt = fromfd(MAGIC_FILE_DESCRIPTOR, AF_UNIX, SOCK_STREAM)
os.close(MAGIC_FILE_DESCRIPTOR)
serverTransport = UNIXServer(skt, protocol, None, None, 1234, reactor)
protocol.makeConnection(serverTransport)
serverTransport.startReading()
globalLogBeginner.beginLoggingTo([protocol.sendLog])
factory.doStart()
return Deferred()
开发者ID:glyph,项目名称:WarpedAlloy,代码行数:17,代码来源:__init__.py
示例12: _reactor_start
def _reactor_start(self):
"""
Start the reactor if it is not already running
If someone else started it -> someone else should shut it down
"""
try:
if reactor.running:
observer = STDLibLogObserver(name='twisted')
globalLogBeginner.beginLoggingTo([observer])
reactor.run(False)
else:
self.info("Reactor already running")
self._reactor_shutdown = False
except ReactorAlreadyRunning:
self.info("Reactor already running")
self._reactor_shutdown = False
except:
self.exception("Failed to start reactor")
开发者ID:the01,项目名称:paps-realtime,代码行数:18,代码来源:plugin.py
示例13: startLogging
def startLogging(self):
"""
Start the L{twisted.logger} logging system.
"""
logFile = self.logFile
fileLogObserverFactory = self.fileLogObserverFactory
fileLogObserver = fileLogObserverFactory(logFile)
logLevelPredicate = LogLevelFilterPredicate(
defaultLogLevel=self.defaultLogLevel
)
filteringObserver = FilteringLogObserver(
fileLogObserver, [logLevelPredicate]
)
globalLogBeginner.beginLoggingTo([filteringObserver])
开发者ID:dansgithubuser,项目名称:constructicon,代码行数:19,代码来源:_runner.py
示例14: run
def run():
from twisted.internet import reactor
root = logging.getLogger()
logging.getLogger('django').setLevel(logging.INFO)
logging.raiseExceptions = settings.DEBUG
logging._srcfile = None # Disable expensive collection of location information.
root.setLevel(logging.DEBUG if settings.DEBUG else logging.INFO)
root.addHandler(TwistedLoggerLogHandler())
observer = FilteringLogObserver(
FileLogObserver(sys.stdout, formatForSystemd),
[dropUnhandledHTTP2Shutdown],
)
globalLogBeginner.beginLoggingTo([observer], redirectStandardIO=False)
log.info("Yarrharr {version} starting", version=__version__)
factory = Site(Root(reactor, reactor.getThreadPool()), logPath=None)
endpoint = serverFromString(reactor, settings.SERVER_ENDPOINT)
reactor.addSystemEventTrigger('before', 'startup', endpoint.listen, factory)
updateLoop = AdaptiveLoopingCall(reactor, lambda: updateFeeds(reactor))
loopEndD = updateLoop.start()
loopEndD.addErrback(lambda f: log.failure("Polling loop broke", f))
@receiver(schedule_changed)
def threadPollNow(sender, **kwargs):
"""
When the `schedule_changed` signal is sent poke the polling loop. If it
is sleeping this will cause it to poll immediately. Otherwise this will
cause it to run the poll function immediately once it returns (running
it again protects against races).
"""
log.debug("Immediate poll triggered by {sender}", sender=sender)
reactor.callFromThread(updateLoop.poke)
def stopUpdateLoop():
updateLoop.stop()
return loopEndD
reactor.addSystemEventTrigger('before', 'shutdown', stopUpdateLoop)
reactor.run()
开发者ID:twm,项目名称:yarrharr,代码行数:43,代码来源:application.py
示例15: init
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):
event['log_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(event['log_time']))
event['log_level'] = event['log_level'].name.upper()
logstring = u'{log_time} [{log_namespace}] {log_level} ' + event['log_format'] + '\n'
return logstring.format(**event)
observers = [FileLogObserver(sys.stdout, formatter)]
globalLogBeginner.beginLoggingTo(observers)
开发者ID:bwagnerr,项目名称:pixelated-user-agent,代码行数:21,代码来源:logger.py
示例16: start
def start(syslog=False, logfile=None, syslog_prefix='lumina', redirect_stdio=False,
loglevel=None):
''' Start the custom logger '''
# System defaults from twisted.logger._global.py:
# globalLogPublisher = LogPublisher()
# globalLogBeginner = LogBeginner(globalLogPublisher, sys.stderr, sys, warnings)
if logfile is None:
logfile = sys.stdout
if loglevel is None:
loglevel = LogLevel.info
# Lumina log observers
if syslog and SYSLOG_IMPORTED:
out_observer = SyslogObserver(prefix=syslog_prefix)
else:
out_observer = FileLogObserver(sys.stdout, formatLuminaLogText)
#level_filter = LogLevelFilterPredicate(defaultLogLevel=loglevel)
#level_filter.setLogLevelForNamespace('server', LogLevel.warn)
observers = (
LuminaLogFormatter(),
FilteringLogObserver(
out_observer,
[ #level_filter,
LuminaFilterPredicate(minimumLoglevel=loglevel),
]
),
)
# This logger will take over the system (the default LogPublisher). It will
# iterate over any messages that has already been logged prior to
# this registration. However, any errors in the observers will be silently
# ignored because the observers are no longer run through the
# LogPublisher()
globalLogBeginner.beginLoggingTo(observers,
redirectStandardIO=redirect_stdio)
开发者ID:sveinse,项目名称:lumina,代码行数:40,代码来源:log.py
示例17: setup_logging
def setup_logging(config, use_worker_options=False):
""" Set up python logging
Args:
config (LoggingConfig | synapse.config.workers.WorkerConfig):
configuration data
use_worker_options (bool): True to use 'worker_log_config' and
'worker_log_file' options instead of 'log_config' and 'log_file'.
"""
log_config = (config.worker_log_config if use_worker_options
else config.log_config)
log_file = (config.worker_log_file if use_worker_options
else config.log_file)
log_format = (
"%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s"
" - %(message)s"
)
if log_config is None:
# We don't have a logfile, so fall back to the 'verbosity' param from
# the config or cmdline. (Note that we generate a log config for new
# installs, so this will be an unusual case)
level = logging.INFO
level_for_storage = logging.INFO
if config.verbosity:
level = logging.DEBUG
if config.verbosity > 1:
level_for_storage = logging.DEBUG
logger = logging.getLogger('')
logger.setLevel(level)
logging.getLogger('synapse.storage.SQL').setLevel(level_for_storage)
formatter = logging.Formatter(log_format)
if log_file:
# TODO: Customisable file size / backup count
handler = logging.handlers.RotatingFileHandler(
log_file, maxBytes=(1000 * 1000 * 100), backupCount=3
)
def sighup(signum, stack):
logger.info("Closing log file due to SIGHUP")
handler.doRollover()
logger.info("Opened new log file due to SIGHUP")
else:
handler = logging.StreamHandler()
def sighup(signum, stack):
pass
handler.setFormatter(formatter)
handler.addFilter(LoggingContextFilter(request=""))
logger.addHandler(handler)
else:
def load_log_config():
with open(log_config, 'r') as f:
logging.config.dictConfig(yaml.load(f))
def sighup(signum, stack):
# it might be better to use a file watcher or something for this.
logging.info("Reloading log config from %s due to SIGHUP",
log_config)
load_log_config()
load_log_config()
# TODO(paul): obviously this is a terrible mechanism for
# stealing SIGHUP, because it means no other part of synapse
# can use it instead. If we want to catch SIGHUP anywhere
# else as well, I'd suggest we find a nicer way to broadcast
# it around.
if getattr(signal, "SIGHUP"):
signal.signal(signal.SIGHUP, sighup)
# It's critical to point twisted's internal logging somewhere, otherwise it
# stacks up and leaks kup to 64K object;
# see: https://twistedmatrix.com/trac/ticket/8164
#
# Routing to the python logging framework could be a performance problem if
# the handlers blocked for a long time as python.logging is a blocking API
# see https://twistedmatrix.com/documents/current/core/howto/logger.html
# filed as https://github.com/matrix-org/synapse/issues/1727
#
# However this may not be too much of a problem if we are just writing to a file.
observer = STDLibLogObserver()
globalLogBeginner.beginLoggingTo(
[observer],
redirectStandardIO=not config.no_redirect_stdio,
)
开发者ID:rubo77,项目名称:synapse,代码行数:94,代码来源:logger.py
示例18: LayeredTwistedIOLoop
# Since we're not using twisted's test runner, it's tricky to get
# logging set up well. Most of the time it's easiest to just
# leave it turned off, but while working on these tests you may want
# to uncomment one of the other lines instead.
log.defaultObserver.stop()
# import sys; log.startLogging(sys.stderr, setStdout=0)
# log.startLoggingWithObserver(log.PythonLoggingObserver().emit, setStdout=0)
# import logging; logging.getLogger('twisted').setLevel(logging.WARNING)
# Twisted recently introduced a new logger; disable that one too.
try:
from twisted.logger import globalLogBeginner
except ImportError:
pass
else:
globalLogBeginner.beginLoggingTo([])
if have_twisted:
class LayeredTwistedIOLoop(TwistedIOLoop):
"""Layers a TwistedIOLoop on top of a TornadoReactor on a SelectIOLoop.
This is of course silly, but is useful for testing purposes to make
sure we're implementing both sides of the various interfaces
correctly. In some tests another TornadoReactor is layered on top
of the whole stack.
"""
def initialize(self, **kwargs):
# When configured to use LayeredTwistedIOLoop we can't easily
# get the next-best IOLoop implementation, so use the lowest common
# denominator.
self.real_io_loop = SelectIOLoop(make_current=False)
开发者ID:nobolis,项目名称:tornado,代码行数:31,代码来源:twisted_test.py
示例19: LayeredTwistedIOLoop
# Since we're not using twisted's test runner, it's tricky to get
# logging set up well. Most of the time it's easiest to just
# leave it turned off, but while working on these tests you may want
# to uncomment one of the other lines instead.
log.defaultObserver.stop()
# import sys; log.startLogging(sys.stderr, setStdout=0)
# log.startLoggingWithObserver(log.PythonLoggingObserver().emit, setStdout=0)
# import logging; logging.getLogger('twisted').setLevel(logging.WARNING)
# Twisted recently introduced a new logger; disable that one too.
try:
from twisted.logger import globalLogBeginner
except ImportError:
pass
else:
globalLogBeginner.beginLoggingTo([], redirectStandardIO=False)
if have_twisted:
class LayeredTwistedIOLoop(TwistedIOLoop):
"""Layers a TwistedIOLoop on top of a TornadoReactor on a SelectIOLoop.
This is of course silly, but is useful for testing purposes to make
sure we're implementing both sides of the various interfaces
correctly. In some tests another TornadoReactor is layered on top
of the whole stack.
"""
def initialize(self, **kwargs):
# When configured to use LayeredTwistedIOLoop we can't easily
# get the next-best IOLoop implementation, so use the lowest common
开发者ID:emehrkay,项目名称:tornado,代码行数:31,代码来源:twisted_test.py
示例20: configure_logging
def configure_logging():
logging.basicConfig(level=logging.INFO)
globalLogBeginner.beginLoggingTo([STDLibLogObserver(name='shinysdr')])
开发者ID:kpreid,项目名称:shinysdr,代码行数:3,代码来源:main.py
注:本文中的twisted.logger.globalLogBeginner.beginLoggingTo函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论