Merge "add missing packages requires" into tizen
[profile/ivi/ico-uxf-homescreen.git] / tests / system-controller / test-dummy-hs / CicoLog.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  * @brief   Application Framework debug log function
12  *
13  * @date    Feb-28-2013
14  */
15
16 #ifndef __CICO_LOG_H__
17 #define __CICO_LOG_H__
18
19 #include    <stdio.h>
20 #include    <stdlib.h>
21 #include    <stdarg.h>
22 #include    <unistd.h>
23 #include    <string.h>
24 #include    <sys/time.h>
25 #include    <sys/types.h>
26 #include    <time.h>
27
28 #ifndef ICO_LOG_STDOUT
29 #define ICO_LOG_STDOUT      0       /* Log output to stdout(=1) or file(=0)     */
30 #endif /*ICO_APF_LOG_STDOUT*/
31
32 #define ICO_LOG_DIR         "/var/log/ico"
33                                         /* Directory name of Log destination        */
34
35 /* Maximum lines/files          */
36 #define ICO_LOG_MAXLINES    10000   /* Maximum output lines of one log file     */
37 #define ICO_LOG_MAXFILES    6       /* Maximum number of the log file           */
38
39 /* Log output level             */
40 #define ICO_LOG_DEBUG       128     /* Debug write                              */
41 #define ICO_LOG_INFO        64      /* Information                              */
42 #define ICO_LOG_WARNING     16      /* Warning                                  */
43 #define ICO_LOG_CRITICAL    8       /* Critical                                 */
44 #define ICO_LOG_ERROR       4       /* Error                                    */
45
46 /* Log output flush             */
47 #define ICO_LOG_FLUSH       0x4000  /* Log outout with log flush                */
48 #define ICO_LOG_NOFLUSH     0x2000  /* Log output without log flush             */
49
50 #define ICO_TRA(fmt,...)                                            \
51 {                                                                   \
52     CicoLog::getInstance()->printLog(ICO_LOG_DEBUG,                 \
53                                      "%s> " fmt " (%s,%s:%d)\n",    \
54                                      CicoLog::getStrCurTime("DBG"), \
55                                      ##__VA_ARGS__,                 \
56                                      __func__,                      \
57                                      __FILE__,                      \
58                                      __LINE__);                     \
59 }
60
61 #define ICO_DBG(fmt,...)                                            \
62 {                                                                   \
63     CicoLog::getInstance()->printLog(ICO_LOG_DEBUG,                 \
64                                      "%s> " fmt " (%s,%s:%d)\n",    \
65                                      CicoLog::getStrCurTime("DBG"), \
66                                      ##__VA_ARGS__,                 \
67                                      __func__,                      \
68                                      __FILE__,                      \
69                                      __LINE__);                     \
70 }
71
72 #define ICO_INF(fmt,...)                                            \
73 {                                                                   \
74     CicoLog::getInstance()->printLog(ICO_LOG_INFO,                  \
75                                      "%s> " fmt " (%s,%s:%d)\n",    \
76                                      CicoLog::getStrCurTime("INF"), \
77                                      ##__VA_ARGS__,                 \
78                                      __func__,                      \
79                                      __FILE__,                      \
80                                      __LINE__);                     \
81 }
82
83 #define ICO_WRN(fmt,...)                                            \
84 {                                                                   \
85     CicoLog::getInstance()->printLog(ICO_LOG_WARNING,               \
86                                      "%s> " fmt " (%s,%s:%d)\n",    \
87                                      CicoLog::getStrCurTime("WRN"), \
88                                      ##__VA_ARGS__,                 \
89                                      __func__,                      \
90                                      __FILE__,                      \
91                                      __LINE__);                     \
92 }
93
94 #define ICO_CRI(fmt,...)                                            \
95 {                                                                   \
96     CicoLog::getInstance()->printLog(ICO_LOG_CRITICAL,              \
97                                      "%s> " fmt " (%s,%s:%d)\n",    \
98                                      CicoLog::getStrCurTime("CRI"), \
99                                      ##__VA_ARGS__,                 \
100                                      __func__,                      \
101                                      __FILE__,                      \
102                                      __LINE__);                     \
103 }
104
105 #define ICO_ERR(fmt,...)                                            \
106 {                                                                   \
107     CicoLog::getInstance()->printLog(ICO_LOG_ERROR,                 \
108                                      "%s> " fmt " (%s,%s:%d)\n",    \
109                                      CicoLog::getStrCurTime("ERR"), \
110                                      ##__VA_ARGS__,                 \
111                                      __func__,                      \
112                                      __FILE__,                      \
113                                      __LINE__);                     \
114 }
115
116 class CicoLog
117 {
118 public:
119     CicoLog();
120
121     ~CicoLog();
122
123     static CicoLog* getInstance(void);
124
125     void printLog(int loglevel, const char *fmt, ...);
126
127     void openLog(const char *prog);
128
129     void closeLog(void);
130
131     void flushLog(void);
132
133     void setLogLevel(const int loglevel);
134
135     static char * getStrCurTime(const char *level);
136
137 private:
138     static CicoLog* ms_myInstance;  //!< CicoLog Object
139     static int  m_sTimeZone;               //!< local time difference(sec)
140     int  m_logLevel;                //!< output level debug log
141     bool m_flushMode;               //!< flush mode flag
142     bool m_initialized;             //!< initialized flag
143     FILE *m_sDbgFd;                 //!< file descriptor of output debug log
144     int  m_sDbgLines;               //!< output lines
145     char m_sDbgProg[32];            //!< name of output source module
146 };
147 #endif  // __CICO_LOG_H__
148 // vim:set expandtab ts=4 sw=4: