File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1
1
#ifndef CPP_LOGTRACER_H
2
2
#define CPP_LOGTRACER_H
3
3
4
+ #include < regex>
4
5
#include " Tracer.h"
5
6
6
7
class LogTracer : Tracer {
@@ -32,6 +33,57 @@ class LogTracer : Tracer {
32
33
addTrace (key, " print" , json::array ({message}));
33
34
return *this ;
34
35
}
36
+
37
+ LogTracer println (json message) {
38
+ addTrace (key, " println" , json::array ({message}));
39
+ return *this ;
40
+ }
41
+
42
+ LogTracer printf (string format, ...) {
43
+ json traceArgs = json::array ({format});
44
+
45
+ va_list args;
46
+ va_start (args, format);
47
+ string::const_iterator searchStart (format.cbegin ());
48
+ const std::regex exp (
49
+ " (?:[^\\ x25]|^)(?:\\ x25{2})*\\ x25(?:([1-9]\\ d*)\\ $|\\ (([^)]+)\\ ))?(\\ +)?(0|'[^$])?(-)?(\\ d+)?(?:\\ .(\\ d+))?([b-gijostTuvxX])" );
50
+ std::smatch match;
51
+ while (std::regex_search (searchStart, format.cend (), match, exp )) {
52
+ char specifier = match.str (8 ).at (0 );
53
+ switch (specifier) {
54
+ case ' b' :
55
+ case ' c' :
56
+ case ' d' :
57
+ case ' i' :
58
+ case ' u' :
59
+ case ' o' :
60
+ case ' t' :
61
+ case ' x' :
62
+ case ' X' :
63
+ traceArgs.push_back (va_arg (args, int ));
64
+ break ;
65
+ case ' e' :
66
+ case ' f' :
67
+ case ' g' :
68
+ traceArgs.push_back (va_arg (args, double ));
69
+ break ;
70
+ case ' s' :
71
+ traceArgs.push_back (va_arg (args, char *));
72
+ break ;
73
+ case ' T' :
74
+ case ' v' :
75
+ case ' j' :
76
+ throw std::invalid_argument (" Format Not Supported" );
77
+ default :
78
+ break ;
79
+ }
80
+ searchStart = match.suffix ().first ;
81
+ }
82
+ va_end (args);
83
+
84
+ addTrace (key, " printf" , traceArgs);
85
+ return *this ;
86
+ }
35
87
};
36
88
37
89
#endif
You can’t perform that action at this time.
0 commit comments