Fix Coverity issues
[platform/core/api/sound-pool.git] / test / logger / logger.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #define MAX_PATH_LEN 1024
18 #define MAX_MSG_LEN 1024
19
20 #define _STRINGIFY(x) #x
21 #define STRINGIFY(x) _STRINGIFY(x)
22
23 #define MAX_PATH_LEN_STR STRINGIFY(MAX_PATH_LEN)
24 #define MAX_MSG_LEN_STR STRINGIFY(MAX_MSG_LEN)
25
26 #define LOG_MODE_NONE 0
27 #define LOG_MODE_FILE 1
28 #ifdef LOG_MODE_FILE
29 #    define LOG_MODE_STDERR (LOG_MODE_FILE << 1)
30 #    define LOG_MODE_DLOG   (LOG_MODE_FILE << 2)
31 #endif
32
33 #define PRINT_INFO_OR_ERROR_INFO(expr, fmt, arg...)           \
34         do {                                                    \
35                 if (expr)                                           \
36                         _logger_log_info(""fmt"", ##arg);               \
37                 else                                                \
38                         _logger_log_err(""fmt"", ##arg);                \
39         } while (0)
40
41 /* Enumeration for terminal colors. Used in internal _printf() function */
42 typedef enum {
43         CMD_COLOR_RED,
44         CMD_COLOR_YELLOW,
45         CMD_COLOR_GREEN
46 } _cmd_color_e;
47
48 /* Sets globally the mode of logging. mode has to be specified as a single or
49    combination of the following defines:
50    LOG_MODE_NONE - no logging;
51    LOG_MODE_FILE - logging to the file;
52    LOG_MODE_STDERR - logging to the standart error stream;
53    LOG_MODE_DLOG - logging to the dlog.
54    For example, set_logging_mode(LOG_MODE_FILE | LOG_MODE_DLOG) call will
55    direct all following logging to both file and dlog daemon */
56 void _logger_set_logging_mode(int mode);
57
58 /* Sets globally the name of the file for LOG_MODE_FILE logging mode */
59 int _logger_set_file(const char *fname);
60
61 /* Sets globally the log tag will be used in logging journals like Tizen dlog */
62 int _logger_set_log_tag(const char *tag);
63
64 /* Functions for corresponding logging: */
65 int _logger_log_info(const char *fmt, ...);
66 int _logger_log_warn(const char *fmt, ...);
67 int _logger_log_err(const char *fmt, ...);
68
69 /* Function for using instead of standard printf() if coloring is needed */
70 int _printf(_cmd_color_e color, const char *fmt, ...);