modbusd
modbus master daemon
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
log.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <syslog.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 
14 
15 /* ==================================================
16  * Logging functions
17 ================================================== */
18 
19 // MAX ERROR MESSAGE LENGTH
20 #define MSG_LEN 256
21 static char cstr[MSG_LEN];
22 
23 // Error Message
24 #define ERR(flag, fmt, ...) \
25  do { \
26  snprintf(cstr, sizeof(cstr), "[%s:%d]: " fmt, __func__, __LINE__, ##__VA_ARGS__); \
27  switch (flag) \
28  { \
29  case 0: { break;} \
30  case 1: { printf("[ERROR]%s\n", cstr); } \
31  default: { syslog(LOG_ERR, "%s", cstr); break; } \
32  } \
33  } while (0)
34 
35 // Normal Message
36 #define LOG(flag, fmt, ...) \
37  do { \
38  snprintf(cstr, sizeof(cstr), "[%s:%d]: " fmt, __func__, __LINE__, ##__VA_ARGS__); \
39  switch (flag) \
40  { \
41  case 0: { break;} \
42  case 1: { printf("[LOG]%s\n", cstr); } \
43  default: { syslog(LOG_INFO, "%s", cstr); break; } \
44  } \
45  } while (0)
46 
47 // FUNCTION BEGIN
48 #define BEGIN(flag) \
49  do { \
50  snprintf(cstr, sizeof(cstr), "[BEGIN][%s:%d]", __func__, __LINE__); \
51  switch (flag) \
52  { \
53  case 0: { break;} \
54  case 1: { printf("%s\n", cstr); } \
55  default: { syslog(LOG_DEBUG, "%s", cstr); break; } \
56  } \
57  } while (0)
58 
59 // FUNCTION END
60 #define END(flag) \
61  do { \
62  snprintf(cstr, sizeof(cstr), "[END][%s:%d]", __func__, __LINE__); \
63  switch (flag) \
64  { \
65  case 0: { break;} \
66  case 1: { printf("%s\n", cstr); } \
67  default: { syslog(LOG_DEBUG, "%s", cstr); break; } \
68  } \
69  } while (0)
#define MSG_LEN
Definition: log.h:20