CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
ConsoleOutput.cpp
Go to the documentation of this file.
1
5#include "ConsoleOutput.h"
6
7namespace cmlabs{
8
9bool SetDebugLevel(unsigned char level) {
10 memset(DebugLevel, level, CONSOLE_COUNT);
11 return true;
12}
13
14bool SetDebugLevel(unsigned char subject, unsigned char level) {
15 if (subject >= CONSOLE_COUNT)
16 return false;
17 DebugLevel[subject-1] = level;
18 return true;
19}
20
21bool SetVerboseLevel(unsigned char level) {
22 memset(VerboseLevel, level, CONSOLE_COUNT);
23 return true;
24}
25
26bool SetVerboseLevel(unsigned char subject, unsigned char level) {
27 if (subject >= CONSOLE_COUNT)
28 return false;
29 VerboseLevel[subject-1] = level;
30 return true;
31}
32
33bool SetErrorLevel(unsigned char level) {
34 ErrorLevel = level;
35 return true;
36}
37
38bool PrintFile(FILE* stream, const char *formatstring, ... ) {
39
40 va_list args;
41 va_start(args, formatstring);
42 char res = fprintf(stream, formatstring, args);
43 va_end(args);
44 return (res > 0);
45}
46
47bool PrintVerbose(unsigned char subject, unsigned char level, const char *formatstring, ... ) {
48
49 bool res = true;
50 if (VerboseLevel[subject] >= level) {
51 va_list args;
52 va_start(args, formatstring);
53 res = PrintFile(stdout, formatstring, args);
54 va_end(args);
55 }
56 return res;
57}
58
59bool PrintError(unsigned char level, const char *formatstring, ... ) {
60
61 bool res = true;
62 if (ErrorLevel >= level) {
63 va_list args;
64 va_start(args, formatstring);
65 res = PrintFile(stderr, formatstring, args);
66 va_end(args);
67 }
68 return res;
69}
70
71bool PrintDebug(unsigned char subject, unsigned char level, const char *formatstring, ... ) {
72
73 bool res = true;
74 if (DebugLevel[subject] >= level) {
75 va_list args;
76 va_start(args, formatstring);
77 res = PrintFile(stdout, formatstring, args);
78 va_end(args);
79 }
80 return res;
81}
82
83
84}
Levelled console logging: verbose, debug and error printf-style output with per-subject filtering.
#define CONSOLE_COUNT
Number of defined subjects (array sizes below).
bool SetDebugLevel(unsigned char level)
Set the debug level for all subjects at once.
bool PrintError(unsigned char level, const char *formatstring,...)
Print an error message if enabled.
bool SetVerboseLevel(unsigned char level)
Set the verbose level for all subjects at once.
bool PrintVerbose(unsigned char subject, unsigned char level, const char *formatstring,...)
Print a verbose (informational) message if enabled for the subject.
static unsigned char ErrorLevel
Current error level threshold.
bool PrintDebug(unsigned char subject, unsigned char level, const char *formatstring,...)
Print a debug message if enabled for the subject.
static unsigned char VerboseLevel[5]
Current verbose level per subject (index = subject-1).
bool PrintFile(FILE *stream, const char *formatstring,...)
Print a printf-style formatted string to an arbitrary stdio stream.
bool SetErrorLevel(unsigned char level)
Set the global error output level.
static unsigned char DebugLevel[5]
Current debug level per subject (index = subject-1).