mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 18:57:07 -07:00
Log Level and Timestamp to File
This commit is contained in:
parent
1811fe2133
commit
d8226f2693
3 changed files with 33 additions and 18 deletions
|
@ -64,10 +64,14 @@ void SessionLog::Log(ChiakiLogLevel level, const char *msg)
|
|||
|
||||
if(file)
|
||||
{
|
||||
static const QString date_format = "yyyy-MM-dd HH:mm:ss:zzzzzz";
|
||||
QString str = QString("[%1] [%2] %3\n").arg(
|
||||
QDateTime::currentDateTime().toString(date_format),
|
||||
QString(chiaki_log_level_char(level)),
|
||||
msg);
|
||||
|
||||
QMutexLocker lock(&file_mutex);
|
||||
// TODO: add timestamp and level
|
||||
file->write(msg);
|
||||
file->write("\n");
|
||||
file->write(str.toLocal8Bit());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,12 +89,12 @@ static void LogCb(ChiakiLogLevel level, const char *msg, void *user)
|
|||
|
||||
#define KEEP_LOG_FILES_COUNT 5
|
||||
|
||||
static const QString date_format = "yyyy-MM-dd_HH-mm-ss-zzzz";
|
||||
static const QString session_log_wildcard = "chiaki_session_*.log";
|
||||
static const QRegularExpression session_log_regex("chiaki_session_(.*).log");
|
||||
|
||||
QString CreateLogFilename()
|
||||
{
|
||||
static const QString date_format = "yyyy-MM-dd_HH-mm-ss-zzzzzz";
|
||||
static const QString session_log_wildcard = "chiaki_session_*.log";
|
||||
static const QRegularExpression session_log_regex("chiaki_session_(.*).log");
|
||||
|
||||
auto base_dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
if(base_dir.isEmpty())
|
||||
return QString();
|
||||
|
|
|
@ -37,6 +37,8 @@ typedef enum {
|
|||
|
||||
#define CHIAKI_LOG_ALL ((1 << 5) - 1)
|
||||
|
||||
CHIAKI_EXPORT char chiaki_log_level_char(ChiakiLogLevel level);
|
||||
|
||||
typedef void (*ChiakiLogCb)(ChiakiLogLevel level, const char *msg, void *user);
|
||||
|
||||
typedef struct chiaki_log_t
|
||||
|
|
|
@ -20,6 +20,25 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
CHIAKI_EXPORT char chiaki_log_level_char(ChiakiLogLevel level)
|
||||
{
|
||||
switch(level)
|
||||
{
|
||||
case CHIAKI_LOG_VERBOSE:
|
||||
return 'V';
|
||||
case CHIAKI_LOG_DEBUG:
|
||||
return 'D';
|
||||
case CHIAKI_LOG_INFO:
|
||||
return 'I';
|
||||
case CHIAKI_LOG_WARNING:
|
||||
return 'W';
|
||||
case CHIAKI_LOG_ERROR:
|
||||
return 'E';
|
||||
default:
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT void chiaki_log_init(ChiakiLog *log, uint32_t level_mask, ChiakiLogCb cb, void *user)
|
||||
{
|
||||
log->level_mask = level_mask;
|
||||
|
@ -31,30 +50,20 @@ CHIAKI_EXPORT void chiaki_log_cb_print(ChiakiLogLevel level, const char *msg, vo
|
|||
{
|
||||
(void)user;
|
||||
|
||||
char c;
|
||||
char c = chiaki_log_level_char(level);
|
||||
const char *color = NULL;
|
||||
switch(level)
|
||||
{
|
||||
case CHIAKI_LOG_VERBOSE:
|
||||
c = 'V';
|
||||
break;
|
||||
case CHIAKI_LOG_DEBUG:
|
||||
c = 'D';
|
||||
color = "34";
|
||||
break;
|
||||
case CHIAKI_LOG_INFO:
|
||||
c = 'I';
|
||||
break;
|
||||
case CHIAKI_LOG_WARNING:
|
||||
c = 'W';
|
||||
color = "33";
|
||||
break;
|
||||
case CHIAKI_LOG_ERROR:
|
||||
c = 'E';
|
||||
color = "31";
|
||||
break;
|
||||
default:
|
||||
c = '?';
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue