blob: 5f772d492e8377fca38fca18983e8eed335c059e [file] [log] [blame]
Radek Krejci5fe60cc2015-09-01 17:14:39 +02001/**
Michal Vaskoc446a382021-06-18 08:54:05 +02002 * @file log.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief libnetconf2 logger
Radek Krejci5fe60cc2015-09-01 17:14:39 +02005 *
Michal Vasko95ea9ff2021-11-09 12:29:14 +01006 * @copyright
Michal Vaskoc446a382021-06-18 08:54:05 +02007 * Copyright (c) 2015 - 2021 CESNET, z.s.p.o.
Radek Krejci5fe60cc2015-09-01 17:14:39 +02008 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01009 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
Michal Vaskoafd416b2016-02-25 14:51:46 +010012 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010013 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejci5fe60cc2015-09-01 17:14:39 +020014 */
15
16#ifndef NC_LOG_PRIVATE_H_
17#define NC_LOG_PRIVATE_H_
18
Radek Krejcia3528022015-09-02 13:46:38 +020019#include <stdint.h>
20
Václav Kubernáta4474cf2022-01-17 12:37:22 +010021#include "compat.h"
Radek Krejcia3528022015-09-02 13:46:38 +020022#include "log.h"
23
Radek Krejci5fe60cc2015-09-01 17:14:39 +020024/*
25 * libnetconf's message printing
26 */
27
28/**
Michal Vasko05532772021-06-03 12:12:38 +020029 * @brief Internal printing function
30 *
31 * @param[in] session Optional NETCONF session that generated the message
Radek Krejci5fe60cc2015-09-01 17:14:39 +020032 * @param[in] level Verbose level
33 * @param[in] format Formatting string
34 */
Michal Vasko05532772021-06-03 12:12:38 +020035void prv_printf(const struct nc_session *session, NC_VERB_LEVEL level, const char *format, ...);
Radek Krejci5fe60cc2015-09-01 17:14:39 +020036
37/**
38 * @brief Verbose level variable
39 */
Václav Kubernáta4474cf2022-01-17 12:37:22 +010040extern ATOMIC_T verbose_level;
Radek Krejci5fe60cc2015-09-01 17:14:39 +020041
42/*
43 * Verbose printing macros
44 */
Michal Vasko05532772021-06-03 12:12:38 +020045#define ERR(session, format, args ...) prv_printf(session,NC_VERB_ERROR,format,##args)
Václav Kubernáta4474cf2022-01-17 12:37:22 +010046#define WRN(session, format, args ...) if(ATOMIC_LOAD_RELAXED(verbose_level)>=NC_VERB_WARNING){prv_printf(session,NC_VERB_WARNING,format,##args);}
47#define VRB(session, format, args ...) if(ATOMIC_LOAD_RELAXED(verbose_level)>=NC_VERB_VERBOSE){prv_printf(session,NC_VERB_VERBOSE,format,##args);}
48#define DBG(session, format, args ...) if(ATOMIC_LOAD_RELAXED(verbose_level)>=NC_VERB_DEBUG){prv_printf(session,NC_VERB_DEBUG,format,##args);}
49#define DBL(session, format, args ...) if(ATOMIC_LOAD_RELAXED(verbose_level)>=NC_VERB_DEBUG_LOWLVL){prv_printf(session,NC_VERB_DEBUG_LOWLVL,format,##args);}
Radek Krejci5fe60cc2015-09-01 17:14:39 +020050
Michal Vasko05532772021-06-03 12:12:38 +020051#define ERRMEM ERR(NULL, "%s: memory reallocation failed (%s:%d).", __func__, __FILE__, __LINE__)
52#define ERRARG(arg) ERR(NULL, "%s: invalid argument (%s).", __func__, arg)
53#define ERRINIT ERR(NULL, "%s: libnetconf2 not initialized.", __func__)
54#define ERRINT ERR(NULL, "%s: internal error (%s:%d).", __func__, __FILE__, __LINE__)
Radek Krejci52b37022015-10-06 16:11:48 +020055
Radek Krejci5fe60cc2015-09-01 17:14:39 +020056#endif /* NC_LOG_PRIVATE_H_ */