2 * This file is part of the PCEPlib, a PCEP protocol library.
4 * Copyright (C) 2020 Volta Networks https://voltanet.io/
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * Author : Brady Johnson <brady@voltanet.io>
31 #include "pcep_utils_logging.h"
33 /* Forward declaration */
34 int pcep_stdout_logger(int priority
, const char *format
, va_list args
)
37 static pcep_logger_func logger_func
= pcep_stdout_logger
;
38 static int logging_level_
= LOG_INFO
;
40 void register_logger(pcep_logger_func logger
)
45 void set_logging_level(int level
)
47 logging_level_
= level
;
50 int get_logging_level(void)
52 return logging_level_
;
55 void pcep_log(int priority
, const char *format
, ...)
59 logger_func(priority
, format
, va
);
63 void pcep_log_hexbytes(int priority
, const char *message
, const uint8_t *bytes
,
66 char byte_str
[2048] = {0};
69 snprintf(byte_str
, 2048, "%s ", message
);
70 for (; i
< bytes_len
; i
++) {
71 snprintf(byte_str
, 2048, "%02x ", bytes
[i
]);
73 snprintf(byte_str
, 2048, "\n");
75 pcep_log(priority
, "%s", byte_str
);
78 /* Defined with a return type to match the FRR logging signature.
79 * Assuming glibc printf() is thread-safe. */
80 int pcep_stdout_logger(int priority
, const char *format
, va_list args
)
82 if (priority
<= logging_level_
) {
83 vprintf(format
, args
);