# log2mongo **Repository Path**: revol/log2mongo ## Basic Information - **Project Name**: log2mongo - **Description**: 存储到mongodb的日志系统 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2015-07-23 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #Log2Mongo >Log2mongo is a logging package that makes it easy to log your logs into [MongoDB](http://www.mongodb.org) #Quick Start ```python from log2mongo import L2M logger=L2M.getlogger('logger_name') # all logger method will automatic log the datetime and level # error, debug, warning will automatic log the frame state logger.error(Exception('simple exception'))# just log the exception object logger.debug('debug message')# will be ignored if logger's level is not L2M.DEBUG logger.warning('warning message') # no frame logged logger.info('info')# just log a message logger.cache({'student':student_id, 'method':'update_student_grade', 'value':{'grade':80,'average':75} })# log a BSON valid document directly into MongoDB ``` #Advanced Tutorial ##basicConfig ```python from log2mongo import L2M L2M.basicConfig({'password':'11111', 'level':L2M.DEBUG}) # bacicConfig will affect all the loggers created afterwards logger=L2M.getLogger() logger.debug("by default this debug message will not be logged.") ``` ##Default Configs ```python # by default every logger will have these configs from log2mongo import MONGODB_DEFAULT_CONFIG MONGODB_DEFAULT_CONFIG = { "host": "127.0.0.1", "port": 27017, "username": "admin", "password": "123456", "database": "mongo_log", "level": 'INFO' } ``` #Cache Logger Designed for caching the calculated data that won't be stored in ordinary database by some reason. `logger.cache(record)`only accept one [BSON](https://api.mongodb.org/python/current/api/bson/index.html?highlight=valid#module-bson) argument that will be directly insert into MongoDB Just cache it #Thanks Thanks to [mongodb-log](https://github.com/puentesarrin/mongodb-log)