datalogd.plugins.file_datasink module¶
-
class
datalogd.plugins.file_datasink.
FileDataSink
(filename, filename_timestamp=False, mode='w', header='', terminator='n', flush_interval=10)[source]¶ Bases:
datalogd.DataSink
Write data to a file.
By default, any existing contents of
filename
will be overwritten without prompting. To instead raise an error if the file exists, set themode
parameter to ‘x’. The contents of any existing file will be appended to by settingmode='a'
.To automatically prepend a date and time stamp to the given filename, set
filename_timestamp=True
. In general, this should create a unique filename and prevent overwriting whenfilename
already exists.The
flush_interval
parameter controls the behaviour of the file writes. It describes how often, in seconds, the operating system’s buffers should be flushed to disk, updating the file contents:flush_interval > 0
causes the flush to occur at the given time interval, in seconds. More frequent flushes will keep the contents of the file updated, but put more strain on the machines I/O systems.flush_interval = 0
will flush immediately after each receipt of data.flush_interval < 0
will not automatically flush, leaving this to the operating system. The contents of the file may not update until the program closes.flush_interval == None
will perform a file open, write, and close operation on each receipt of data. This may be desired if the contents of the file should only contain the latest received data (and should be used in conjunction with themode='w'
parameter).
Parameters: - filename – File name to write data to.
- filename_timestamp – Prepend a timestamp to the filename.
- mode – Mode in which to open the file. One of ‘w’ (write), ‘a’ (append), ‘x’ (exclusive creation).
- header – Header to write to file after plugin initialisation.
- terminator – Separator written to file after each receipt of data.
- flush_interval – Interval, in seconds, between flushes to disk.