blob: 13f7726ba8c3792dbedebec4778b51727dde6889 [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 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the License); you may
6 * not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * 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, WITHOUT
13 * 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 */
17
18#ifndef ETHOSU_LOG_H
19#define ETHOSU_LOG_H
20
21/******************************************************************************
22 * Includes
23 ******************************************************************************/
24
25#include <stdio.h>
26#include <string.h>
27
28/******************************************************************************
29 * Defines
30 ******************************************************************************/
31
32// Log severity levels
33#define ETHOSU_LOG_ERR 0
34#define ETHOSU_LOG_WARN 1
35#define ETHOSU_LOG_INFO 2
36#define ETHOSU_LOG_DEBUG 3
37
38// Define default log severity
39#ifndef ETHOSU_LOG_SEVERITY
40#define ETHOSU_LOG_SEVERITY ETHOSU_LOG_WARN
41#endif
42
Jonny Svärd0189cd22023-10-11 13:33:44 +000043// Logs enabled by default
44#ifndef ETHOSU_LOG_ENABLE
45#define ETHOSU_LOG_ENABLE 1
46#endif
47
48#if ETHOSU_LOG_ENABLE
49#define LOG_COMMON(s, f, ...) (void)fprintf(s, f, ##__VA_ARGS__)
50#else
51#define LOG_COMMON(s, f, ...)
52#endif
53
Anton Moberg6eab40b2021-07-07 11:43:51 +020054// Log formatting
Jonny Svärd0189cd22023-10-11 13:33:44 +000055#define LOG(f, ...) LOG_COMMON(stdout, f, ##__VA__ARGS__)
Anton Moberg6eab40b2021-07-07 11:43:51 +020056
57#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_ERR
Ledion Dajaecdce6c2023-01-16 15:39:29 +010058#define LOG_ERR(f, ...) \
Jonny Svärd0189cd22023-10-11 13:33:44 +000059 LOG_COMMON(stderr, "E: " f " (%s:%d)\n", ##__VA_ARGS__, strrchr("/" __FILE__, '/') + 1, __LINE__)
Anton Moberg6eab40b2021-07-07 11:43:51 +020060#else
61#define LOG_ERR(f, ...)
Anton Moberg6eab40b2021-07-07 11:43:51 +020062#endif
63
64#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_WARN
Jonny Svärd0189cd22023-10-11 13:33:44 +000065#define LOG_WARN(f, ...) LOG_COMMON(stdout, "W: " f "\n", ##__VA_ARGS__)
Anton Moberg6eab40b2021-07-07 11:43:51 +020066#else
67#define LOG_WARN(f, ...)
Anton Moberg6eab40b2021-07-07 11:43:51 +020068#endif
69
70#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_INFO
Jonny Svärd0189cd22023-10-11 13:33:44 +000071#define LOG_INFO(f, ...) LOG_COMMON(stdout, "I: " f "\n", ##__VA_ARGS__)
Anton Moberg6eab40b2021-07-07 11:43:51 +020072#else
73#define LOG_INFO(f, ...)
Anton Moberg6eab40b2021-07-07 11:43:51 +020074#endif
75
76#if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_DEBUG
Jonny Svärd0189cd22023-10-11 13:33:44 +000077#define LOG_DEBUG(f, ...) LOG_COMMON(stdout, "D: %s(): " f "\n", __FUNCTION__, ##__VA_ARGS__)
Anton Moberg6eab40b2021-07-07 11:43:51 +020078#else
79#define LOG_DEBUG(f, ...)
Anton Moberg6eab40b2021-07-07 11:43:51 +020080#endif
81
Jonny Svärd0189cd22023-10-11 13:33:44 +000082#endif