diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/loglinegenerator.py | 7 | ||||
-rw-r--r-- | service/pixelated/application.py | 18 | ||||
-rw-r--r-- | service/twisted/plugins/logger.py | 15 |
3 files changed, 40 insertions, 0 deletions
diff --git a/service/loglinegenerator.py b/service/loglinegenerator.py new file mode 100644 index 00000000..3b7820fb --- /dev/null +++ b/service/loglinegenerator.py @@ -0,0 +1,7 @@ +from zope.interface import Interface + + +class ILogLineGenerator(Interface): + def getLogLine(self): + """ Return a string that will be logged, or None. This method will be called every second. + """ diff --git a/service/pixelated/application.py b/service/pixelated/application.py index 03b4417f..2bb5cb9b 100644 --- a/service/pixelated/application.py +++ b/service/pixelated/application.py @@ -28,6 +28,8 @@ from twisted.cred.checkers import AllowAnonymousAccess, FilePasswordDB from twisted.internet import defer from twisted.internet import reactor from twisted.internet import ssl +from twisted.internet.task import LoopingCall +from twisted.plugin import getPlugins from pixelated.adapter.welcome_mail import add_welcome_mail from pixelated.config import arguments @@ -39,6 +41,7 @@ from pixelated.config.site import PixelatedSite from pixelated.resources.auth import LeapPasswordChecker, PixelatedRealm, PixelatedAuthSessionWrapper, SessionChecker from pixelated.resources.login_resource import LoginResource from pixelated.resources.root_resource import RootResource +from loglinegenerator import ILogLineGenerator log = logging.getLogger(__name__) @@ -98,6 +101,7 @@ def initialize(): def start(): start_async = _start_mode(args, resource, services_factory) + start_plugins() add_top_level_system_callbacks(start_async, services_factory) log.info('Running the reactor') @@ -105,6 +109,18 @@ def initialize(): reactor.run() +def start_plugins(): + log.info('start_plugins') + + def logGeneratedLines(): + for p in getPlugins(ILogLineGenerator): + logLine = p.getLogLine() + if logLine is not None: + log.info(logLine) + + LoopingCall(logGeneratedLines).start(1) + + def add_top_level_system_callbacks(deferred, services_factory): def _quit_on_error(failure): @@ -125,6 +141,7 @@ def add_top_level_system_callbacks(deferred, services_factory): def _start_mode(args, resource, services_factory): + log.debug('_start_mode') if services_factory.mode.is_single_user: deferred = _start_in_single_user_mode(args, resource, services_factory) else: @@ -192,6 +209,7 @@ def _start_in_single_user_mode(args, resource, services_factory): def start_site(config, resource): log.info('Starting the API on port %s' % config.port) + if config.manhole: log.info('Starting the manhole on port 8008') diff --git a/service/twisted/plugins/logger.py b/service/twisted/plugins/logger.py new file mode 100644 index 00000000..b466d015 --- /dev/null +++ b/service/twisted/plugins/logger.py @@ -0,0 +1,15 @@ +import gc +import sys + +from zope.interface import implementer +from twisted.plugin import IPlugin +from loglinegenerator import ILogLineGenerator + + +@implementer(IPlugin, ILogLineGenerator) +class GCLogger(): + def getLogLine(self): + return '%010d' % sum(sys.getsizeof(o) for o in gc.get_objects()) + + +gcLogger = GCLogger() |