comparison gen/logger.c @ 38:27b2f40bdb58 trunk

[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back. Fiddled a bit the the testing system. Added a very simple SDL graphics demo.
author lindquist
date Wed, 10 Oct 2007 06:16:48 +0200
parents e116aa1488e6
children
comparison
equal deleted inserted replaced
37:77cdca8c210f 38:27b2f40bdb58
1 #ifndef LLVMD_NO_LOGGER
2
3 #include <cassert> 1 #include <cassert>
4 #include <cstdarg> 2 #include <cstdarg>
5 #include <cstdio> 3 #include <cstdio>
6 #include <cstdlib> 4 #include <cstdlib>
7 #include <iostream> 5 #include <iostream>
6 #include <fstream>
8 #include <string> 7 #include <string>
9 8
10 #include "gen/logger.h" 9 #include "gen/logger.h"
11 10
12 namespace Logger 11 namespace Logger
13 { 12 {
14 static std::string indent_str; 13 static std::string indent_str;
14 static std::ofstream null_out("/dev/null");
15
16 static bool enabled = false;
15 void indent() 17 void indent()
16 { 18 {
19 if (enabled)
17 indent_str += " "; 20 indent_str += " ";
18 } 21 }
19 void undent() 22 void undent()
20 { 23 {
21 assert(!indent_str.empty()); 24 if (enabled) {
22 indent_str.resize(indent_str.size()-2); 25 assert(!indent_str.empty());
26 indent_str.resize(indent_str.size()-2);
27 }
23 } 28 }
24 std::ostream& cout() 29 std::ostream& cout()
25 { 30 {
26 return std::cout << indent_str; 31 if (enabled)
32 return std::cout << indent_str;
33 else
34 return null_out;
27 } 35 }
28 void println(const char* fmt,...) 36 void println(const char* fmt,...)
29 { 37 {
30 printf(indent_str.c_str()); 38 if (enabled) {
31 va_list va; 39 printf(indent_str.c_str());
32 va_start(va,fmt); 40 va_list va;
33 vprintf(fmt,va); 41 va_start(va,fmt);
34 va_end(va); 42 vprintf(fmt,va);
35 printf("\n"); 43 va_end(va);
44 printf("\n");
45 }
36 } 46 }
37 void print(const char* fmt,...) 47 void print(const char* fmt,...)
38 { 48 {
39 printf(indent_str.c_str()); 49 if (enabled) {
40 va_list va; 50 printf(indent_str.c_str());
41 va_start(va,fmt); 51 va_list va;
42 vprintf(fmt,va); 52 va_start(va,fmt);
43 va_end(va); 53 vprintf(fmt,va);
54 va_end(va);
55 }
56 }
57 void enable()
58 {
59 enabled = true;
60 }
61 void disable()
62 {
63 enabled = false;
44 } 64 }
45 } 65 }
46 66
47 #endif