blob: 582b91d948c09c9b951a6ecdbbc7371579d82521 [file] [log] [blame]
Anton Moberg6eab40b2021-07-07 11:43:51 +02001/*
Ledion Dajaecdce6c2023-01-16 15:39:29 +01002 * SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
Anton Moberg6eab40b2021-07-07 11:43:51 +02003 *
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
Ledion Dajaecdce6c2023-01-16 15:39:29 +010045#define LOG(f, ...) (void)fprintf(stdout, f, ##__VA_ARGS__)
Anton Moberg6eab40b2021-07-07 11:43:51 +020046
47#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_ERR
Ledion Dajaecdce6c2023-01-16 15:39:29 +010048#define LOG_ERR(f, ...) \
49 (void)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
Ledion Dajaecdce6c2023-01-16 15:39:29 +010055#define LOG_WARN(f, ...) (void)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
Ledion Dajaecdce6c2023-01-16 15:39:29 +010061#define LOG_INFO(f, ...) (void)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
Ledion Dajaecdce6c2023-01-16 15:39:29 +010067#define LOG_DEBUG(f, ...) (void)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