1 krisbash 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 krisbash 1.1 **==============================================================================
23 */
24
25 #ifndef _logging_h
26 #define _logging_h
27
28 // Logging functions for OMI components used outside of omi{agent,check,cli,gen,reg,server}
29
30 #ifndef ENABLE_TRACING // We need to change this to log instead of printing on
31 // stdout, when log file rotation is implemented and when
32 // logging from library components used outside of
33 // omi{agent,check,cli,gen,reg,server} is finished.
34
35 #define LOGE2(a)
36 #define LOGW2(a)
37 #define LOGD2(a)
38 #define LOGX2(a)
39
40 #else
41
42 #include <stdio.h>
43 krisbash 1.1 #include <stddef.h>
44 #include <pthread.h>
45
46 #include <MI.h>
47 #include <common.h>
48 #include <base/result.h>
49
50 #if defined(linux)
51 #include <syscall.h>
52 #endif
53
54 #if defined(CONFIG_OS_WINDOWS)
55 #define getpid GetCurrentProcessId()
56 #endif
57
58 // The time stamp for log messages
59 #define TIMESTAMP(typ) \
60 {\
61 MI_Uint64 currentTimeUsec;\
62 void* ptr;\
63 ptr = malloc(8);\
64 krisbash 1.1 free(ptr);\
65 Time_Now(¤tTimeUsec);\
66 printf("%s %s %u:%lu %s:%d ", FmtTime(currentTimeUsec), typ, (unsigned int)getpid(), get_tid(), __FILE__, __LINE__);\
67 }
68
69 #undef printf
70
71 // the LOGE2, LOGW2 nd LOGD2 macros
72 #ifndef TRACING_LEVEL
73 #define TRACING_LEVEL 2
74 #endif
75
76 #if TRACING_LEVEL > 4
77 #define LOGX2(a) TIMESTAMP("X"); printf a; putchar('\n'); fflush(stdout);
78 #else
79 #define LOGX2(a)
80 #endif
81
82 #if TRACING_LEVEL > 3
83 #define LOGD2(a) do { TIMESTAMP("T"); printf a; putchar('\n'); fflush(stdout); } while (0)
84 #else
85 krisbash 1.1 #define LOGD2(a)
86 #endif
87
88 #if TRACING_LEVEL > 2
89 #define LOGW2(a) do { TIMESTAMP("W"); printf a; putchar('\n'); fflush(stdout); } while (0)
90 #else
91 #define LOGW2(a)
92 #endif
93
94 #define LOGE2(a) do { TIMESTAMP("E"); printf a; putchar('\n'); fflush(stdout); } while (0)
95
96 /*
97 **==============================================================================
98 **
99 ** Formatting functions for some data types
100 **
101 **==============================================================================
102 */
103
104 BEGIN_EXTERNC
105
106 krisbash 1.1 extern unsigned long get_tid();
107 extern const char* mistrerror(MI_Result res);
108 extern const char* selectorflagstr(MI_Uint32 Flags);
109 extern const char* bitnumberstr(unsigned long Bits);
110 extern const char* sslstrerror(int SslError);
111 extern const char* notifyitemtypestr(int NotifyItemType);
112 extern const char* clientstatusstr(int Status);
113 extern const char* messagetagnamestr(int Tag);
114 extern const char* protocoleventnamestr(int Event);
115 extern const char* FmtTime(MI_Uint64 Time);
116 extern const char* FmtInterval( MI_Sint64 Time);
117 extern MI_Result Time_Now(MI_Uint64* self);
118
119 END_EXTERNC
120
121 #endif // defined ENABLE_TRACING
122
123 #endif // defined _logging_h
|