Beispiel #1
0
 def _setup_mongodb(self, logger):
     mongodb = self.config.logging.mongodb
     if mongodb:
         conn = self.config.sys.log
         if conn:
             conn = conn.connect()
             existing = conn.connection[
                 conn.database].list_collection_names()
             if conn.collection not in existing:
                 try:
                     conn.connection[conn.database].create_collection(
                         name=conn.name,
                         capped=True,
                         size=self.config.logging.size)
                     for idx in ("hostname", "identifier", "username",
                                 "qual_name"):
                         conn.create_index([("created", pymongo.DESCENDING),
                                            (idx, pymongo.DESCENDING)],
                                           name=idx)
                 except:
                     self.logger.warning("failed to create [sys.log]")
             level = getattr(logging, mongodb)
             write_concern = self.config.logging.write_concern
             handler = core4.logger.handler.MongoLoggingHandler(
                 conn.with_options(write_concern=pymongo.WriteConcern(
                     w=write_concern)))
             handler.setLevel(level)
             logger.addHandler(handler)
             self._setup_tornado(handler, level)
             self.logger.debug(
                 "mongodb logging setup complete, "
                 "level [%s], write concern [%d]", mongodb, write_concern)
         else:
             raise core4.error.Core4SetupError(
                 "config.logging.mongodb set, but config.sys.log is None")
Beispiel #2
0
 def _setup_tornado(self, handler, level):
     for name in ("access", "application", "general"):
         logger = logging.getLogger("tornado." + name)
         logger.addHandler(handler)
         logger.setLevel(level)
         f = core4.logger.filter.CoreLoggingFilter()
         logger.addFilter(f)
Beispiel #3
0
 def _setup_console(self, logger):
     log_format = self.config.logging.format
     for name in ("stdout", "stderr"):
         level = self.config.logging[name]
         if level:
             handler = logging.StreamHandler()
             handler.setLevel(getattr(logging, level))
             formatter = logging.Formatter(log_format)
             handler.setFormatter(formatter)
             logger.addHandler(handler)
             self._setup_tornado(handler, level)
             self.logger.debug("{} logging setup complete, level {}".format(
                 name, level))
Beispiel #4
0
 def add_exception_logger(self):
     if not (hasattr(self, "config") and hasattr(self, "logger")):
         raise core4.error.Core4UsageError("method requires CoreBase class")
     mongodb = self.config.logging.mongodb
     if mongodb:
         mongo_level = getattr(logging, mongodb)
         if mongo_level > logging.DEBUG:
             handler = core4.logger.exception.CoreExceptionHandler(
                 level=self.config.logging.mongodb,
                 size=self.config.logging.exception.capacity,
                 target=self.config.sys.log)
             handler.setLevel(logging.DEBUG)
             logger = logging.getLogger(self.qual_name(short=False))
             logger.addHandler(handler)
Beispiel #5
0
 def _open_logging(self):
     # open and attach logging
     global _except_hook
     self.logger_name = self.qual_name(short=False)
     logger = logging.getLogger(self.logger_name)
     level = self.log_level
     if level:
         logger.setLevel(getattr(logging, level))
     nh = logging.NullHandler()
     logger.addHandler(nh)
     f = core4.logger.filter.CoreLoggingFilter()
     logger.addFilter(f)
     # pass object reference into logging and enable lazy property access
     #   and late binding
     self.logger = core4.logger.CoreLoggingAdapter(logger, self)
     if _except_hook is None:
         _except_hook = sys.excepthook
         sys.excepthook = self.excepthook