blob: 6c115abcb5f5e39d9c896fd048a85b1891282f48 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
Kshitij Sisodia657a54d2022-12-22 16:51:23 +00002 * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates
3 * <open-source-office@arm.com> SPDX-License-Identifier: Apache-2.0
alexander3c798932021-03-26 21:42:19 +00004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
alexander31ae9f02022-02-10 16:15:54 +000017#ifndef ML_EMBEDDED_CORE_LOG_H
18#define ML_EMBEDDED_CORE_LOG_H
19
20#ifdef __cplusplus
21extern "C" {
22#endif
alexander3c798932021-03-26 21:42:19 +000023
alexander31ae9f02022-02-10 16:15:54 +000024#include <inttypes.h>
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000025#include <stdio.h>
alexander3c798932021-03-26 21:42:19 +000026
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000027#define LOG_LEVEL_TRACE 0
28#define LOG_LEVEL_DEBUG 1
29#define LOG_LEVEL_INFO 2
30#define LOG_LEVEL_WARN 3
31#define LOG_LEVEL_ERROR 4
alexander3c798932021-03-26 21:42:19 +000032
33#ifndef LOG_LEVEL
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000034#define LOG_LEVEL LOG_LEVEL_INFO
alexander3c798932021-03-26 21:42:19 +000035#endif /*LOG_LEVEL*/
36
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000037#if !defined(UNUSED)
38#define UNUSED(x) ((void)(x))
39#endif /* #if !defined(UNUSED) */
alexander3c798932021-03-26 21:42:19 +000040
41#if (LOG_LEVEL == LOG_LEVEL_TRACE)
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000042#define trace(...) \
43 printf("TRACE - "); \
44 printf(__VA_ARGS__)
alexander3c798932021-03-26 21:42:19 +000045#else
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000046#define trace(...)
47#endif /* LOG_LEVEL == LOG_LEVEL_TRACE */
alexander3c798932021-03-26 21:42:19 +000048
49#if (LOG_LEVEL <= LOG_LEVEL_DEBUG)
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000050#define debug(...) \
51 printf("DEBUG - "); \
52 printf(__VA_ARGS__)
alexander3c798932021-03-26 21:42:19 +000053#else
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000054#define debug(...)
55#endif /* LOG_LEVEL > LOG_LEVEL_TRACE */
alexander3c798932021-03-26 21:42:19 +000056
57#if (LOG_LEVEL <= LOG_LEVEL_INFO)
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000058#define info(...) \
59 printf("INFO - "); \
60 printf(__VA_ARGS__)
alexander3c798932021-03-26 21:42:19 +000061#else
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000062#define info(...)
63#endif /* LOG_LEVEL > LOG_LEVEL_DEBUG */
alexander3c798932021-03-26 21:42:19 +000064
65#if (LOG_LEVEL <= LOG_LEVEL_WARN)
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000066#define warn(...) \
67 printf("WARN - "); \
68 printf(__VA_ARGS__)
alexander3c798932021-03-26 21:42:19 +000069#else
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000070#define warn(...)
71#endif /* LOG_LEVEL > LOG_LEVEL_INFO */
alexander3c798932021-03-26 21:42:19 +000072
73#if (LOG_LEVEL <= LOG_LEVEL_ERROR)
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000074#define printf_err(...) \
75 printf("ERROR - "); \
76 printf(__VA_ARGS__)
alexander3c798932021-03-26 21:42:19 +000077#else
Kshitij Sisodia657a54d2022-12-22 16:51:23 +000078#define printf_err(...)
79#endif /* LOG_LEVEL > LOG_LEVEL_INFO */
alexander3c798932021-03-26 21:42:19 +000080
alexander31ae9f02022-02-10 16:15:54 +000081#ifdef __cplusplus
82}
83#endif
84
Kshitij Sisodia8c61c0a2022-05-17 11:16:22 +010085#endif /* ML_EMBEDDED_CORE_LOG_H */