]> Dogcows Code - chaz/yoink/blob - src/Moof/Log.cc
dcdb5ecf5c205e3aea8f4ab32f6309cf4e04a64e
[chaz/yoink] / src / Moof / Log.cc
1
2 /*******************************************************************************
3
4 Copyright (c) 2009, Charles McGarvey
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 *******************************************************************************/
28
29 #include <cstdarg>
30 #include <cstdio> // snprintf
31 #include <cstring> // strcpy
32
33 #include "Log.hh"
34
35
36 namespace Mf {
37
38
39 static LogLevel logLevel_ = WARNING;
40
41 static void printLog_(int logLevel, const char* fmt, va_list args)
42 {
43 if (logLevel_ < logLevel) return;
44
45 switch (logLevel)
46 {
47 case ERROR:
48 fprintf(stderr, " error: ");
49 break;
50 case WARNING:
51 fprintf(stderr, "warning: ");
52 break;
53 case INFO:
54 fprintf(stderr, " info: ");
55 break;
56 case DEBUGGING:
57 fprintf(stderr, " debug: ");
58 break;
59 }
60
61 vfprintf(stderr, fmt, args);
62 fprintf(stderr, "\n");
63 }
64
65
66 LogLevel setLogLevel(LogLevel level)
67 {
68 if (level != 0)
69 logLevel_ = level;
70
71 return logLevel_;
72 }
73
74
75 void
76 logError(const char* fmt, ...)
77 {
78 va_list args;
79 va_start(args, fmt);
80
81 printLog_(ERROR, fmt, args);
82
83 va_end(args);
84 }
85
86 void
87 logWarning(const char* fmt, ...)
88 {
89 va_list args;
90 va_start(args, fmt);
91
92 printLog_(WARNING, fmt, args);
93
94 va_end(args);
95 }
96
97 void
98 logInfo(const char* fmt, ...)
99 {
100 va_list args;
101 va_start(args, fmt);
102
103 printLog_(INFO, fmt, args);
104
105 va_end(args);
106 }
107
108 void
109 logDebug(const char* fmt, ...)
110 {
111 va_list args;
112 va_start(args, fmt);
113
114 printLog_(DEBUGGING, fmt, args);
115
116 va_end(args);
117 }
118
119
120 } // namespace Mf
121
This page took 0.035515 seconds and 3 git commands to generate.