blob: 8977a0ceabb099009a5580cbec683d99a434ab6c [file] [log] [blame]
fei.dengf7a0cd32023-08-29 09:36:37 +00001/*
2 * Copyright (C) 2021 Amlogic Corporation.
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#ifndef __TOOLS_LOGGER_H__
17#define __TOOLS_LOGGER_H__
18#include <stdarg.h>
19
20#define LOG_LEVEL_ERROR 0
21#define LOG_LEVEL_WARNING 1
22#define LOG_LEVEL_INFO 2
23#define LOG_LEVEL_DEBUG 3
24#define LOG_LEVEL_TRACE 4
25
fei.dengb9a1a572023-09-13 01:33:57 +000026#define NO_CAT -1
27
28/**
29 * @brief init logger print
30 * @param id plugin instance id
31 *
32 * @return category id
33 */
34int Logger_init(int id);
35
36/**
37 * @brief exit logger print
38 * @param category category id
39 *
40 * @return
41 */
42void Logger_exit(int category);
43
44void logPrint(int category, int level, const char *fmt, ... );
fei.dengf7a0cd32023-08-29 09:36:37 +000045
46/**
47 * @brief set log level
48 * the log level from 0 ~ 4
49 * @param setLevel the log level
50 * 0 - ERROR
51 * 1.- WARN
52 * 2.- INFO
53 * 3.- DEBUG
54 * 4.- TRACE
55 */
56void Logger_set_level(int setLevel);
57
58/**
59 * @brief get loger level
60 *
61 * @return int the log level from 0~6
62 */
63int Logger_get_level();
64
65/**
66 * @brief set log file,the filepath must is a absolute path,
67 * if set filepath null, will close file and print log to stderr
68 * the stderr is a default print out file
69 * @param filepath the file absolute path
70 */
71void Logger_set_file(char *filepath);
72
fei.dengb9a1a572023-09-13 01:33:57 +000073#define INT_ERROR(CAT,FORMAT, ...) logPrint(CAT,LOG_LEVEL_ERROR, "%s,%s:%d " FORMAT "\n",TAG,__func__, __LINE__, __VA_ARGS__)
74#define INT_WARNING(CAT,FORMAT, ...) logPrint(CAT,LOG_LEVEL_WARNING,"%s,%s:%d " FORMAT "\n",TAG,__func__, __LINE__, __VA_ARGS__)
75#define INT_INFO(CAT,FORMAT, ...) logPrint(CAT,LOG_LEVEL_INFO, "%s,%s:%d " FORMAT "\n",TAG,__func__, __LINE__, __VA_ARGS__)
76#define INT_DEBUG(CAT,FORMAT, ...) logPrint(CAT,LOG_LEVEL_DEBUG, "%s,%s:%d " FORMAT "\n",TAG,__func__, __LINE__, __VA_ARGS__)
77#define INT_TRACE(CAT,FORMAT, ...) logPrint(CAT,LOG_LEVEL_TRACE, "%s,%s:%d " FORMAT "\n",TAG,__func__, __LINE__, __VA_ARGS__)
fei.dengf7a0cd32023-08-29 09:36:37 +000078
fei.dengb9a1a572023-09-13 01:33:57 +000079#define ERROR(CAT,...) INT_ERROR(CAT,__VA_ARGS__, "")
80#define WARNING(CAT,...) INT_WARNING(CAT,__VA_ARGS__, "")
81#define INFO(CAT,...) INT_INFO(CAT,__VA_ARGS__, "")
82#define DEBUG(CAT,...) INT_DEBUG(CAT,__VA_ARGS__, "")
83#define TRACE(CAT,...) INT_TRACE(CAT,__VA_ARGS__, "")
fei.dengf7a0cd32023-08-29 09:36:37 +000084
85#endif /*__TOOLS_LOGGER_H__*/