AURobotServers
4
|
#include <ulogfile.h>
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 |
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>
ULogFile::ULogFile | ( | ) |
Constructor
References failCnt, logFile, logFileName, logFlush, logName, and logTimeUse.
ULogFile::~ULogFile | ( | ) |
DEstructor
References closeLog().
void ULogFile::closeLog | ( | ) |
Close logfile for variable modifications
References ULock::lock(), logFile, logFileLock, logFileName, and ULock::unlock().
Referenced by UResLocater::closelog(), UResAvoid::closeLogAvoid(), UResPoseHist::closeLogfile(), UImageLog::closeLogging(), UCmdExe::closeLogServer(), UCmdExe::handleServerCommand(), UFunctionSmrIf::handleSmr(), UResLocater::locate(), UServerClient::logClose(), ULaserDevice::logFileClose(), UResVarPool::logFileClose(), UServerClient::logOpen(), ULaserSim::logSourceData(), openLog(), UFuncRule::openLog(), UResAvoid::openLogAvoid(), UHokuyo::receiveFromDevice(), UResLocater::rowEndDetect(), UFuncRadar::runRead(), UGroundPatches::saveMatlabScript(), ULaserDevice::stop(), testLog(), ULaserDevice::threadRunLoop(), UResPoseHist::toKml(), UCmdExe::~UCmdExe(), UFuncKinect::~UFuncKinect(), UFuncLoca2::~UFuncLoca2(), UFuncPiCam::~UFuncPiCam(), UHokuyo::~UHokuyo(), UImageLog::~UImageLog(), ULms100::~ULms100(), ULms500::~ULms500(), ~ULogFile(), UResLaserIfObst::~UResLaserIfObst(), and UResSmrCtl::~UResSmrCtl().
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 | ( | ) |
Get file handle itself for own printing
References logFile.
Referenced by UResPoseHist::addPoseHist(), UResLocater::doLocatorUpdates(), UResSmrIf::eventGpsUpdate(), UCmdExe::executeFunction(), UResSmrCtl::getSMRCLDrive2cmd(), UFuncLoca2::handleLocalize(), UResBin::handleNewData(), UResLaserIfObst::handleObstGrp(), UCmdExe::handleOneMessageFromQueue(), UCmdExe::handleOneServerPushMessage(), UCmdExe::handleServerCommand(), UCmdExe::killServer(), UResLocater::locate(), UVarHist::logDataDouble(), UImageLog::logImage(), ULaserSim::logSourceData(), ULaserDevice::logThisScan(), UServerClient::logWrite(), UResLocater::rowEndDetect(), UFuncKinect::run(), UFuncRadar::runRead(), UGroundPatches::saveMatlabScript(), UVariable::saveToLog(), UResSmrCtl::sendNewManoeuvreToSMR(), UAvoidCell::setCuts(), setLogFlush(), UResPoseHist::toKml(), UHokuyo::toLog(), and UFuncLoca2::UFuncLoca2().
|
inline |
Get logfile name - full logname including path.
References logFileName.
Referenced by UImageLog::closeLogging(), UServerClient::getLogFilename(), UResPoseHist::getLogfileName(), UResVarPool::getLogFileName(), UFuncImu::handleCommand(), Funcavoid::handleCommand(), UFunctionGps::handleCommand(), UFuncKinect::handleKinect(), UFunctionLaserIfData::handleLaserObst(), UFuncPiCam::handleNormal(), UFuncPTgrey::handlePTgrey(), UCmdExe::handleServerCommand(), UFuncStereo::handleStereo(), UFuncPiCam::logFileTest(), UFuncKinect::logFileTest(), UImageLog::openLogging(), testLog(), UResPoseHist::toKml(), and UResAvoid::UResAvoidInit().
|
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().
|
inline |
Is logfile open - the file itself
References isOpen().
Referenced by UVarHist::changed(), UFuncCron::handleCommand(), UFuncMapObst::handleCommand(), UFuncKeep::handleKeep(), UResLaserIfObst::handleObstGrp(), UFuncRule::handleRuleSet(), UFunctionVarPool::handleVar(), UMisRuleState::isLogOpen(), UResLocater::locate(), UVarHist::logDataDouble(), ULaserDevice::logFileClose(), ULaserDevice::logFileOpen(), UImageLog::logImage(), ULaserDevice::logThisScan(), UFuncTOF::processChannel8(), UHokuyo::receiveFromDevice(), UFuncPTgrey::Receiver(), UFuncPiCam::run(), UFuncKinect::run(), UFunctionVarPool::sendVar(), UFunctionVarPool::sendVarList(), ULaserDevice::threadRunLoop(), and UHokuyo::toLog().
|
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().
|
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
name | is 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. |
References min.
Referenced by openLog(), and useLogTime().
|
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 | ( | ) |
Open logfile with default name, i.e. resource name
References closeLog(), failCnt, ULock::lock(), logFile, logFileLock, logFileName, logRename(), setLogNameNumber(), and ULock::unlock().
Referenced by UResSmrIf::eventGpsUpdate(), UVarLog::getUpdTime(), UFuncImu::handleCommand(), UFuncFile::handleCommand(), UFuncLobst::handleCommand(), UFuncMapObst::handleCommand(), UFuncBin::handleCommand(), UFuncPoly::handleCommand(), UFuncPcp::handleCommand(), UFuncKeep::handleKeep(), UFuncKinect::handleKinect(), UFuncPiCam::handleNormal(), UResLaserIfObst::handleObst(), UCmdExe::handleServerCommand(), UFunctionSmrIf::handleSmr(), UFuncStereo::handleStereo(), UResLocater::locate(), ULaserDevice::logFileOpen(), UResVarPool::logFileOpen(), UFuncKinect::logFileTest(), UServerClient::logOpen(), ULaserSim::logSourceData(), UImageLog::openLog(), openLog(), UFuncRule::openLog(), UResLocater::openlog(), UResAvoid::openLogAvoid(), UResPoseHist::openLogfile(), UImageLog::openLogging(), UHokuyo::receiveFromDevice(), UResLocater::rowEndDetect(), UFuncRadar::runRead(), UGroundPatches::saveMatlabScript(), testLog(), ULaserDevice::threadRunLoop(), UResPoseHist::toKml(), UFuncLoca2::UFuncLoca2(), ULms100::ULms100(), ULms500::ULms500(), UResBin::UResBinInit(), and UResMapObst::UResMapObstInit().
bool ULogFile::openLog | ( | bool | doOpen | ) |
Open or close log in one call
doOpen | opens log if true, else close. |
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().
|
inline |
void ULogFile::setLogName | ( | const char * | resName, |
const char * | ext = "log" |
||
) |
Set logfile pre-name, and optionally the extension as other than .log. for a plug-in the logname should typically be the plug-in name.
resName | a pointer to a valid character string. |
ext | an optional alternative extension - default is log |
References dataPath, ULock::lock(), logFileLock, logFileName, logName, MAX_FILENAME_SIZE, and ULock::unlock().
Referenced by ULaserDevice::createBaseVars(), UFuncPiCam::createResources(), UFuncKinect::createResources(), UFuncPTgrey::createResources(), UResSmrIf::eventGpsUpdate(), Funcavoid::Funcavoid(), UCmdExe::handleServerCommand(), UServerClient::justConnected(), UVarHist::makeLogName(), openLog(), UResLocater::rowEndDetect(), UFuncRadar::runRead(), UGroundPatches::saveMatlabScript(), UResPoseHist::setResID(), testLog(), testsmrcl(), UResPoseHist::toKml(), UCamPool::UCamPoolInit(), UFuncImu::UFuncImu(), UFuncLoca2::UFuncLoca2(), UFuncStereo::UFuncStereo(), UHokuyo::UHokuyo(), UImagePool::UImagePoolInit(), ULaserSim::ULaserSim(), UResAvoid::UResAvoidInit(), UResBin::UResBinInit(), UResLaserIfObst::UResLaserIfObst(), UResLobst::UResLobstInit(), UResLocater::UResLocater(), UResMapObst::UResMapObstInit(), UResSmrCtl::UResSmrCtlInit(), and UResVarPool::UResVarPool().
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).
number | is the integer number to add. |
References dataPath, logFileName, logName, and MAX_FILENAME_SIZE.
Referenced by openLog(), and UResLocater::rowEndDetect().
|
inline |
Set logtime for subsequent toLog calls
timestamp | to use |
References logTime, and logTimeUse.
void ULogFile::toLog | ( | const char * | logString | ) |
Save this string to the logfile. The string is preceded with a timestamp and terminated with a 'newline'.
logString | is the data that need to be logged (with a timestamp) |
References UTime::getMicrosec(), UTime::getSec(), ULock::lock(), logFile, logFileLock, logFlush, logTime, logTimeUse, UTime::Now(), and ULock::unlock().
Referenced by UFuncKinect::callGotNewDataWithObject(), UVarHist::changed(), ULms100::decodeData(), ULms500::decodeData(), UHokuyo::decodeData(), UResAvoid::findPathToHere(), UHokuyo::getDataTo(), UResBin::handleNewData(), UResLaserIfObst::handleObstGrp(), isOpen(), UMisRuleState::logActualCall(), UMisRuleState::logActualCallV(), UFuncPiCam::logFileTest(), UFuncKinect::logFileTest(), UImageLog::logImage(), UResAvoid::methodCall(), UResAvoid::methodCallV(), UCmdExe::postCommand(), ULms100::receiveData(), ULms500::receiveData(), UHokuyo::receiveData(), UFuncKinect::run(), UMisRuleState::runControl(), UCronJob::runJob(), UMisRuleState::runLine(), UMisRuleState::runLines(), UMisRuleState::runRuleCommands(), UResSmrCtl::sendNewManoeuvreToSMR(), UMisRuleState::skipOneStatement(), UMisRuleState::step(), testLog(), UKeepItem::tick(), UImageLog::toLog(), ULms100::toLog(), ULms500::toLog(), and UMisRuleState::toLog().
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
s1 | is the first string |
s2 | is 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
num | is the first number after timestamp |
s1 | is the first string |
s2 | is 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
s1 | is the first string |
num | is number after first string |
s2 | is 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
s1 | is the first string |
n1 | is the first integer |
n2 | is the second integer |
s2 | is 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
s1 | is the first string |
num | is an integer |
s2 | is the second string |
s3 | is 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
s1 | is the first string |
n1 | is the first integer |
n2 | is the second integer |
s2 | is the second string |
s3 | is the third string |
References UTime::getMicrosec(), UTime::getSec(), ULock::lock(), logFile, logFileLock, logFlush, logTime, logTimeUse, UTime::Now(), and ULock::unlock().
|
inline |
Set flag for use of specified logTime rather than current time
value | when true latest specified logTime is used, else current time is used |
References doFlush(), logRename(), and logTimeUse.
|
protected |
count of open failures since lase success
Referenced by openLog(), and ULogFile().
|
protected |
Logfile for variable updates
Referenced by closeLog(), doFlush(), getF(), isOpen(), openLog(), toLog(), and ULogFile().
|
protected |
Resource lock for variable logfile
Referenced by closeLog(), doFlush(), logLock(), openLog(), setLogName(), and toLog().
|
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().
|
protected |
Should any 'toLog' be flushed to disk after writing to file?
doFlush | if true the toLog will do a fflush. |
Referenced by UVarHist::logDataDouble(), setLogFlush(), toLog(), and ULogFile().
|
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().
|
protected |
A specific logtime
Referenced by setLogTime(), and toLog().
|
protected |
Use a specific logtime set by setTime, else use current time from a gettimeofday() call
Referenced by setLogTime(), toLog(), ULogFile(), and useLogTime().