blob: 76fe29208664c15c41ab4a8ca25c61316925ba6f [file] [log] [blame]
Anton Moberg6eab40b2021-07-07 11:43:51 +02001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * 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, WITHOUT
14 * 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 ETHOSU_LOG_H
20#define ETHOSU_LOG_H
21
22/******************************************************************************
23 * Includes
24 ******************************************************************************/
25
26#include <stdio.h>
27#include <string.h>
28
29/******************************************************************************
30 * Defines
31 ******************************************************************************/
32
33// Log severity levels
34#define ETHOSU_LOG_ERR 0
35#define ETHOSU_LOG_WARN 1
36#define ETHOSU_LOG_INFO 2
37#define ETHOSU_LOG_DEBUG 3
38
39// Define default log severity
40#ifndef ETHOSU_LOG_SEVERITY
41#define ETHOSU_LOG_SEVERITY ETHOSU_LOG_WARN
42#endif
43
44// Log formatting
45
46#define LOG(f, ...) fprintf(stdout, f, ##__VA_ARGS__)
47
48#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_ERR
Kristofer Jonsson089a3472021-11-12 12:52:07 +010049#define LOG_ERR(f, ...) fprintf(stderr, "E: " f " (%s:%d)\n", ##__VA_ARGS__, strrchr("/" __FILE__, '/') + 1, __LINE__)
Anton Moberg6eab40b2021-07-07 11:43:51 +020050#else
51#define LOG_ERR(f, ...)
Anton Moberg6eab40b2021-07-07 11:43:51 +020052#endif
53
54#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_WARN
Kristofer Jonsson089a3472021-11-12 12:52:07 +010055#define LOG_WARN(f, ...) fprintf(stdout, "W: " f "\n", ##__VA_ARGS__)
Anton Moberg6eab40b2021-07-07 11:43:51 +020056#else
57#define LOG_WARN(f, ...)
Anton Moberg6eab40b2021-07-07 11:43:51 +020058#endif
59
60#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_INFO
Kristofer Jonsson089a3472021-11-12 12:52:07 +010061#define LOG_INFO(f, ...) fprintf(stdout, "I: " f "\n", ##__VA_ARGS__)
Anton Moberg6eab40b2021-07-07 11:43:51 +020062#else
63#define LOG_INFO(f, ...)
Anton Moberg6eab40b2021-07-07 11:43:51 +020064#endif
65
66#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_DEBUG
Kristofer Jonsson089a3472021-11-12 12:52:07 +010067#define LOG_DEBUG(f, ...) fprintf(stdout, "D: %s(): " f "\n", __FUNCTION__, ##__VA_ARGS__)
Anton Moberg6eab40b2021-07-07 11:43:51 +020068#else
69#define LOG_DEBUG(f, ...)
Anton Moberg6eab40b2021-07-07 11:43:51 +020070#endif
71
72#endif