forked from carlonluca/pot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lc_logging.h
1918 lines (1716 loc) · 64.2 KB
/
lc_logging.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Author: Luca Carlon
* Company: -
* Date: 05.12.2011
*
* Copyright (c) 2013 Luca Carlon. All rights reserved.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 2.1 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-2.1.html
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
/**
* Classes and structures for logging purposes. Tested on Android, iOS, Linux Embedded,
* Mac OS X, Windows Vista/7/8, Linux.
*
* Available conf macros:
* 1. COLORING_ENABLED: if defined it forces coloring. If not defined, it is defined or
* not according to the platform.
* 2. ENABLE_LOG_*: if defined, it enables the specific log level.
* 3. BUILD_LOG_LEVEL_*: if defined it enables all the levels with equal or higher
* priority.
* 4. BUILD_LOG_LEVEL_ALL: enables all the logs.
* 5. XCODE_COLORING_ENABLED: Enables coloring with XCode coloring format. This also
* enables COLORING_ENABLED automatically.
*
* Version: 1.0.0
*/
#ifndef LC_LOGGING_H
#define LC_LOGGING_H
/*------------------------------------------------------------------------------
| includes
+-----------------------------------------------------------------------------*/
#include <sstream>
#include <string>
#include <cstdio>
#include <cstdarg>
#include <cstring>
#include <iostream>
#if !defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__ANDROID__)
#include <unistd.h>
#include <execinfo.h>
#include <cxxabi.h>
#elif defined(_WIN32) || defined(_WIN32_WCE)
#include <WinBase.h>
#if WINVER < 0x0602
// It seems Windows 8.1 does not support DbgHelp yet.
#include <DbgHelp.h>
#else
// On Windows 8 this seems to be needed to get timing functions.
#include <datetimeapi.h>
#endif // WINVER<0x0602
#endif // !defined(_WIN32) && !defined(_WIN32_WCE) && !defined(NTDDI_WIN8)
#ifdef __ANDROID__
#include <android/log.h>
#else
#include <assert.h>
#endif // __ANDROID__
#ifdef QT_SQL_LIB
#include <QSqlQuery>
#include <QSqlError>
#endif // QT_SQL_LIB
#if defined(__APPLE__) && (__OBJC__ == 1)
#include <Foundation/Foundation.h>
#endif
#define VA_LIST_CONTEXT(last, i) \
{va_list args; va_start(args, last); i; va_end(args); }
#define LOG_UNUSED(x) \
(void) x
// Coloring is automatically enabled if XCODE_COLORING_ENABLED is defined.
#ifdef XCODE_COLORING_ENABLED
#define COLORING_ENABLED
#endif
// Coloring is automatically enabled on some platforms.
#ifndef COLORING_ENABLED
#if __APPLE__
#include "TargetConditionals.h"
#if TARGET_IPHONE_SIMULATOR
// iOS Simulator
#elif TARGET_OS_IPHONE
// iOS device
#elif TARGET_OS_MAC
#define COLORING_ENABLED
#else
// Unsupported platform
#endif
#elif !defined(_WIN32) && !defined(_WIN32_WCE)
#define COLORING_ENABLED
#else
// Probably some Windows. You might want to enable coloring if you intend
// to run from cygwin or similar.
#endif // __APPLE__
#endif // COLORING_ENABLED
// Define a LOG_TAG macro project-widely or none is used.
#ifndef LOG_TAG
#define LOG_TAG NULL
#endif
// Enable logs according to log level.
#ifdef BUILD_LOG_LEVEL_DEBUG
#define BUILD_LOG_LEVEL_ALL
#elif defined(BUILD_LOG_LEVEL_VERBOSE)
#define ENABLE_LOG_CRITICAL
#define ENABLE_LOG_ERROR
#define ENABLE_LOG_WARNING
#define ENABLE_LOG_INFORMATION
#define ENABLE_LOG_VERBOSE
#elif defined(BUILD_LOG_LEVEL_INFORMATION)
#define ENABLE_LOG_CRITICAL
#define ENABLE_LOG_ERROR
#define ENABLE_LOG_WARNING
#define ENABLE_LOG_INFORMATION
#elif defined(BUILD_LOG_LEVEL_WARNING)
#define ENABLE_LOG_CRITICAL
#define ENABLE_LOG_ERROR
#define ENABLE_LOG_WARNING
#elif defined(BUILD_LOG_LEVEL_ERROR)
#define ENABLE_LOG_CRITICAL
#define ENABLE_LOG_ERROR
#elif defined(BUILD_LOG_LEVEL_CRITICAL)
#define ENABLE_LOG_CRITICAL
#else
// If none is selected select all.
#ifndef BUILD_LOG_LEVEL_ALL
#define BUILD_LOG_LEVEL_ALL
#endif
#endif // BUILD_LOG_LEVEL_DEBUG
#ifdef BUILD_LOG_LEVEL_ALL
#define ENABLE_LOG_CRITICAL
#define ENABLE_LOG_ERROR
#define ENABLE_LOG_WARNING
#define ENABLE_LOG_INFORMATION
#define ENABLE_LOG_VERBOSE
#define ENABLE_LOG_DEBUG
#endif // BUILD_LOG_LEVEL_ALL
/*------------------------------------------------------------------------------
| definitions
+-----------------------------------------------------------------------------*/
enum LC_LogLevel {
// Do not mess with the order.
LC_LOG_CRITICAL = 0,
LC_LOG_ERROR = 1,
LC_LOG_WARN = 2,
LC_LOG_INFO = 3,
LC_LOG_VERBOSE = 4,
LC_LOG_DEBUG = 5,
LC_LOG_NONE = 1000
};
// Text attributes.
#define C_RESET 0
#define C_BRIGHT 1 // Bold.
#define C_DIM 2
#define C_UNDERLINE 4 // Underscore
#define C_BLINK 5
#define C_REVERSE 7
#define C_HIDDEN 8
enum LC_LogAttrib {
LC_LOG_ATTR_RESET = C_RESET,
LC_LOG_ATTR_BRIGHT = C_BRIGHT,
LC_LOG_ATTR_DIM = C_DIM,
LC_LOG_ATTR_UNDERLINE = C_UNDERLINE,
LC_LOG_ATTR_BLINK = C_BLINK,
LC_LOG_ATTR_REVERSE = C_REVERSE,
LC_LOG_ATTR_HIDDEN = C_HIDDEN
};
// Foreground colors.
#define C_F_BLACK 0
#define C_F_RED 1
#define C_F_GREEN 2
#define C_F_YELLOW 3
#define C_F_BLUE 4
#define C_F_MAGENTA 5
#define C_F_CYAN 6
#define C_F_WHITE 7
#define C_F_DEFAULT 9
enum LC_LogColor {
LC_LOG_COL_BLACK = C_F_BLACK,
LC_LOG_COL_RED = C_F_RED,
LC_LOG_COL_GREEN = C_F_GREEN,
LC_LOG_COL_YELLOW = C_F_YELLOW,
LC_LOG_COL_BLUE = C_F_BLUE,
LC_LOG_COL_MAGENTA = C_F_MAGENTA,
LC_LOG_COL_CYAN = C_F_CYAN,
LC_LOG_COL_WHITE = C_F_WHITE,
LC_LOG_COL_DEFAULT = C_F_DEFAULT
};
#ifdef XCODE_COLORING_ENABLED
static const NSString* LC_XC_COL [] = {
@"fg0,0,0;",
@"fg255,0,0;",
@"fg34,139,34;",
@"fg255,215,0;", // Gold should be more visible.
@"fg0,0,255;",
@"fg255,20,147;", // Magenta.
@"fg0,255,255;",
@"fg255,255,255;",
@"fg0,0,0;"
};
#endif // XCODE_COLORING_ENABLED
#ifdef ENABLE_LOG_CRITICAL
inline bool log_critical_t_v(const char* log_tag, const char* format, va_list args);
inline bool log_critical_t(const char* log_tag, const char* format, ...);
inline bool log_critical_v(const char* format, va_list args);
inline bool log_critical(const char* format, ...);
#if defined(__APPLE__) && __OBJC__ == 1
inline BOOL log_critical_t_v(const char* log_tag, NSString* format, va_list args);
inline BOOL log_critical_t(const char* log_tag, NSString* format, ...);
inline BOOL log_critical_v(NSString* format, va_list args);
inline BOOL log_critical(NSString* format, ...);
#endif // defined(__APPLE__) && __OBJC__ == 1
#else
inline bool log_critical_t_v(...) { return false; }
inline bool log_critical_t(...) { return false; }
inline bool log_critical_v(...) { return false; }
inline bool log_critical(...) { return false; }
#endif // ENABLE_LOG_CRITICAL
#ifdef ENABLE_LOG_ERROR
inline bool log_err_t_v(const char* log_tag, const char* format, va_list args);
inline bool log_err_t(const char* log_tag, const char* format, ...);
inline bool log_err_v(const char* format, va_list args);
inline bool log_err(const char* format, ...);
#if defined(__APPLE__) && __OBJC__ == 1
inline BOOL log_err_t_v(const char* log_tag, NSString* format, va_list args);
inline BOOL log_err_t(const char* log_tag, NSString* format, ...);
inline BOOL log_err_v(NSString* format, va_list args);
inline BOOL log_err(NSString* format, ...);
#endif // defined(__APPLE__) && __OBJC__ == 1
#else
inline bool log_err_t_v(...) { return false; }
inline bool log_err_t(...) { return false; }
inline bool log_err_v(...) { return false; }
inline bool log_err(...) { return false; }
#endif // ENABLE_LOG_ERROR
#ifdef ENABLE_LOG_WARNING
inline bool log_warn_t_v(const char* log_tag, const char* format, va_list args);
inline bool log_warn_t(const char* log_tag, const char* format, ...);
inline bool log_warn_v(const char* format, va_list args);
inline bool log_warn(const char* format, ...);
#if defined(__APPLE__) && __OBJC__ == 1
inline BOOL log_warn_t_v(const char* log_tag, NSString* format, va_list args);
inline BOOL log_warn_t(const char* log_tag, NSString* format, ...);
inline BOOL log_warn_v(NSString* format, va_list args);
inline BOOL log_warn(NSString* format, ...);
#endif // defined(__APPLE__) && __OBJC__ == 1
#else
inline bool log_warn_t_v(...) { return false; }
inline bool log_warn_t(...) { return false; }
inline bool log_warn_v(...) { return false; }
inline bool log_warn(...) { return false; }
#endif // ENABLE_LOG_WARNING
#ifdef ENABLE_LOG_INFORMATION
inline bool log_info_t_v(const char* log_tag, const char* format, va_list args);
inline bool log_info_t(const char* log_tag, const char* format, ...);
inline bool log_info_v(const char* format, va_list args);
inline bool log_info(const char* format, ...);
// TODO: Some more functions might be needed!
inline bool log_formatted_t_v(const char* log_tag, LC_LogAttrib a, LC_LogColor c, const char* format, va_list args);
inline bool log_formatted_t(const char* log_tag, LC_LogAttrib a, LC_LogColor c, const char* format, ...);
inline bool log_formatted_v(LC_LogAttrib a, LC_LogColor c, const char* format, va_list args);
inline bool log_formatted(LC_LogAttrib a, LC_LogColor c, const char* format, ...);
inline bool log_formatted(LC_LogColor c, const char* format, ...);
#if defined(__APPLE__) && __OBJC__ == 1
inline BOOL log_info_t_v(const char* log_tag, NSString* format, va_list args);
inline BOOL log_info_t(const char* log_tag, NSString* format, ...);
inline BOOL log_info_v(NSString* format, va_list args);
inline BOOL log_info(NSString* format, ...);
#endif // defined(__APPLE__) && __OBJC__ == 1
#else
inline bool log_info_t_v(...) { return true; }
inline bool log_info_t(...) { return true; }
inline bool log_info_v(...) { return true; }
inline bool log_info(...) { return true; }
inline bool log_formatted_t_v(...) { return true; }
inline bool log_formatted_t(...) { return true; }
inline bool log_formatted_v(...) { return true; }
inline bool log_formatted(...) { return true; }
#endif // ENABLE_LOG_INFORMATION
#ifdef ENABLE_LOG_VERBOSE
inline bool log_verbose_t_v(const char* log_tag, const char* format, va_list args);
inline bool log_verbose_t(const char* log_tag, const char* format, ...);
inline bool log_verbose_v(const char* format, va_list args);
inline bool log_verbose(const char* format, ...);
#if defined(__APPLE__) && __OBJC__ == 1
inline BOOL log_vervose_t_v(const char* log_tag, NSString* format, va_list args);
inline BOOL log_verbose_t(const char* log_tag, NSString* format, ...);
inline BOOL log_verbose_v(NSString* format, va_list args);
inline BOOL log_verbose(NSString* format, ...);
#endif // defined(__APPLE__) && __OBJC__ == 1
#else
inline bool log_verbose_t_v(...) { return true; }
inline bool log_verbose_t(...) { return true; }
inline bool log_verbose_v(...) { return true; }
inline bool log_verbose(...) { return true; }
#endif // ENABLE_LOG_VERBOSE
#ifdef ENABLE_LOG_DEBUG
inline void log_debug_t_v(const char* log_tag, const char* format, va_list args);
inline void log_debug_t(const char* log_tag, const char* format, ...);
inline void log_debug_v(const char* format, va_list args);
inline void log_debug(const char* format, ...);
#if defined(__APPLE__) && __OBJC__ == 1
inline void log_debug_t_v(const char* log_tag, NSString* format, va_list args);
inline void log_debug_t(const char* log_tag, NSString* format, ...);
inline void log_debug_v(NSString* format, va_list args);
inline void log_debug(NSString* format, ...);
#endif // defined(__APPLE__) && __OBJC__ == 1
#else
inline void log_debug_t_v(...) {}
inline void log_debug_t(...) {}
inline void log_debug_v(...) {}
inline void log_debug(...) {}
#endif // ENABLE_LOG_DEBUG
#if !defined(__ANDROID__) && (!defined(WINVER) || WINVER < 0x0602)
inline void log_stacktrace(const char* log_tag, LC_LogLevel level, unsigned int max_frames = 65);
inline void log_stacktrace(const char* log_tag, unsigned int max_frames = 65);
inline void log_stacktrace(LC_LogLevel level, unsigned int max_frames = 65);
inline void log_stacktrace(unsigned int max_frames = 65);
#endif // !defined(__ANDROID__) && (!defined(WINVER) || WINVER < 0x06020000)
inline std::string lc_current_time();
/*------------------------------------------------------------------------------
| lc_font_change
+-----------------------------------------------------------------------------*/
/**
* @brief lc_font_change Changes font attributes. These will be used for the text
* following this call.
* @param f The FILE* on which the color change should be written.
* @param attrib An attribute.
* @param color A color.
*/
inline void lc_font_change(FILE* f, LC_LogAttrib attrib, LC_LogColor color)
{
fprintf(f, "%c[%d;%dm", 0x1B, attrib, color + 30);
}
/*------------------------------------------------------------------------------
| lc_font_reset
+-----------------------------------------------------------------------------*/
/**
* @brief lc_font_reset Resets font attributes and color to the default params.
* @param f The file descriptor to use.
*/
inline void lc_font_reset(FILE* f)
{
fprintf(f, "%c[%dm", 0x1B, C_RESET);
}
/*------------------------------------------------------------------------------
| lc_color_change
+-----------------------------------------------------------------------------*/
/**
* @brief lc_color_change Changes the color that will be used for the following text.
* @param f The file descriptor the color change will be written.
* @param color The color to be used.
*/
inline void lc_color_change(FILE* f, LC_LogColor color)
{
lc_font_change(f, LC_LOG_ATTR_RESET, color);
}
/*------------------------------------------------------------------------------
| lc_formatted_printf
+-----------------------------------------------------------------------------*/
/**
* @brief lc_formatted_printf printf-like function accepting attributes and color for
* the text being written.
* @param f The output file descriptor to use.
* @param attrib Attribute to use for the font.
* @param color Color to use for the font.
* @param format The text to write followed by the parameters.
*/
inline void lc_formatted_printf(FILE* f, LC_LogAttrib attrib, LC_LogColor color, const char* format, ...)
{
std::stringstream sink;
sink << (char) 0x1B
<< "[" << (int) attrib << ";"
<< (int) ((int) color + 30) << "m";
sink << format;
sink << (char) 0x1B
<< "[" << (int) LC_LOG_ATTR_RESET << "m";
std::string final = sink.str();
VA_LIST_CONTEXT(format, vfprintf(f, final.c_str(), args));
}
// Assertions.
#ifdef __ANDROID__
#define LOG_ASSERT(cond, text) \
{if (!(cond)) __android_log_assert(0, LOG_TAG, text); }
#else
#define LOG_ASSERT(cond, text) assert(cond)
#endif
/*------------------------------------------------------------------------------
| LC_NullStreamBuf class
+-----------------------------------------------------------------------------*/
/**
* @brief The LC_NullStreamBuf class implements a null sink for a char stream.
*/
class LC_NullStreamBuf : public std::basic_streambuf<char> {};
/*------------------------------------------------------------------------------
| LC_NullStream class
+-----------------------------------------------------------------------------*/
/**
* @brief The LC_NullStream struct A type that can be used as a null stream. This should
* be optimized by the compiler.
*/
class LC_NullStream : public std::ostream {
public:
LC_NullStream() : std::ostream(&buf) {}
private:
LC_NullStreamBuf buf;
};
/*------------------------------------------------------------------------------
| LC_LogPriv class
+-----------------------------------------------------------------------------*/
/**
* Internal class used for logging. This class is used to prepare the string that
* will be printed by some other delegate class.
*/
template <typename T>
class LC_Log
{
public:
LC_Log(LC_LogLevel level);
LC_Log(LC_LogColor color);
LC_Log(const char* log_tag);
LC_Log(const char* log_tag, LC_LogLevel level);
LC_Log(const char* log_tag, LC_LogAttrib attrib, LC_LogColor color);
~LC_Log();
std::ostream& stream();
void printf(const char* format, ...);
void printf(const char* format, va_list args);
#ifdef QT_SQL_LIB
void printf(QSqlQuery& query, const char* format, ...);
void printf(QSqlQuery& query, const char *format, va_list args);
#endif // QT_SQL_LIB
#if defined(__APPLE__) && defined(__OBJC__)
void printf(NSString* format, ...);
void printf(NSString* format, va_list args);
#endif
static std::string toString(LC_LogLevel level);
static LC_LogLevel fromString(const std::string& level);
void prependHeader(std::string& s);
void prependLogTagIfNeeded(std::string& s);
std::stringstream m_string;
// If level is set, then attrib and color are not unless level
// is none.
LC_LogLevel m_level;
const char* m_log_tag;
LC_LogAttrib m_attrib;
LC_LogColor m_color;
private:
LC_Log(const LC_Log&);
LC_Log& operator =(const LC_Log&) ;
void initForLevel(const LC_LogLevel& level);
std::ostringstream m_stream;
};
/*------------------------------------------------------------------------------
| LC_Output2Std class
+-----------------------------------------------------------------------------*/
class LC_Output2Std
{
public:
static void printf(LC_Log<LC_Output2Std>& logger, va_list args);
static LC_LogColor getColorForLevel(LC_LogLevel level);
};
typedef LC_Log<LC_Output2Std> LC_LogStd;
/*------------------------------------------------------------------------------
| LC_Output2File class
+-----------------------------------------------------------------------------*/
class LC_Output2FILE
{
public:
static void printf(LC_Log<LC_Output2Std>& logger, va_list args);
private:
static FILE*& stream();
};
typedef LC_Log<LC_Output2FILE> LC_LogFile;
#ifdef ENABLE_MSVS_OUTPUT
/*------------------------------------------------------------------------------
| LC_Output2File class
+-----------------------------------------------------------------------------*/
/**
* Used to send debugging messages to Visual Studio instead of standard output.
*/
class LC_Output2MSVS
{
public:
static void printf(LC_Log<LC_Output2MSVS>& logger, va_list args);
};
typedef LC_Log<LC_Output2MSVS> LC_LogMSVC;
#endif // ENABLE_MSVS_OUTPUT
#ifdef __ANDROID__
/*------------------------------------------------------------------------------
| LC_OutputAndroid class
+-----------------------------------------------------------------------------*/
class LC_OutputAndroid
{
public:
static void printf(LC_Log<LC_OutputAndroid>& logger, va_list args);
};
typedef LC_Log<LC_OutputAndroid> LC_LogAndroid;
#endif // __ANDROID__
#ifdef XCODE_COLORING_ENABLED
/*------------------------------------------------------------------------------
| LC_OutputXCodeColors class
+-----------------------------------------------------------------------------*/
class LC_Output2XCodeColors
{
public:
static void printf(LC_Log<LC_Output2XCodeColors>& logger, va_list args);
static bool checkEnv();
static NSString* getColorForLevel(LC_LogLevel level);
};
typedef LC_Log<LC_Output2XCodeColors> LC_LogXCodeColors;
#endif
// Define the default logger.
#ifdef __ANDROID__
typedef LC_Log<LC_OutputAndroid> LC_LogDef;
#elif defined(XCODE_COLORING_ENABLED)
typedef LC_Log<LC_Output2XCodeColors> LC_LogDef;
#elif defined(ENABLE_MSVS_OUTPUT)
typedef LC_Log<LC_Output2MSVS> LC_LogDef;
#else
typedef LC_Log<LC_Output2Std> LC_LogDef;
#endif
#ifdef ENABLE_LOG_CRITICAL
/*------------------------------------------------------------------------------
| log_critical_t_v
+-----------------------------------------------------------------------------*/
inline bool log_critical_t_v(const char* log_tag, const char* format, va_list args)
{
LC_LogDef(log_tag, LC_LOG_CRITICAL).printf(format, args);
return false;
}
/*------------------------------------------------------------------------------
| log_err_t
+-----------------------------------------------------------------------------*/
inline bool log_critical_t(const char* log_tag, const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, LC_LOG_CRITICAL).printf(format, args));
return false;
}
/*------------------------------------------------------------------------------
| log_err_v
+-----------------------------------------------------------------------------*/
inline bool log_critical_v(const char* format, va_list args)
{
LC_LogDef(LC_LOG_CRITICAL).printf(format, args);
return false;
}
/*------------------------------------------------------------------------------
| log_err
+-----------------------------------------------------------------------------*/
inline bool log_critical(const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LC_LOG_CRITICAL).printf(format, args));
return false;
}
#if defined(__APPLE__) && __OBJC__ == 1
/*------------------------------------------------------------------------------
| log_critical_t_v
+-----------------------------------------------------------------------------*/
inline bool log_critical_t_v(const char* log_tag, NSString* format, va_list args)
{
LC_LogDef(log_tag, LC_LOG_CRITICAL).printf(format, args);
return NO;
}
/*------------------------------------------------------------------------------
| log_critical_t
+-----------------------------------------------------------------------------*/
inline bool log_critical_t(const char* log_tag, NSString* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, LC_LOG_CRITICAL).printf(format, args));
return NO;
}
/*------------------------------------------------------------------------------
| log_critical_v
+-----------------------------------------------------------------------------*/
inline bool log_critical_v(NSString* format, va_list args)
{
LC_LogDef(LC_LOG_CRITICAL).printf(format, args);
return NO;
}
/*------------------------------------------------------------------------------
| log_critical
+-----------------------------------------------------------------------------*/
inline bool log_critical(NSString* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LC_LOG_CRITICAL).printf(format, args));
return NO;
}
#endif // defined(__APPLE__) && __OBJC__ == 1
#endif // ENABLE_LOG_CRITICAL
#ifdef ENABLE_LOG_ERROR
/*------------------------------------------------------------------------------
| log_err_t_v
+-----------------------------------------------------------------------------*/
inline bool log_err_t_v(const char* log_tag, const char* format, va_list args)
{
LC_LogDef(log_tag, LC_LOG_ERROR).printf(format, args);
return false;
}
/*------------------------------------------------------------------------------
| log_err_t
+-----------------------------------------------------------------------------*/
inline bool log_err_t(const char* log_tag, const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, LC_LOG_ERROR).printf(format, args));
return false;
}
/*------------------------------------------------------------------------------
| log_err_v
+-----------------------------------------------------------------------------*/
inline bool log_err_v(const char* format, va_list args)
{
LC_LogDef(LC_LOG_ERROR).printf(format, args);
return false;
}
/*------------------------------------------------------------------------------
| log_err
+-----------------------------------------------------------------------------*/
inline bool log_err(const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LC_LOG_ERROR).printf(format, args));
return false;
}
#if defined(__APPLE__) && __OBJC__ == 1
/*------------------------------------------------------------------------------
| log_err_t_v
+-----------------------------------------------------------------------------*/
inline bool log_err_t_v(const char* log_tag, NSString* format, va_list args)
{
LC_LogDef(log_tag, LC_LOG_ERROR).printf(format, args);
return NO;
}
/*------------------------------------------------------------------------------
| log_err_t
+-----------------------------------------------------------------------------*/
inline bool log_err_t(const char* log_tag, NSString* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, LC_LOG_ERROR).printf(format, args));
return NO;
}
/*------------------------------------------------------------------------------
| log_err_v
+-----------------------------------------------------------------------------*/
inline bool log_err_v(NSString* format, va_list args)
{
LC_LogDef(LC_LOG_ERROR).printf(format, args);
return NO;
}
/*------------------------------------------------------------------------------
| log_critical
+-----------------------------------------------------------------------------*/
inline bool log_err(NSString* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LC_LOG_ERROR).printf(format, args));
return NO;
}
#endif // defined(__APPLE__) && __OBJC__ == 1
#endif // ENABLE_LOG_ERROR
#ifdef ENABLE_LOG_WARNING
/*------------------------------------------------------------------------------
| log_warn_t_v
+-----------------------------------------------------------------------------*/
inline bool log_warn_t_v(const char* log_tag, const char* format, va_list args)
{
LC_LogDef(log_tag, LC_LOG_WARN).printf(format, args);
return false;
}
/*------------------------------------------------------------------------------
| log_warn_t
+-----------------------------------------------------------------------------*/
inline bool log_warn_t(const char* log_tag, const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, LC_LOG_WARN).printf(format, args));
return false;
}
/*------------------------------------------------------------------------------
| log_warn_v
+-----------------------------------------------------------------------------*/
inline bool log_warn_v(const char* format, va_list args)
{
LC_LogDef(LC_LOG_WARN).printf(format, args);
return false;
}
/*------------------------------------------------------------------------------
| log_warn
+-----------------------------------------------------------------------------*/
inline bool log_warn(const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LC_LOG_WARN).printf(format, args));
return false;
}
#if defined(__APPLE__) && __OBJC__ == 1
/*------------------------------------------------------------------------------
| log_critical_t_v
+-----------------------------------------------------------------------------*/
inline bool log_warn_t_v(const char* log_tag, NSString* format, va_list args)
{
LC_LogDef(log_tag, LC_LOG_CRITICAL).printf(format, args);
return NO;
}
/*------------------------------------------------------------------------------
| log_critical_t
+-----------------------------------------------------------------------------*/
inline bool log_warn_t(const char* log_tag, NSString* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, LC_LOG_WARN).printf(format, args));
return NO;
}
/*------------------------------------------------------------------------------
| log_critical_v
+-----------------------------------------------------------------------------*/
inline bool log_warn_v(NSString* format, va_list args)
{
LC_LogDef(LC_LOG_WARN).printf(format, args);
return NO;
}
/*------------------------------------------------------------------------------
| log_critical
+-----------------------------------------------------------------------------*/
inline bool log_warn(NSString* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LC_LOG_WARN).printf(format, args));
return NO;
}
#endif // defined(__APPLE__) && __OBJC__ == 1
#endif // ENABLE_LOG_WARNING
#ifdef ENABLE_LOG_INFORMATION
/*------------------------------------------------------------------------------
| log_info_t_v
+-----------------------------------------------------------------------------*/
inline bool log_info_t_v(const char* log_tag, const char* format, va_list args)
{
LC_LogDef(log_tag, LC_LOG_INFO).printf(format, args);
return true;
}
/*------------------------------------------------------------------------------
| log_info_t
+-----------------------------------------------------------------------------*/
inline bool log_info_t(const char* log_tag, const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, LC_LOG_INFO).printf(format, args));
return true;
}
/*------------------------------------------------------------------------------
| log_info_vs
+-----------------------------------------------------------------------------*/
inline bool log_info_v(const char* format, va_list args)
{
LC_LogDef(LC_LOG_INFO).printf(format, args);
return true;
}
/*------------------------------------------------------------------------------
| log_info
+-----------------------------------------------------------------------------*/
inline bool log_info(const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LC_LOG_INFO).printf(format, args));
return true;
}
/*------------------------------------------------------------------------------
| log_formatted_t
+-----------------------------------------------------------------------------*/
inline bool log_formatted_t_v(const char* log_tag, LC_LogAttrib a, LC_LogColor c, const char* format, va_list args)
{
LC_LogDef(log_tag, a, c).printf(format, args);
return true;
}
/*------------------------------------------------------------------------------
| log_formatted_t
+-----------------------------------------------------------------------------*/
inline bool log_formatted_t(const char* log_tag, LC_LogAttrib a, LC_LogColor c, const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, a, c).printf(format, args));
return true;
}
/*------------------------------------------------------------------------------
| log_formatted_v
+-----------------------------------------------------------------------------*/
inline bool log_formatted_v(LC_LogAttrib a, LC_LogColor c, const char* format, va_list args)
{
LC_LogDef(LOG_TAG, a, c).printf(format, args);
return true;
}
/*------------------------------------------------------------------------------
| log_formatted
+-----------------------------------------------------------------------------*/
inline bool log_formatted(LC_LogAttrib a, LC_LogColor c, const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LOG_TAG, a, c).printf(format, args));
return true;
}
/*------------------------------------------------------------------------------
| log_formatted
+-----------------------------------------------------------------------------*/
inline bool log_formatted(LC_LogColor c, const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LOG_TAG, LC_LOG_ATTR_RESET, c).printf(format, args));
return true;
}
#if defined(__APPLE__) && __OBJC__ == 1
/*------------------------------------------------------------------------------
| log_info_t_v
+-----------------------------------------------------------------------------*/
inline bool log_info_t_v(const char* log_tag, NSString* format, va_list args)
{
LC_LogDef(log_tag, LC_LOG_INFO).printf(format, args);
return YES;
}
/*------------------------------------------------------------------------------
| log_info_t
+-----------------------------------------------------------------------------*/
inline bool log_info_t(const char* log_tag, NSString* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, LC_LOG_INFO).printf(format, args));
return YES;
}
/*------------------------------------------------------------------------------
| log_info_v
+-----------------------------------------------------------------------------*/
inline bool log_info_v(NSString* format, va_list args)
{
LC_LogDef(LC_LOG_INFO).printf(format, args);
return YES;
}
/*------------------------------------------------------------------------------
| log_info
+-----------------------------------------------------------------------------*/
inline bool log_info(NSString* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LC_LOG_INFO).printf(format, args));
return YES;
}
/*------------------------------------------------------------------------------
| log_formatted_t
+-----------------------------------------------------------------------------*/
inline bool log_formatted_t(const char* log_tag, LC_LogAttrib a, LC_LogColor c, NSString* format, va_list args)
{
LC_LogDef(log_tag, a, c).printf(format, args);
return YES;
}
/*------------------------------------------------------------------------------
| log_formatted
+-----------------------------------------------------------------------------*/
inline bool log_formatted_t(const char* log_tag, LC_LogAttrib a, LC_LogColor c, NSString* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, a, c).printf(format, args));
return YES;
}
/*------------------------------------------------------------------------------
| log_formatted
+-----------------------------------------------------------------------------*/
inline bool log_formatted(LC_LogAttrib a, LC_LogColor c, NSString* format, ...)
{
VA_LIST_CONTEXT(format, log_formatted_t(LOG_TAG, a, c, format, args));
return YES;
}
/*------------------------------------------------------------------------------
| log_formatted
+-----------------------------------------------------------------------------*/
inline bool log_formatted(LC_LogColor c, NSString* format, ...)
{
VA_LIST_CONTEXT(format, log_formatted_t(LOG_TAG, LC_LOG_ATTR_RESET, c, format, args));
return YES;
}
#endif // defined(__APPLE__) && __OBJC__ == 1
#endif // ENABLE_LOG_INFORMATION
#ifdef ENABLE_LOG_VERBOSE
/*------------------------------------------------------------------------------
| log_verbose_t_v
+-----------------------------------------------------------------------------*/
inline bool log_verbose_t_v(const char* log_tag, const char* format, va_list args)
{
LC_LogDef(log_tag, LC_LOG_VERBOSE).printf(format, args);
return true;
}
/*------------------------------------------------------------------------------
| log_verbose_t
+-----------------------------------------------------------------------------*/
inline bool log_verbose_t(const char* log_tag, const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(log_tag, LC_LOG_VERBOSE).printf(format, args));
return true;
}
/*------------------------------------------------------------------------------
| log_verbose_v
+-----------------------------------------------------------------------------*/
inline bool log_verbose_v(const char* format, va_list args)
{
LC_LogDef(LC_LOG_VERBOSE).printf(format, args);
return true;
}
/*------------------------------------------------------------------------------
| log_verbose
+-----------------------------------------------------------------------------*/
inline bool log_verbose(const char* format, ...)
{
VA_LIST_CONTEXT(format, LC_LogDef(LC_LOG_VERBOSE).printf(format, args));
return true;
}
#if defined(__APPLE__) && __OBJC__ == 1
/*------------------------------------------------------------------------------
| log_verbose_t_v