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>
26 #include "pcep_utils_logging.h"
28 /* Forward declaration */
29 int pcep_stdout_logger(int priority
, const char *format
, va_list args
);
31 static pcep_logger_func logger_func
= pcep_stdout_logger
;
32 static int logging_level_
= LOG_INFO
;
34 void register_logger(pcep_logger_func logger
)
39 void set_logging_level(int level
)
41 logging_level_
= level
;
44 int get_logging_level()
46 return logging_level_
;
49 void pcep_log(int priority
, const char *format
, ...)
53 logger_func(priority
, format
, va
);
57 void pcep_log_hexbytes(int priority
, const char *message
, const uint8_t *bytes
,
60 char byte_str
[2048] = {0};
63 snprintf(byte_str
, 2048, "%s ", message
);
64 for (; i
< bytes_len
; i
++) {
65 snprintf(byte_str
, 2048, "%02x ", bytes
[i
]);
67 snprintf(byte_str
, 2048, "\n");
69 pcep_log(priority
, "%s", byte_str
);
72 /* Defined with a return type to match the FRR logging signature.
73 * Assuming glibc printf() is thread-safe. */
74 int pcep_stdout_logger(int priority
, const char *format
, va_list args
)
76 if (priority
<= logging_level_
) {
77 vprintf(format
, args
);