Go to the documentation of this file.
79 #ifndef XSENS_NO_AUTOLIB
80 #pragma comment(lib, "psapi.lib")
88 #if JOURNALLER_WITH_THREAD_SUPPORT && !defined(__APPLE__)
110 #pragma GCC diagnostic push
111 #pragma GCC diagnostic ignored "-Wnonnull-compare"
123 , m_level(initialLogLevel)
124 , m_debugLevel(initialLogLevel)
127 , m_useDateTime(false)
129 init(pathfile, purge);
153 const size_t b = fn.find_last_of(
"/") + 1;
154 const size_t l = fn.find_first_of(
".");
155 return fn.substr(b, l - b);
193 JLWRITE(
this,
"Journaller logging to " <<
m_file->filename() << (appName.empty() ?
XsString() :
XsString(
" for ") + appName) <<
" on " << XsTimeStamp::now().toString());
204 __android_log_write(level,
tag().c_str(),
msg.c_str());
211 #if JOURNALLER_WITH_THREAD_SUPPORT
231 sprintf(timebuf,
"%10" PRINTF_INT64_MODIFIER
"d.%03d ", ts.secondTime(), (
int) ts.milliSecondPart());
237 writeMessage(ts.utcToLocalTime().toString().toStdString());
246 sprintf(buf,
"<%08X> ", (
unsigned int)
threadId());
248 sprintf(buf,
"<%04X> ", (
unsigned int)
threadId());
256 std::string tmp =
tag();
285 char eol = *
msg.rbegin();
286 if (eol ==
'\n' || eol ==
'\r')
332 JLGENERIC(
this, level,
"************ Dump Begin ************");
335 JLGENERIC(
this, level,
"************* Dump End *************");
365 return m_file->filename();
390 return os << JlHexLogger<int>((
int) hex.
m_value);
400 if (
m_file &&
m_file->filename().replacedAll(
"\\",
"/") == pathfile.replacedAll(
"\\",
"/"))
405 if (!newFile->
xsFile().isOpen())
407 JLERROR(
this,
"Could not switch to new log location " << pathfile);
413 std::unique_ptr<uint8_t[]> buffer;
417 oldFileName =
m_file->filename();
418 JLWRITE(
this,
"Switching to file " << pathfile);
425 buffer.reset(
new uint8_t[(
int)sz]);
426 sz = file.read(buffer.get(), 1, sz);
432 m_file->xsFile().write(buffer.get(), 1, sz);
436 if (!oldFileName.empty())
439 _unlink(oldFileName.c_str());
440 JLDEBUG(
this,
"Switched from " << oldFileName <<
" to " << pathfile);
443 JLDEBUG(
this,
"Switched to " << pathfile);
457 auto newFile = target->
m_file;
459 std::unique_ptr<uint8_t[]> buffer;
463 oldFileName =
m_file->filename();
464 JLDEBUG(target,
"************ Moving logs from " << oldFileName <<
" to " << target->
filename());
471 buffer.reset(
new uint8_t[(
int)sz]);
472 sz = file.read(buffer.get(), 1, sz);
476 if (buffer && sz && newFile)
477 newFile->xsFile().write(buffer.get(), 1, sz);
480 if (!oldFileName.empty())
483 _unlink(oldFileName.c_str());
484 JLDEBUG(target,
"************ Moved logs from " << oldFileName);
493 #if JOURNALLER_WITH_THREAD_SUPPORT
515 #pragma GCC diagnostic pop
@ JLL_Write
only log 'write' messages
void writeFileHeader(const std::string &appName)
Write a header for the log file including some meta-data about the journaller.
static void setAdditionalLogger(AbstractAdditionalLogger *additionalLogger)
Sets the additional logger.
JournalLogLevel m_debugLevel
BOOL ShowCallstack(HANDLE hThread=GetCurrentThread(), const CONTEXT *context=NULL, PReadProcessMemoryRoutine readMemoryFunction=NULL, LPVOID pUserData=NULL)
void cleanupThread()
Removes stored information on the current thread after flushing all data.
void moveLogFile(const XsString &pathfile, bool purge=true, bool eraseOld=true)
Move the log file to the supplied path, keeping current contents intact.
void writeTime()
Write the current time to the file.
void moveLogs(Journaller *target, bool eraseOld=true)
Copy the contents of the current log file to target.
void setUseDateTime(bool yes)
When setting the Date Time to yes, the timestamps are translated from unix timestamp into a redable d...
~Journaller()
Destructor, detaches from the logfile and closes it if this was the last reference.
void writeMessage(const std::string &msg)
Write msg to the file without decoration or added newline.
@ JLL_Alert
only log fatal, error and alert messages
A class containing a journal file and some meta-data.
A journalling class for debugging applications.
static const char * gLogLevelString[]
A list of strings representing the different log levels, use JournalLogLevel to index.
JournalLogLevel m_flushLevel
std::shared_ptr< JournalFile > m_file
#define JLGENERIC(journal, level, msg)
A support class of journaller that is used for the logging of hex values.
std::shared_ptr< JournalThreader > m_threader
static AbstractAdditionalLogger * m_additionalLogger
The optional additional logger.
void flushLine()
Flush any data currently queued for logging to the file buffer.
void jlTerminate(Journaller **gj)
Cleans up any remaining stuff.
#define JLWRITE(journal, msg)
void writeThread()
Write the current time to the file.
Encapsulates a file, providing a platform independent interface.
#define JLERROR(journal, msg)
void setTag(const std::string &tag)
Set a tag to be added before the log level tag in each log file.
Journaller(const XsString &pathfile, bool purge=true, JournalLogLevel initialLogLevel=JLL_Alert)
Constructor.
void setDebugLevel(JournalLogLevel level, bool writeLogLine=true)
Set the log level for logging to debug output.
void log(JournalLogLevel level, const std::string &msg)
Write a log message to the file if level is at least equal to the current log level.
static std::string tagFromFilename(const std::string &fn)
void writeCallstack(JournalLogLevel level)
Write the current callstack to the file if level is at least equal to the current log level.
void setLogLevel(JournalLogLevel level, bool writeLogLine=true)
Set the log level for logging to file.
void setFlushLevel(JournalLogLevel level, bool writeLogLine=true)
Set level threshold for automatically flushing lines to disk.
void writeTag()
Write the tag to the file.
std::ostream & operator<<(std::ostream &os, JlHexLogger< char > const &hex)
void flush()
Flush any data to disk.
void writeLevel(JournalLogLevel level)
Write the supplied log level to the file.
XsFile & xsFile()
Return the internal XsFile object, only to be used directly when absolutely necessary.
#define xsGetCurrentThreadId()
int64_t XsFilePos
The type that is used for positioning inside a file.
A 0-terminated managed string of characters.
void init(XsString const &pathfile, bool purge)
Initialize the Journaller by (re-)creating the internal journal file.
const XsString filename() const
Returns the filename of the used journal file.
Manages threaded writes for the Journaller objects.
This class contains method to set, retrieve and compare timestamps.
A journaller class that is used for walking the stack.