This repository has been archived on 2026-03-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
netbenixCMD/utils/logger.c
2020-07-24 16:50:12 +02:00

20 lines
No EOL
587 B
C

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <linux/limits.h>
#include "logger.h"
char loggerDirPath[PATH_MAX];
//Logs given message into output.log
void logger(char message[512]){
FILE *log_file;
time_t t = time(NULL);
struct tm tm = *localtime(&t);
char buffer[1024];
snprintf(buffer, sizeof(buffer), "%s/output.log", loggerDirPath);
log_file = fopen(buffer, "a");
fprintf(log_file, "[%d-%02d-%02d %02d:%02d:%02d] ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
fprintf(log_file, "%s\n", message);
fclose(log_file);
}