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 inprefix_fmt
.
Changed in version 3.2: Added
fmt
anddatefmt
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.
- record (logging.LogRecord) –
-
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
andport
param bylogging.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 whichContains all the information pertinent to the event being logged. :arg tuple address: client resquest ip and port
(ip, port)
-