multithread-server/log/log.cpp

33 lines
753 B
C++

#include <iostream>
#include <string>
#include <sys/stat.h>
#include <cstring>
#include <time.h>
#include <fstream>
#include <ctime>
#include <pthread.h>
std::string LOG_DIR = "/log_data";
void log(std::string msg) {
mkdir(LOG_DIR.c_str(), 0755);
time_t now = time(0);
struct tm tstruct;
tstruct = *localtime(&now);
char filename[12];
std::strftime(filename, 12, "%Y-%m-%d", &tstruct);
std::ofstream log_file;
log_file.open(LOG_DIR + "/" + filename + ".log", std::ios_base::app);
char timestamp[32];
std::strftime(timestamp, 32, "%Y/%m/%d %H:%M:%S ", &tstruct);
log_file << timestamp << msg << std::endl;
log_file.close();
}
int main() {
log("uwu");
log("owo");
log("yay");
return 0;
}