blob: 15f4dd50e88336f4800d4805a9dc8b8d57adb76b [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
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
24#include <stdio.h>
alexander31ae9f02022-02-10 16:15:54 +000025#include <inttypes.h>
alexander3c798932021-03-26 21:42:19 +000026
27#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
32
33#ifndef LOG_LEVEL
34#define LOG_LEVEL LOG_LEVEL_INFO
35#endif /*LOG_LEVEL*/
36
37#define UNUSED(x) ((void)(x))
38
39#if (LOG_LEVEL == LOG_LEVEL_TRACE)
Isabella Gottardi8df12f32021-04-07 17:15:31 +010040 #define trace(...) printf("TRACE - "); printf(__VA_ARGS__)
alexander3c798932021-03-26 21:42:19 +000041#else
42 #define trace(...)
43#endif /* LOG_LEVEL == LOG_LEVEL_TRACE */
44
45#if (LOG_LEVEL <= LOG_LEVEL_DEBUG)
Isabella Gottardi8df12f32021-04-07 17:15:31 +010046 #define debug(...) printf("DEBUG - "); printf(__VA_ARGS__)
alexander3c798932021-03-26 21:42:19 +000047#else
48 #define debug(...)
49#endif /* LOG_LEVEL > LOG_LEVEL_TRACE */
50
51#if (LOG_LEVEL <= LOG_LEVEL_INFO)
Isabella Gottardi8df12f32021-04-07 17:15:31 +010052 #define info(...) printf("INFO - "); printf(__VA_ARGS__)
alexander3c798932021-03-26 21:42:19 +000053#else
54 #define info(...)
55#endif /* LOG_LEVEL > LOG_LEVEL_DEBUG */
56
57#if (LOG_LEVEL <= LOG_LEVEL_WARN)
Isabella Gottardi8df12f32021-04-07 17:15:31 +010058 #define warn(...) printf("WARN - "); printf(__VA_ARGS__)
alexander3c798932021-03-26 21:42:19 +000059#else
60 #define warn(...)
61#endif /* LOG_LEVEL > LOG_LEVEL_INFO */
62
63#if (LOG_LEVEL <= LOG_LEVEL_ERROR)
Isabella Gottardi8df12f32021-04-07 17:15:31 +010064 #define printf_err(...) printf("ERROR - "); printf(__VA_ARGS__)
alexander3c798932021-03-26 21:42:19 +000065#else
66 #define printf_err(...)
67#endif /* LOG_LEVEL > LOG_LEVEL_INFO */
68
alexander31ae9f02022-02-10 16:15:54 +000069#ifdef __cplusplus
70}
71#endif
72
73#endif /* ML_EMBEDDED_CORE_LOG_H */