The qDecoder Project

qLog.c File Reference

Rotating File Logger API. More...


Functions

Q_LOGqLog (const char *filepathfmt, int rotateinterval, bool flush)
 Open ratating-log file.
static bool _write (Q_LOG *log, const char *str)
 Q_LOG->write(): Log messages.
static bool _writef (Q_LOG *log, const char *format,...)
 Q_LOG->writef(): Log messages.
static bool _duplicate (Q_LOG *log, FILE *outfp, bool flush)
 Q_LOG->duplicate(): Duplicate log string into other stream.
static bool _flush (Q_LOG *log)
 Q_LOG->flush(): Flush buffered log.
static bool _free (Q_LOG *log)
 Q_LOG->free(): Close ratating-log file & de-allocate resources.


Detailed Description

Rotating File Logger API.


Function Documentation

Q_LOG* qLog ( const char *  filepathfmt,
int  rotateinterval,
bool  flush 
)

Open ratating-log file.

Parameters:
filepathfmt filename format. formatting argument is same as strftime()
rotateinterval rotating interval seconds, set 0 to disable rotation
flush set to true if you want to flush everytime logging. false for buffered logging
Returns:
a pointer of Q_LOG structure
Note:
rotateinterval is not relative time. If you set it to 3600, log file will be rotated at every hour. And filenameformat is same as strftime(). So If you want to log with hourly rotating, filenameformat must be defined including hour format like "/somepath/xxx-%Y%m%d%H.log". You can set it to "/somepath/xxx-%H.log" for daily overrided log file.
   Q_LOG *log = qLogOpen("/tmp/qdecoder-%Y%m%d.err", 86400, false);
   qLogClose(log);

Note:
Use "--enable-threadsafe" configure script option to use under multi-threaded environments.

static bool _write ( Q_LOG log,
const char *  str 
) [static]

Q_LOG->write(): Log messages.

Parameters:
log a pointer of Q_LOG
str message string
Returns:
true if successful, otherewise returns false

static bool _writef ( Q_LOG log,
const char *  format,
  ... 
) [static]

Q_LOG->writef(): Log messages.

Parameters:
log a pointer of Q_LOG
format messages format
Returns:
true if successful, otherewise returns false

static bool _duplicate ( Q_LOG log,
FILE *  outfp,
bool  flush 
) [static]

Q_LOG->duplicate(): Duplicate log string into other stream.

Parameters:
log a pointer of Q_LOG
fp logging messages will be printed out into this stream. set NULL to disable.
flush set to true if you want to flush everytime duplicating.
Returns:
true if successful, otherewise returns false
   log->duplicate(log, stdout, true);   // enable console out with flushing
   log->duplicate(log, stderr, false);  // enable console out
   log->duplicate(log, NULL, false);    // disable console out (default)

static bool _flush ( Q_LOG log  )  [static]

Q_LOG->flush(): Flush buffered log.

Parameters:
log a pointer of Q_LOG
Returns:
true if successful, otherewise returns false

static bool _free ( Q_LOG log  )  [static]

Q_LOG->free(): Close ratating-log file & de-allocate resources.

Parameters:
log a pointer of Q_LOG
Returns:
true if successful, otherewise returns false


Copyright (c) 2008 The qDecoder Project