Changed Logger
This commit is contained in:
parent
1bfc571a51
commit
07094cea1d
1 changed files with 5 additions and 1 deletions
|
|
@ -1,14 +1,18 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
|
char loggerDirPath[PATH_MAX];
|
||||||
|
|
||||||
void logger(char message[512]){
|
void logger(char message[512]){
|
||||||
FILE *log_file;
|
FILE *log_file;
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm tm = *localtime(&t);
|
struct tm tm = *localtime(&t);
|
||||||
log_file = fopen("output.log", "a");
|
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, "[%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);
|
fprintf(log_file, "%s\n", message);
|
||||||
fclose(log_file);
|
fclose(log_file);
|
||||||
|
|
|
||||||
Reference in a new issue