mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 23:28:20 +00:00
Adding a few options to the ASCII writer.
module LogAscii; export { # Output everything to stdout rather than into files. This is primarily # for testing purposes. const output_to_stdout = F &redef; # The separator between fields. const separator = "\t" &redef; # True to include a header line with column names. const include_header = T &redef; }
This commit is contained in:
parent
26eab74ecc
commit
c6d20dbfdf
9 changed files with 101 additions and 19 deletions
|
@ -3,20 +3,30 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include "LogWriterAscii.h"
|
||||
#include "NetVar.h"
|
||||
|
||||
LogWriterAscii::LogWriterAscii()
|
||||
{
|
||||
file = 0;
|
||||
|
||||
output_to_stdout = BifConst::LogAscii::output_to_stdout;
|
||||
include_header = BifConst::LogAscii::include_header;
|
||||
separator = strdup(BifConst::LogAscii::separator->CheckString());
|
||||
}
|
||||
|
||||
LogWriterAscii::~LogWriterAscii()
|
||||
{
|
||||
if ( file )
|
||||
fclose(file);
|
||||
|
||||
free(separator);
|
||||
}
|
||||
|
||||
bool LogWriterAscii::DoInit(string path, int num_fields, const LogField* const * fields)
|
||||
{
|
||||
if ( output_to_stdout )
|
||||
path = "/dev/stdout";
|
||||
|
||||
fname = IsSpecial(path) ? path : path + ".log";
|
||||
|
||||
if ( ! (file = fopen(fname.c_str(), "w")) )
|
||||
|
@ -25,22 +35,25 @@ bool LogWriterAscii::DoInit(string path, int num_fields, const LogField* const *
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( fputs("# ", file) == EOF )
|
||||
goto write_error;
|
||||
|
||||
for ( int i = 0; i < num_fields; i++ )
|
||||
if ( include_header )
|
||||
{
|
||||
const LogField* field = fields[i];
|
||||
if ( fputs(field->name.c_str(), file) == EOF )
|
||||
if ( fputs("# ", file) == EOF )
|
||||
goto write_error;
|
||||
|
||||
if ( fputc('\t', file) == EOF )
|
||||
for ( int i = 0; i < num_fields; i++ )
|
||||
{
|
||||
const LogField* field = fields[i];
|
||||
if ( fputs(field->name.c_str(), file) == EOF )
|
||||
goto write_error;
|
||||
|
||||
if ( fputs(separator, file) == EOF )
|
||||
goto write_error;
|
||||
}
|
||||
|
||||
if ( fputc('\n', file) == EOF )
|
||||
goto write_error;
|
||||
}
|
||||
|
||||
if ( fputc('\n', file) == EOF )
|
||||
goto write_error;
|
||||
|
||||
return true;
|
||||
|
||||
write_error:
|
||||
|
@ -65,7 +78,7 @@ bool LogWriterAscii::DoWrite(int num_fields, const LogField* const * fields, Log
|
|||
for ( int i = 0; i < num_fields; i++ )
|
||||
{
|
||||
if ( i > 0 )
|
||||
desc.Add("\t");
|
||||
desc.Add(separator);
|
||||
|
||||
LogVal* val = vals[i];
|
||||
const LogField* field = fields[i];
|
||||
|
@ -135,7 +148,7 @@ bool LogWriterAscii::DoWrite(int num_fields, const LogField* const * fields, Log
|
|||
|
||||
bool LogWriterAscii::DoRotate(string rotated_path, string postprocessor, double open, double close, bool terminating)
|
||||
{
|
||||
if ( ! IsSpecial(Path()) )
|
||||
if ( IsSpecial(Path()) )
|
||||
// Don't rotate special files.
|
||||
return true;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue