88 lines
2.4 KiB
C++
88 lines
2.4 KiB
C++
// =====================================================================================================================
|
|
// fennec, a free and open source game engine
|
|
// Copyright © 2025 Medusa Slockbower
|
|
//
|
|
// 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 3 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, see <https://www.gnu.org/licenses/>.
|
|
// =====================================================================================================================
|
|
|
|
///
|
|
/// \file logger.h
|
|
/// \brief
|
|
///
|
|
///
|
|
/// \details
|
|
/// \author Medusa Slockbower
|
|
///
|
|
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
|
///
|
|
///
|
|
|
|
|
|
#ifndef FENNEC_CORE_LOGGER_H
|
|
#define FENNEC_CORE_LOGGER_H
|
|
|
|
#include <fennec/filesystem/file.h>
|
|
#include <fennec/rtti/singleton.h>
|
|
#include <fennec/containers/tuple.h>
|
|
|
|
namespace fennec
|
|
{
|
|
|
|
class logger : public singleton<logger> {
|
|
public:
|
|
logger();
|
|
~logger();
|
|
|
|
static void log(const cstring& str,
|
|
uint32_t _line = FENNEC_BUILTIN_LINE(),
|
|
const char* _file = FENNEC_BUILTIN_FILE()
|
|
) {
|
|
logger& inst = instance();
|
|
|
|
if (inst._logfile.is_open()) {
|
|
inst._logfile.print(cstring(_file, strlen(_file)));
|
|
inst._logfile.printf("({}): ", _line);
|
|
inst._logfile.println(str);
|
|
}
|
|
|
|
inst._cout->print(cstring(_file, strlen(_file)));
|
|
inst._cout->printf("({}): ", _line);
|
|
inst._cout->println(str);
|
|
}
|
|
|
|
static void log(const string& str,
|
|
uint32_t _line = FENNEC_BUILTIN_LINE(),
|
|
const char* _file = FENNEC_BUILTIN_FILE()
|
|
) {
|
|
logger& inst = instance();
|
|
|
|
if (inst._logfile.is_open()) {
|
|
inst._logfile.print(cstring(_file, strlen(_file)));
|
|
inst._logfile.printf("({}): ", _line);
|
|
inst._logfile.println(str);
|
|
}
|
|
|
|
inst._cout->print(cstring(_file, strlen(_file)));
|
|
inst._cout->printf("({}): ", _line);
|
|
inst._cout->println(str);
|
|
}
|
|
|
|
private:
|
|
file _logfile;
|
|
file* _cout;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // FENNEC_CORE_LOGGER_H
|