e059da4de095f44b163022566d2d546e4164514a
[profile/ivi/ico-uxf-utilities.git] / include / ico_log.h
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 /*========================================================================*/
11 /**
12  *  @file   ico_log.h
13  *
14  *  @brief  debug log function
15  */
16 /*========================================================================*/
17 #ifndef __ICO_LOG_H__
18 #define __ICO_LOG_H__
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #ifndef ICO_LOG_STDOUT
25 #define ICO_LOG_STDOUT      0
26                             /**!< Log output to stdout(=1) or file(=0) */
27 #endif /*ICO_APF_LOG_STDOUT*/
28
29 #define ICO_LOG_DIR         "/var/log/ico"
30                            /**!< Directory name of Log destination */
31
32 /* Maximum lines/files */
33 #define ICO_LOG_MAXLINES    20000
34                             /**!< Maximum output lines of log file  */
35 #define ICO_LOG_MAXFILES    6
36                             /**!< Maximum number of the log file    */
37
38 /* Log output level */
39 #define ICO_LOG_DEBUG       0x0080  /**!< Debug write */
40 #define ICO_LOG_INFO        0x0040  /**!< Information */
41 #define ICO_LOG_WARNING     0x0010  /**!< Warning     */
42 #define ICO_LOG_CRITICAL    0x0008  /**!< Critical    */
43 #define ICO_LOG_ERROR       0x0004  /**!< Error       */
44
45 /* Log output flush */
46 #define ICO_LOG_FLUSH       0x4000  /**!< Log outout with log flush     */
47 #define ICO_LOG_NOFLUSH     0x2000  /**!< Log output without log flush  */
48
49 #define ICO_TRA(fmt,...)                        \
50 {                                               \
51     ico_log_print(ICO_LOG_DEBUG,                \
52                   "%s> " fmt " (%s,%s:%d)\n",   \
53                   ico_get_str_cur_time("DBG"),  \
54                   ##__VA_ARGS__,                \
55                   __func__,                     \
56                   __FILE__,                     \
57                   __LINE__);                    \
58 }
59
60 #define ICO_DBG(fmt,...)                        \
61 {                                               \
62     ico_log_print(ICO_LOG_DEBUG,                \
63                   "%s> " fmt " (%s,%s:%d)\n",   \
64                   ico_get_str_cur_time("DBG"),  \
65                   ##__VA_ARGS__,                \
66                   __func__,                     \
67                   __FILE__,                     \
68                   __LINE__);                    \
69 }
70
71 #define ICO_INF(fmt,...)                        \
72 {                                               \
73     ico_log_print(ICO_LOG_INFO,                 \
74                   "%s> " fmt " (%s,%s:%d)\n",   \
75                   ico_get_str_cur_time("INF"),  \
76                   ##__VA_ARGS__,                \
77                   __func__,                     \
78                   __FILE__,                     \
79                   __LINE__);                    \
80 }
81
82 #define ICO_WRN(fmt,...)                        \
83 {                                               \
84     ico_log_print(ICO_LOG_WARNING,              \
85                   "%s> " fmt " (%s,%s:%d)\n",   \
86                   ico_get_str_cur_time("WRN"),  \
87                   ##__VA_ARGS__,                \
88                   __func__,                     \
89                   __FILE__,                     \
90                   __LINE__);                    \
91 }
92
93 #define ICO_CRI(fmt,...)                        \
94 {                                               \
95     ico_log_print(ICO_LOG_CRITICAL,             \
96                   "%s> " fmt " (%s,%s:%d)\n",   \
97                   ico_get_str_cur_time("CRI"),  \
98                   ##__VA_ARGS__,                \
99                   __func__,                     \
100                   __FILE__,                     \
101                   __LINE__);                    \
102 }
103
104 #define ICO_ERR(fmt,...)                        \
105 {                                               \
106     ico_log_print(ICO_LOG_ERROR,                \
107                   "%s> " fmt " (%s,%s:%d)\n",   \
108                   ico_get_str_cur_time("ERR"),  \
109                   ##__VA_ARGS__,                \
110                   __func__,                     \
111                   __FILE__,                     \
112                   __LINE__);                    \
113 }
114
115
116 void ico_log_print(int level, const char *fmt, ...);
117 void ico_log_open(const char *prog);
118 void ico_log_close(void);
119 void ico_log_flush(void);
120 char * ico_get_str_cur_time(const char *level);
121 void ico_log_set_level(int level);
122
123 #ifdef __cplusplus
124 }
125 #endif
126
127 #endif  // __ICO__LOG_H__
128 /* vim:set expandtab ts=4 sw=4: */