50 lines
1.5 KiB
C
50 lines
1.5 KiB
C
#include "include/LLog.h"
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "time.h"
|
|
|
|
int timer_array_append(timer_array* array, lTimer timer) {
|
|
if (array->count >= array->capacity) {
|
|
if (array->capacity == 0) array->capacity = 8;
|
|
else array->capacity *= 2;
|
|
|
|
array->items = realloc(array->items, array->capacity * sizeof(*array->items));
|
|
}
|
|
array->items[array->count++] = timer;
|
|
return array->count - 1;
|
|
}
|
|
|
|
int create_timer(Logger* logger) {
|
|
return timer_array_append(&logger->timers, (lTimer){});
|
|
}
|
|
|
|
void start_timer(Logger* logger, int timer_id) {
|
|
if (logger->timers.count < (timer_id + 1)) return;
|
|
logger->timers.items[timer_id].time.start = time(NULL);
|
|
}
|
|
|
|
void stop_timer(Logger* logger, int timer_id) {
|
|
if (logger->timers.count < (timer_id + 1)) return;
|
|
logger->timers.items[timer_id].time.end = time(NULL);
|
|
}
|
|
|
|
lLogString to_lLogString(const char* string) {
|
|
lLogString str;
|
|
str.buf = (char *)string;
|
|
if (string == NULL) {
|
|
str.len = 0;
|
|
} else {
|
|
str.len = strlen(string);
|
|
}
|
|
return str;
|
|
};
|
|
|
|
void lLog(Logger logger, enum lLogLevel LOG_LEVEL, lLogString MESSAGE) {
|
|
char* LOG_LEVEL_STRING = LOG_LEVEL == 0 ? "INFO" :
|
|
LOG_LEVEL == 1 ? "WARNING" :
|
|
LOG_LEVEL == 2 ? "ERROR" :
|
|
LOG_LEVEL == 3 ? "DEBUG" :
|
|
"invalid_log_level";
|
|
printf("[%s]: %.*s\n", LOG_LEVEL_STRING, (int)MESSAGE.len, MESSAGE.buf);
|
|
} |