furnace/src/ta-log.h

85 lines
2.3 KiB
C
Raw Normal View History

2022-02-15 03:12:20 +00:00
/**
* Furnace Tracker - multi-system chiptune tracker
2023-01-20 00:18:40 +00:00
* Copyright (C) 2021-2023 tildearrow and contributors
2022-02-15 03:12:20 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _TA_LOG_H
#define _TA_LOG_H
#include <stdio.h>
#include <stdarg.h>
2022-04-11 05:12:24 +00:00
#include <time.h>
#include <atomic>
#include <string>
#include <fmt/printf.h>
#define LOGLEVEL_ERROR 0
#define LOGLEVEL_WARN 1
#define LOGLEVEL_INFO 2
#define LOGLEVEL_DEBUG 3
2022-03-24 03:05:09 +00:00
#define LOGLEVEL_TRACE 4
// this has to be a power of 2
#define TA_LOG_SIZE 2048
2022-12-18 06:55:21 +00:00
// this as well
#define TA_LOGFILE_BUF_SIZE 65536
2021-06-09 17:28:46 +00:00
extern int logLevel;
extern std::atomic<unsigned short> logPosition;
struct LogEntry {
int loglevel;
2022-04-11 05:12:24 +00:00
struct tm time;
std::string text;
bool ready;
LogEntry():
loglevel(0),
2022-04-14 23:25:59 +00:00
ready(false) {
memset(&time,0,sizeof(struct tm));
}
};
2022-04-11 18:08:12 +00:00
int writeLog(int level, const char* msg, fmt::printf_args args);
extern LogEntry logEntries[TA_LOG_SIZE];
template<typename... T> int logV(const char* msg, const T&... args) {
2022-04-11 18:36:02 +00:00
return writeLog(LOGLEVEL_TRACE,msg,fmt::make_printf_args(args...));
}
template<typename... T> int logD(const char* msg, const T&... args) {
2022-04-11 18:36:02 +00:00
return writeLog(LOGLEVEL_DEBUG,msg,fmt::make_printf_args(args...));
}
template<typename... T> int logI(const char* msg, const T&... args) {
2022-04-11 18:36:02 +00:00
return writeLog(LOGLEVEL_INFO,msg,fmt::make_printf_args(args...));
}
template<typename... T> int logW(const char* msg, const T&... args) {
2022-04-11 18:36:02 +00:00
return writeLog(LOGLEVEL_WARN,msg,fmt::make_printf_args(args...));
}
template<typename... T> int logE(const char* msg, const T&... args) {
2022-04-11 18:36:02 +00:00
return writeLog(LOGLEVEL_ERROR,msg,fmt::make_printf_args(args...));
}
void initLog();
2022-12-18 06:55:21 +00:00
bool startLogFile(const char* path);
bool finishLogFile();
#endif