summaryrefslogtreecommitdiff
path: root/Source/Kernel/Core/Log.ns.cpp
blob: 17270241ac400a2a10a7f2298b02fb78fa2ee98e (plain) (blame)
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
#include "Log.ns.h"
#include <VFS/VFS.ns.h>

namespace Log {

TextFile *logs[7] = {0, 0, 0, 0, 0, 0, 0};

void init(u8int loglevel) {
	//Create directories
	if (VFS::find("/System") == 0) VFS::createDirectory("/System");
	if (VFS::find("/System/Logs") == 0) VFS::createDirectory("/System/Logs");

	logs[KL_PANIC] = new TextFile("/System/Logs/Panic.log", FM_APPEND);
	if (KL_CRITICAL <= loglevel) logs[KL_CRITICAL] = new TextFile("/System/Logs/Critical.log", FM_APPEND);
	if (KL_ERROR <= loglevel) logs[KL_ERROR] = new TextFile("/System/Logs/Error.log", FM_APPEND);
	if (KL_WARNING <= loglevel) logs[KL_WARNING] = new TextFile("/System/Logs/Warning.log", FM_APPEND);
	if (KL_NOTICE <= loglevel) logs[KL_NOTICE] = new TextFile("/System/Logs/Notice.log", FM_APPEND);
	if (KL_STATUS <= loglevel) logs[KL_STATUS] = new TextFile("/System/Logs/Status.log", FM_APPEND);
	if (KL_DEBUG <= loglevel) logs[KL_DEBUG] = new TextFile("/System/Logs/Debug.log", FM_APPEND);
}

void close() {
	for (u32int i = 0; i < 7; i++) {
		if (logs[i] != 0) {
			delete logs[i];
			logs[i] = 0;
		}
	}
}

void log(u8int level, String event) {
	if (logs[level] != 0 and logs[level]->valid()) logs[level]->write(event, true);
}

}