AURobotServers  4
Public Member Functions | Protected Attributes | List of all members
ULogFile Class Reference

#include <ulogfile.h>

Inheritance diagram for ULogFile:
Inheritance graph

Public Member Functions

void closeLog ()
 
void doFlush ()
 
FILE * getF ()
 
const char * getLogFileName ()
 
const char * getLogName ()
 
bool isLogOpen ()
 
bool isOpen ()
 
void logLock ()
 
bool logRename (const char *name)
 
void logUnlock ()
 
bool openLog ()
 
bool openLog (bool doOpen)
 
bool openLog (const char *resName)
 
void setLogFlush (bool doFlush)
 
void setLogName (const char *resName, const char *ext="log")
 
void setLogNameNumber (int number)
 add a number to the logfile name, That is if the logName is 'svs' and number is 2 (and logPath is '/rhome/demo'), then logfilename is set to '/rhome/demo/svs_2.log'. The purpose is to have an alternative, if the file renaming fails (if the file system is locked or something). More...
 
void setLogTime (UTime timestamp)
 
void toLog (const char *logString)
 
void toLog (const char *s1, const char *s2)
 
void toLog (const int num, const char *s1, const char *s2)
 
void toLog (const char *s1, const int num, const char *s2)
 
void toLog (const char *s1, const int n1, const int n2, const char *s2)
 
void toLog (const char *s1, const int num, const char *s2, const char *s3)
 
void toLog (const char *s1, const int n1, const int n2, const char *s2, const char *s3)
 
 ULogFile ()
 
void useLogTime (bool value)
 
 ~ULogFile ()
 

Protected Attributes

int failCnt
 
FILE * logFile
 
ULock logFileLock
 
char logFileName [MAX_FILENAME_SIZE]
 
bool logFlush
 
char logName [MAX_FILENAME_SIZE]
 
UTime logTime
 
bool logTimeUse
 

Detailed Description

A few functions to open and close a logfile and to store the name and status of the file

    @author Christian Andersen <chrand@mail.dk>

Constructor & Destructor Documentation

ULogFile::ULogFile ( )

Constructor

References failCnt, logFile, logFileName, logFlush, logName, and logTimeUse.

ULogFile::~ULogFile ( )

DEstructor

References closeLog().

Member Function Documentation

void ULogFile::closeLog ( )
void ULogFile::doFlush ( )

Flush unsaved data to disk - if file is open

References ULock::lock(), logFile, logFileLock, and ULock::unlock().

Referenced by setLogFlush(), UResPoseHist::toKml(), and useLogTime().

FILE * ULogFile::getF ( )
const char* ULogFile::getLogFileName ( )
inline
const char* ULogFile::getLogName ( )
inline

Get log name, that is the name of the logfile without the path and the '.log' extension.

References logName.

Referenced by UCamPool::getImagelogFilename(), UResPoseHist::getReplayFileName(), UMisRuleState::getStateStr(), UFuncRule::openLog(), testLog(), and UResPoseHist::toKml().

bool ULogFile::isLogOpen ( )
inline
bool ULogFile::isOpen ( )
inline

Is logfile open - the file itself

References logFile, and toLog().

Referenced by UResPoseHist::addPoseHist(), UCamPool::closeImageLogging(), UImageLog::closeLogging(), UHokuyo::decodeData(), UResLocater::doLocatorUpdates(), UResSmrIf::eventGpsUpdate(), UCmdExe::executeFunction(), UResAvoid::findPathToHere(), UResSmrCtl::getSMRCLDrive2cmd(), UFuncImu::handleCommand(), Funcavoid::handleCommand(), UFuncKinect::handleKinect(), UFunctionLaserIfData::handleLaserObst(), UFuncLoca2::handleLocalize(), UFuncPiCam::handleNormal(), UResLaserIfObst::handleObst(), UCmdExe::handleOneMessageFromQueue(), UCmdExe::handleOneServerPushMessage(), UFuncPTgrey::handlePTgrey(), UCmdExe::handleServerCommand(), UFunctionSmrIf::handleSmr(), UFuncStereo::handleStereo(), UImgPush::imgUpdated(), UCamPool::isImagelogOpen(), UResAvoid::isLogAvoidOpen(), ULaserDevice::isLogFileOpen(), UResPoseHist::isLogfileOpen(), UResVarPool::isLogFileOpen(), isLogOpen(), UServerClient::isLogOpen(), UCmdExe::killServer(), UResLocater::locate(), ULaserDevice::logFileOpen(), UResVarPool::logFileOpen(), UFuncPiCam::logFileTest(), UFuncKinect::logFileTest(), UServerClient::logOpen(), ULaserSim::logSourceData(), UServerClient::logWrite(), UResAvoid::methodCall(), UResAvoid::methodCallV(), UCamPool::openImageLogging(), UImageLog::openLog(), UResAvoid::openLogAvoid(), UHokuyo::receiveFromDevice(), UResLocater::rowEndDetect(), UFuncKinect::run(), UFuncRadar::runRead(), UGroundPatches::saveMatlabScript(), UVariable::saveToLog(), UResSmrCtl::sendNewManoeuvreToSMR(), UHokuyo::sendToDevice(), UVarPool::setLogfile(), UImagePool::setLogImg(), UResPoseHist::toKml(), ULms100::toLog(), ULms500::toLog(), ULms100::~ULms100(), and ULms500::~ULms500().

void ULogFile::logLock ( )
inline

When using the file-handle it this file lock-unlock should be used too, to avoid conflicts

References ULock::lock(), and logFileLock.

Referenced by ULaserDevice::logThisScan().

bool ULogFile::logRename ( const char *  name)

REname this file (or file mask) to include date and time, and add an extra 'g' to the filename

Parameters
nameis the filename, either in current directory, or with full path, or as a mask The functopn uses stat to get the file modified time (mtime), and constructs a string like yyyymmdd_hhmmss (year-month-day_hour-minute-second), and inserts this before the final '.filetype' and appends a 'g' at the end of the file. This should allow a '*.log' specification to rename all logfiles, and not catch the already renamed files.
Returns
true if successful and false, if no sourcefile or rename failed.

References min.

Referenced by openLog(), and useLogTime().

void ULogFile::logUnlock ( )
inline

When using the file-handle it this file lock-unlock should be used too, to avoid conflicts

Referenced by ULaserDevice::logThisScan().

bool ULogFile::openLog ( )
bool ULogFile::openLog ( bool  doOpen)

Open or close log in one call

Parameters
doOpenopens log if true, else close.
Returns
true of open was an succes.

References closeLog(), logName, openLog(), and setLogName().

bool ULogFile::openLog ( const char *  resName)

Open logfile with default name 'resName'.log in the dataPath

References openLog(), and setLogName().

void ULogFile::setLogFlush ( bool  doFlush)
inline

Should any 'toLog' be flushed to disk after writing to file? default is true.

Parameters
doFlushif true the toLog will do a fflush with each toLog command.

References doFlush(), getF(), and logFlush.

void ULogFile::setLogName ( const char *  resName,
const char *  ext = "log" 
)
void ULogFile::setLogNameNumber ( int  number)

add a number to the logfile name, That is if the logName is 'svs' and number is 2 (and logPath is '/rhome/demo'), then logfilename is set to '/rhome/demo/svs_2.log'. The purpose is to have an alternative, if the file renaming fails (if the file system is locked or something).

Parameters
numberis the integer number to add.

References dataPath, logFileName, logName, and MAX_FILENAME_SIZE.

Referenced by openLog(), and UResLocater::rowEndDetect().

void ULogFile::setLogTime ( UTime  timestamp)
inline

Set logtime for subsequent toLog calls

Parameters
timestampto use

References logTime, and logTimeUse.

void ULogFile::toLog ( const char *  logString)
void ULogFile::toLog ( const char *  s1,
const char *  s2 
)

Save this string to the logfile. The strings are preceded with a timestamp and terminated with a 'newline'. like: 1215323632.901925 string1 string2

Parameters
s1is the first string
s2is the second string

References UTime::getMicrosec(), UTime::getSec(), ULock::lock(), logFile, logFileLock, logFlush, logTime, logTimeUse, UTime::Now(), and ULock::unlock().

void ULogFile::toLog ( const int  num,
const char *  s1,
const char *  s2 
)

Save this string to the logfile. The strings are preceded with a timestamp and terminated with a 'newline'. like (if num==27): 1215323632.901925 27 string1 string2

Parameters
numis the first number after timestamp
s1is the first string
s2is the second string

References UTime::getMicrosec(), UTime::getSec(), ULock::lock(), logFile, logFileLock, logFlush, logTime, logTimeUse, UTime::Now(), and ULock::unlock().

void ULogFile::toLog ( const char *  s1,
const int  num,
const char *  s2 
)

Save this string to the logfile. The strings are preceded with a timestamp and terminated with a 'newline'. like (if num==27): 1215323632.901925 string1 27 string2

Parameters
s1is the first string
numis number after first string
s2is the second string

References UTime::getMicrosec(), UTime::getSec(), ULock::lock(), logFile, logFileLock, logFlush, logTime, logTimeUse, UTime::Now(), and ULock::unlock().

void ULogFile::toLog ( const char *  s1,
const int  n1,
const int  n2,
const char *  s2 
)

Save this string to the logfile. The strings are preceded with a timestamp and terminated with a 'newline'. like (if n1==2 and n2==28): 1215323632.901925 string1 2 28 string2

Parameters
s1is the first string
n1is the first integer
n2is the second integer
s2is the second string

References UTime::getMicrosec(), UTime::getSec(), ULock::lock(), logFile, logFileLock, logFlush, logTime, logTimeUse, UTime::Now(), and ULock::unlock().

void ULogFile::toLog ( const char *  s1,
const int  num,
const char *  s2,
const char *  s3 
)

Save this string to the logfile. The strings are preceded with a timestamp and terminated with a 'newline'. like (if num==27): 1215323632.901925 string1 27 string2 string3

Parameters
s1is the first string
numis an integer
s2is the second string
s3is the third string

References UTime::getMicrosec(), UTime::getSec(), ULock::lock(), logFile, logFileLock, logFlush, logTime, logTimeUse, UTime::Now(), and ULock::unlock().

void ULogFile::toLog ( const char *  s1,
const int  n1,
const int  n2,
const char *  s2,
const char *  s3 
)

Save this string to the logfile. The strings are preceded with a timestamp and terminated with a 'newline'. like (if n1==2 and n2==28): 1215323632.901925 string1 2 28 string2 string3

Parameters
s1is the first string
n1is the first integer
n2is the second integer
s2is the second string
s3is the third string

References UTime::getMicrosec(), UTime::getSec(), ULock::lock(), logFile, logFileLock, logFlush, logTime, logTimeUse, UTime::Now(), and ULock::unlock().

void ULogFile::useLogTime ( bool  value)
inline

Set flag for use of specified logTime rather than current time

Parameters
valuewhen true latest specified logTime is used, else current time is used

References doFlush(), logRename(), and logTimeUse.

Member Data Documentation

int ULogFile::failCnt
protected

count of open failures since lase success

Referenced by openLog(), and ULogFile().

FILE* ULogFile::logFile
protected

Logfile for variable updates

Referenced by closeLog(), doFlush(), getF(), isOpen(), openLog(), toLog(), and ULogFile().

ULock ULogFile::logFileLock
protected

Resource lock for variable logfile

Referenced by closeLog(), doFlush(), logLock(), openLog(), setLogName(), and toLog().

char ULogFile::logFileName[MAX_FILENAME_SIZE]
protected

is file attempted open, and should be opened when write is attempted. Filename for logfile including path

Referenced by closeLog(), getLogFileName(), openLog(), setLogName(), setLogNameNumber(), and ULogFile().

bool ULogFile::logFlush
protected

Should any 'toLog' be flushed to disk after writing to file?

Parameters
doFlushif true the toLog will do a fflush.

Referenced by UVarHist::logDataDouble(), setLogFlush(), toLog(), and ULogFile().

char ULogFile::logName[MAX_FILENAME_SIZE]
protected

Log name, i.e. the resource name for the owner of the logfile, e.g. "abc" for a log file name of "abc.log"

Referenced by getLogName(), openLog(), setLogName(), setLogNameNumber(), and ULogFile().

UTime ULogFile::logTime
protected

A specific logtime

Referenced by setLogTime(), and toLog().

bool ULogFile::logTimeUse
protected

Use a specific logtime set by setTime, else use current time from a gettimeofday() call

Referenced by setLogTime(), toLog(), ULogFile(), and useLogTime().


The documentation for this class was generated from the following files: