logger_server

@Project: LoggerServer @Filename: server.py @Author: Kehr <kehr.china@gmail.com> @Created Date: 2017-11-14T19:20:37+08:00 @Last modified time: 2017-11-20T16:19:06+08:00 @License: Apache License <http://www.apache.org/licenses/LICENSE-2.0>

class logger_server.server.AttrDict[source]

Attribute dict

Make dict value can be accessed by attribute:

from logger_server import AttrDict

people = AttrDict({'name':'Joe', 'age': 23})
print people.name
print people.age
class logger_server.server.LoggerFormatter(fmt='%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s', datefmt='%y%m%d %H:%M:%S', style='%', color=True, colors={40: 1, 10: 4, 20: 2, 30: 3})[source]

format

Parameters:
  • color (bool) – Enables color support.
  • fmt (string) – Log message format. It will be applied to the attributes dict of log records. The text between %(color)s and %(end_color)s will be colored depending on the level if color support is on.
  • colors (dict) – color mappings from logging level to terminal color code
  • datefmt (string) – Datetime format. Used for formatting (asctime) placeholder in prefix_fmt.

Changed in version 3.2: Added fmt and datefmt arguments.

formatTime(record, datefmt=None)[source]

Rewrite default formatTime to support %f

Parameters:
  • record (logging.LogRecord) – logging.LogRecord object which Contains all the information pertinent to the event being logged.
  • datefmt – Datetime format string.
class logger_server.server.LoggerServer(config=None, *args, **kwargs)[source]

A logging server serve for logging.handlers.SocketHandler

Parameters:config (argparse.Namespace) – The command line parse result.

Reference: tornado.tcpserver.TCPServer

handle_stream(*args, **kwargs)[source]

Reslove Socket stream data.

Parameters:
  • stream – scoket stream
  • address (tuple) – client resquest ip and port (ip, port)
handleLogRecord(record, address)[source]

Config the decoded record

This will add ip and port param by logging.Filter. You can add them into logging format:

[%(levelname)1.1s %(asctime)s %(ip)s %(port)s %(name)s %(module)s:%(lineno)d] %(message)s
Parameters:record (logging.LogRecord) – logging.LogRecord object which

Contains all the information pertinent to the event being logged. :arg tuple address: client resquest ip and port (ip, port)

start()[source]

Start LoggerServer

init_config_options(config=None)[source]

Initialize logger-server config.

All settings will be merged in self.options

Parameters:config (argparse.Namespace) – The command line parse result.
add_logger_file_handler(logger=None, name='')[source]

Add TimedRotatingFileHandler for every single logger

logger_server.server.parse_command()[source]

Parses the command args

logger_server.server.main()[source]

LoggerServer Entry