blob: 4c91264971d5d937bfef4bfd9d1c4915a0e32fd1 [file] [log] [blame]
Anton Moberg07cf70b2021-07-07 11:08:17 +02001/*
Ledion Dajaf1dada32023-02-17 09:58:00 +01002 * SPDX-FileCopyrightText: Copyright 2021, 2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
Anton Moberg07cf70b2021-07-07 11:08:17 +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
45
Ledion Dajaf1dada32023-02-17 09:58:00 +010046#define LOG(f, ...) (void)fprintf(stdout, f, ##__VA_ARGS__)
Anton Moberg07cf70b2021-07-07 11:08:17 +020047
48#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_ERR
Ledion Dajaf1dada32023-02-17 09:58:00 +010049#define LOG_ERR(f, ...) \
50 (void)fprintf(stderr, "E: " f " (%s:%d)\n", ##__VA_ARGS__, strrchr("/" __FILE__, '/') + 1, __LINE__)
Anton Moberg07cf70b2021-07-07 11:08:17 +020051#else
52#define LOG_ERR(f, ...)
Anton Moberg07cf70b2021-07-07 11:08:17 +020053#endif
54
55#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_WARN
Ledion Dajaf1dada32023-02-17 09:58:00 +010056#define LOG_WARN(f, ...) (void)fprintf(stdout, "W: " f "\n", ##__VA_ARGS__)
Anton Moberg07cf70b2021-07-07 11:08:17 +020057#else
58#define LOG_WARN(f, ...)
Anton Moberg07cf70b2021-07-07 11:08:17 +020059#endif
60
61#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_INFO
Ledion Dajaf1dada32023-02-17 09:58:00 +010062#define LOG_INFO(f, ...) (void)fprintf(stdout, "I: " f "\n", ##__VA_ARGS__)
Anton Moberg07cf70b2021-07-07 11:08:17 +020063#else
64#define LOG_INFO(f, ...)
Anton Moberg07cf70b2021-07-07 11:08:17 +020065#endif
66
67#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_DEBUG
Ledion Dajaf1dada32023-02-17 09:58:00 +010068#define LOG_DEBUG(f, ...) (void)fprintf(stdout, "D: %s(): " f "\n", __FUNCTION__, ##__VA_ARGS__)
Anton Moberg07cf70b2021-07-07 11:08:17 +020069#else
70#define LOG_DEBUG(f, ...)
Anton Moberg07cf70b2021-07-07 11:08:17 +020071#endif
72
73#endif