diff --git a/src/LogWriter.h b/src/LogWriter.h index 02a8c03ad5..2b8d321cd2 100644 --- a/src/LogWriter.h +++ b/src/LogWriter.h @@ -50,6 +50,37 @@ protected: // should be reported via Error(). virtual bool DoWrite(int num_fields, LogField** fields, LogVal** vals) = 0; + // Called when the flushing status for this writer is changed. If + // flushing is enabled, the writer should attempt to write out + // information as quickly as possible even if that may have an + // performance impact. If disabled (which the writer should assume to be + // the default), then it can buffer things up as necessary and write out + // in a way optimized for performance. + // + // A writer may ignore flushing if it doesn't fit with its semantics. + virtual void DoSetFlushing(bool enabled) = 0; + + // Called when a log output is to be rotated. Most directly, this only + // applies to writers outputting files, thoug a writer may also trigger + // other regular actions if that fits a similar model + // + // The string "rotate_path" is interpreted in writer-specific way, yet + // should generally should have similar semantics that the "path" passed + // into DoInit(), except that now it reflects the name to where the + // rotated output is to be moved. After rotation, output should continue + // normally with the standard "path". As an example, for file-based + // output, the rotate_path may be the original filename with an embedded + // timestamp. + // + // The writer must return false if an error occured that prevent the + // writer for continuing operation; it will then be disabled. The error + // reason should be reported via Error(). If a recoverable error occurs, + // still call Error(), but return true. + // + // A writer may ignore rotation requests if it doesn't fit with its + // semantics. In that case, still return true. + virtual bool DoRotate(string rotated_path) = 0; + // Called once on termination. Not called when any of the other methods // has previously signaled an error, i.e., executing this method signals // a regular shutdown. diff --git a/src/LogWriterAscii.cc b/src/LogWriterAscii.cc index e06ba4f9dd..69b9993778 100644 --- a/src/LogWriterAscii.cc +++ b/src/LogWriterAscii.cc @@ -127,3 +127,14 @@ bool LogWriterAscii::DoWrite(int num_fields, LogField** fields, LogVal** vals) return true; } + +bool LogWriterAscii::DoRotate(string rotated_path) + { + return true; + } + +void LogWriterAscii::DoSetFlushing(bool enabled) + { + } + + diff --git a/src/LogWriterAscii.h b/src/LogWriterAscii.h index 4672d2ac54..fa014fbc81 100644 --- a/src/LogWriterAscii.h +++ b/src/LogWriterAscii.h @@ -15,9 +15,11 @@ public: static LogWriter* Instantiate() { return new LogWriterAscii; } protected: - bool DoInit(string path, int num_fields, LogField** fields); - bool DoWrite(int num_fields, LogField** fields, LogVal** vals); - void DoFinish(); + virtual bool DoInit(string path, int num_fields, LogField** fields); + virtual bool DoWrite(int num_fields, LogField** fields, LogVal** vals); + virtual void DoSetFlushing(bool enabled); + virtual bool DoRotate(string rotated_path); + virtual void DoFinish(); private: FILE* file;