33#elif defined __APPLE__
34#include <Carbon/Carbon.h>
41static std::string getDateString()
43 time_t t = time(
nullptr);
44 struct tm *now = localtime(&t);
46 strftime(buffer,
sizeof(buffer),
"%Y-%m-%d", now);
50static std::string &secureName(std::string &name)
52 const size_t sz = name.length();
53 for (
size_t f = 0; f < sz; f ++)
55 const unsigned char ch = name[f];
56 if ((ch <
'0' || ch >
'9') &&
57 (ch <
'a' || ch >
'z') &&
58 (ch <
'A' || ch >
'Z') &&
76static void makeDir(
const std::string &dir)
81 mkdir(dir.c_str(), S_IRWXU | S_IRGRP | S_IXGRP);
93 mLogFile.open(logFilename, std::ios_base::app);
97 std::cout <<
"Warning: error while opening " << logFilename <<
109 DIR *dir = opendir(
mLogDir.c_str());
118 std::string dateStr = getDateString();
134 std::ofstream logFile;
135 logFile.open(
strprintf(
"%s/%s/%s_%s.log",
138 secureName(name).c_str(),
139 getDateString().c_str())
143 if (!logFile.is_open())
147 logFile << str << std::endl;
void setServerName(const std::string &serverName)
void setLogFile(const std::string &logFilename)
Sets the file to log to and opens it.
void setLogDir(const std::string &logDir)
void log(std::string str)
Enters a message in the log.
Config config
Global settings (config.xml)
bool mkdir(const std::string &path)
Creates a directory in the write path.
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.
std::string & removeColors(std::string &msg)
Removes colors from a string.