Trees | Indices | Help |
---|
|
Concrete class LogWriter provides an interface for logging data.
Logs may be written to a stream or a file. The default file format is a gzipped YAML file. If output is sent to a stream, the output is an uncompressed YAML.
Each .write() operation maps into a single YAML document, allowing the yaml module's safe_load_all method to parse them one at a time.
Typical usage: >>> L = LogWriter('mylog.yml.gz') >>> L.write( foo = 'fu', bar = 'bar' ) >>> L.close() >>> for data in iterlog('mylog.yml.gz'): >>> print data
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from |
|
|||
Inherited from |
|
INPUTS: stream -- stream -- output stream to use, must support write, flush, close -- str -- filename to use (.gz added automatically if not present) -- None -- logger started in uninitialized state; use open() sync -- boolean -- set to force a flush after every log entry. ATTRIBUTES: .s -- the open stream .sync -- auto-flush flag .timeUnit -- time unit for log timestamps; default is millisecond
|
Open a logging stream. INPUT: stream -- str -- a file name for the log. A .gz will be appended if not present. Log will be stored as a gzip YAML file. -- file-like -- an object with .write() .flush() and .close() methods. Log will be sent as YAML text, with a single .write() for each entry of the log. |
Write a log entry. Each entry consists of a topic string and an automatically generated timestamp, and may include a dictionary of additional attributes supplied as keyword arguments. The log entry will be emitted as a YAML document (entry starting with ---) that contains a mapping with keys TIME for the timestamp (in units of .timeUnit) and TOPIC for the topic. If .sync is set, the stream will be flushed after each entry. |
Wrap the specified callable and log results of calls. INPUTS: fun -- callable -- "getter" function with no params fmt -- callable -- formatting function for the parameter. Must return something yaml can safe_dump() attr -- dict -- dictionary of extra attributes for log entry OUTPUTS: callable function that calls fun() and logs the results Typical usage is to take an existing getter function and replace it in in place with the wrapped getter: >>> def dummyGetter(): >>> return int(raw_input()) >>> L = joy.loggit.LogWriter("foo") >>> g = L.getterWrapperFor(dummyGetter ,fmt=lambda x : "0x%X" % x , attr=dict(sparrow = 'african')) >>> g() 258 258 >>> L.close() >>> !gunzip -c foo.gz --- {TIME: ????, TOPIC: getter, func_name: dummyGetter, sparrow: african, value: '0x102'} |
Wrap the specified callable and log parameters of calls. INPUTS: fun -- callable function with one parameter name -- function name to use in ifmt -- formatting function for arguments ofmt -- formatting function for results / None to omit result OUTPUTS: callable function that logs the parameter and then calls fun() with it and logs the results Usage -- see example for getterWrapperFor |
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Jan 4 16:46:17 2018 | http://epydoc.sourceforge.net |