Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / custom_logger.py
blobd651612b00a0aa15bf466896d51a3e5adf8278f1
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import logging
7 from environment import IsAppEngine
10 class CustomLogger(object):
11 '''Wraps logging methods to include a prefix and flush immediately.
12 The flushing is important because logging is often done from jobs
13 which may time out, thus losing unflushed logs.
14 '''
15 def __init__(self, prefix):
16 self._prefix = prefix
18 def info(self, msg, *args): self._log(logging.info, msg, args)
19 def warning(self, msg, *args): self._log(logging.warning, msg, args)
20 def error(self, msg, *args): self._log(logging.error, msg, args)
22 def _log(self, logfn, msg, args):
23 try:
24 logfn('%s: %s' % (self._prefix, msg), *args)
25 finally:
26 self.flush()
28 if IsAppEngine():
29 from google.appengine.api.logservice import logservice
30 def flush(self):
31 logservice.flush()
32 else:
33 def flush(self):
34 pass