1 // SPDX-License-Identifier: LGPL-2.1-or-later
3 * This file is part of the PCEPlib, a PCEP protocol library.
5 * Copyright (C) 2020 Volta Networks https://voltanet.io/
7 * Author : Brady Johnson <brady@voltanet.io>
19 #include "pcep_utils_logging.h"
21 /* Forward declaration */
22 int pcep_stdout_logger(int priority
, const char *format
, va_list args
)
25 static pcep_logger_func logger_func
= pcep_stdout_logger
;
26 static int logging_level_
= LOG_INFO
;
28 void register_logger(pcep_logger_func logger
)
33 void set_logging_level(int level
)
35 logging_level_
= level
;
38 int get_logging_level(void)
40 return logging_level_
;
43 void pcep_log(int priority
, const char *format
, ...)
47 logger_func(priority
, format
, va
);
51 void pcep_log_hexbytes(int priority
, const char *message
, const uint8_t *bytes
,
54 char byte_str
[2048] = {0};
57 snprintf(byte_str
, 2048, "%s ", message
);
58 for (; i
< bytes_len
; i
++) {
59 snprintf(byte_str
, 2048, "%02x ", bytes
[i
]);
61 snprintf(byte_str
, 2048, "\n");
63 pcep_log(priority
, "%s", byte_str
);
66 /* Defined with a return type to match the FRR logging signature.
67 * Assuming glibc printf() is thread-safe. */
68 int pcep_stdout_logger(int priority
, const char *format
, va_list args
)
70 if (priority
<= logging_level_
) {
71 vprintf(format
, args
);