Integrate some common codes from tota-ua
[platform/core/system/libtota.git] / ss_engine / fota_log.h
1 /*
2  * libtota
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #ifndef __FOTA_LOG_H__
20 #define __FOTA_LOG_H__
21
22 #include <stdio.h>
23
24 /*
25  * DEBUGGING FEATURE
26  */
27
28 extern unsigned int __log_level__;
29 extern FILE *__log_out_file__;
30 extern int log_printf(FILE* log_fp, char* format_str, ...);
31 extern void truncate_log_file(char *log_path, int size_kb);
32
33 #define LOG_INFO        (1<<8)
34 #define LOG_ENGINE      (1<<7)
35 #define LOG_FUNCS       (1<<6)
36 #define LOG_GUI         (1<<5)
37 #define LOG_DEBUG       (1<<4)
38 #define LOG_FILE        (1<<3)
39 #define LOG_FLASH       (1<<2)
40
41 #define LOG_SSENGINE  LOG_ENGINE
42
43 //#define DEBUG_STDOUT
44 #define DEBUG_FILE
45
46 #ifdef DEBUG_STDOUT
47 #define LOGE(s, args...) printf("UA/ERROR(%s)  " s, __func__, ##args)   // Error log
48 #define LOGL(mask, s, args...) do{if((mask) & __log_level__) printf("UA/(%s): " s,__func__, ##args);}while(0)
49 #define LOG(s, args...) LOGL(LOG_DEBUG, s, ##args)
50
51 #elif defined(DEBUG_FILE)
52 #define LOGE(s, args...) (void)log_printf(__log_out_file__, "UA/ERROR(%s)  " s, __func__, ##args)
53 #define LOGL(mask, s, args...) do{if((mask) & __log_level__) (void)log_printf(__log_out_file__, "UA/(%s): " s ,__func__, ##args);}while(0)
54 #define LOG(s, args...) LOGL(LOG_DEBUG, s, ##args)
55
56 #elif defined(DEBUG_STDOUT_FILE)        // debug printf
57 #define LOGE(s, args...) do {\
58                                                 printf("UA/ERROR(%s)  " s, __func__, ##args);\
59                                                 (void)log_printf(__log_out_file__, "UA/ERROR(%s)  " s, __func__, ##args);\
60                                         }while(0)
61 #define LOGL(mask, s, args...) do{ \
62                                                 if((mask) & __log_level__){\
63                                                         printf("UA/(%s): " s ,__func__, ##args);\
64                                                     (void)log_printf(__log_out_file__, "UA/(%s): " s,__func__, ##args);\
65                                                 }\
66                                         }while(0)
67 #define LOG(s, args...) LOGL(LOG_DEBUG, s, ##args)
68
69 #else
70 #define LOGE(s, args...)
71 #define LOGL(mask, s, args...)
72 #define LOG(s, args...)
73
74 #endif
75
76 #endif                          /* __FOTA_LOG_H__ */