| 1 |
/** |
| 2 |
* Furnace Tracker - multi-system chiptune tracker |
| 3 |
* Copyright (C) 2021-2025 tildearrow and contributors |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifndef _TA_LOG_H |
| 21 |
#define _TA_LOG_H |
| 22 |
#include <stdio.h> |
| 23 |
#include <stdarg.h> |
| 24 |
#include <time.h> |
| 25 |
#include <atomic> |
| 26 |
#include <fmt/printf.h> |
| 27 |
#include "pch.h" |
| 28 |
|
| 29 |
#define LOGLEVEL_ERROR 0 |
| 30 |
#define LOGLEVEL_WARN 1 |
| 31 |
#define LOGLEVEL_INFO 2 |
| 32 |
#define LOGLEVEL_DEBUG 3 |
| 33 |
#define LOGLEVEL_TRACE 4 |
| 34 |
|
| 35 |
// this has to be a power of 2 |
| 36 |
#define TA_LOG_SIZE 2048 |
| 37 |
|
| 38 |
// this as well |
| 39 |
#define TA_LOGFILE_BUF_SIZE 65536 |
| 40 |
|
| 41 |
extern int logLevel; |
| 42 |
|
| 43 |
extern std::atomic<unsigned short> logPosition; |
| 44 |
|
| 45 |
struct LogEntry { |
| 46 |
int loglevel; |
| 47 |
struct tm time; |
| 48 |
std::string text; |
| 49 |
bool ready; |
| 50 |
LogEntry(): |
| 51 |
loglevel(0), |
| 52 |
ready(false) { |
| 53 |
memset(&time,0,sizeof(struct tm)); |
| 54 |
} |
| 55 |
}; |
| 56 |
|
| 57 |
int writeLog(int level, const char* msg, fmt::printf_args args); |
| 58 |
|
| 59 |
extern LogEntry logEntries[TA_LOG_SIZE]; |
| 60 |
|
| 61 |
template<typename... T> int logV(const char* msg, const T&... args) { |
| 62 |
return writeLog(LOGLEVEL_TRACE,msg,fmt::make_printf_args(args...)); |
| 63 |
} |
| 64 |
|
| 65 |
template<typename... T> int logD(const char* msg, const T&... args) { |
| 66 |
return writeLog(LOGLEVEL_DEBUG,msg,fmt::make_printf_args(args...)); |
| 67 |
} |
| 68 |
|
| 69 |
template<typename... T> int logI(const char* msg, const T&... args) { |
| 70 |
return writeLog(LOGLEVEL_INFO,msg,fmt::make_printf_args(args...)); |
| 71 |
} |
| 72 |
|
| 73 |
template<typename... T> int logW(const char* msg, const T&... args) { |
| 74 |
return writeLog(LOGLEVEL_WARN,msg,fmt::make_printf_args(args...)); |
| 75 |
} |
| 76 |
|
| 77 |
template<typename... T> int logE(const char* msg, const T&... args) { |
| 78 |
return writeLog(LOGLEVEL_ERROR,msg,fmt::make_printf_args(args...)); |
| 79 |
} |
| 80 |
|
| 81 |
void initLog(FILE* where); |
| 82 |
void changeLogOutput(FILE* where); |
| 83 |
bool startLogFile(const char* path); |
| 84 |
bool finishLogFile(); |
| 85 |
#endif |