-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlog.h
More file actions
40 lines (31 loc) · 1.11 KB
/
log.h
File metadata and controls
40 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include <stdio.h>
#include <stdarg.h>
void printLog(const char* Achar,
bool isPrintToStdOutput = true,
bool isPrintToFile = true,
const char* timeLog = "",
const char* logFilePath = "log/log.log",
const char* fileName = "",
int numberLine = 0,
...) {
FILE * log = fopen(logFilePath, "a");
if (!log) return;
va_list args;
va_start(args, Achar);
if (isPrintToFile) {
fprintf(log, "Time: %s \n File: %s \n Line: %d \n Message: ", timeLog, fileName, numberLine);
vfprintf(log, Achar, args);
fprintf(log, "\n\n");
}
if (isPrintToStdOutput) {
printf("Time: %s \n File: %s \n Line: %d \n Message: ", timeLog, fileName, numberLine);
vprintf(Achar, args);
printf("\n\n");
}
fclose(log);
va_end(args);
}
#define Log(s) \
printLog(true, true, asctime(localtime(&time(NULL))), "log/" + __FILE__ + ".log", __FILE__, __LINE__); \
printLog(true, true, asctime(localtime(&time(NULL))), "log/log.log", __FILE__, __LINE__);