]> git.lizzy.rs Git - shadowclad.git/blob - src/engine/logger.c
Add copyright and license notices in source code
[shadowclad.git] / src / engine / logger.c
1 /**
2  * Copyright 2019-2020 Iwo 'Outfrost' Bujkiewicz
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8
9 #include "logger.h"
10
11 #include <stdarg.h>
12 #include <stdio.h>
13
14 LogLevel logLevel = LOGLEVEL_DEBUG;
15
16
17
18 void logMessage(LogLevel msgLevel, const char* func, const char* message, ...) {
19         if (msgLevel > logLevel) {
20                 return;
21         }
22
23         const char* msgLevelString;
24         switch (msgLevel) {
25                 case LOGLEVEL_ERROR:
26                         msgLevelString = "ERROR ";
27                         break;
28                 case LOGLEVEL_WARNING:
29                         msgLevelString = "WARNING ";
30                         break;
31                 case LOGLEVEL_INFO:
32                         msgLevelString = "";
33                         break;
34                 case LOGLEVEL_DEBUG:
35                         msgLevelString = "DEBUG ";
36                         break;
37                 default:
38                         msgLevelString = "(invalid message level) ";
39                         break;
40         }
41
42         va_list args;
43         va_start(args, message);
44
45         fprintf(stderr, "%s %s:: ", func, msgLevelString);
46         vfprintf(stderr, message, args);
47         fputc('\n', stderr);
48
49         va_end(args);
50 }