Grok 12.0.1
Logger.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2024 Grok Image Compression Inc.
3 *
4 * This source code is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License, version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This source code is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Affero General Public License for more details.
12 *
13 * You should have received a copy of the GNU Affero General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include <cstring>
20#include <cstdarg>
21
22#include "grok.h"
23#include "ILogger.h"
24
25namespace grk
26{
27
28struct Logger : public ILogger
29{
34
35 void info(const char* fmt, ...) override
36 {
37 if(!info_handler)
38 return;
42 va_end(arg);
43 }
44 void warn(const char* fmt, ...) override
45 {
47 return;
51 va_end(arg);
52 }
53 void error(const char* fmt, ...) override
54 {
55 if(!error_handler)
56 return;
60 va_end(arg);
61 }
62
69
71
72 private:
73 template<typename... Args>
74 void log_message(grk_msg_callback msg_handler, void* l_data, char const* const format,
75 Args&... args) noexcept
76 {
77 const int message_size = 512;
78 if((format != nullptr))
79 {
80 char message[message_size];
81 memset(message, 0, message_size);
82 vsnprintf(message, message_size, format, args...);
83 msg_handler(message, l_data);
84 }
85 }
86};
87
88} // namespace grk
void(* grk_msg_callback)(const char *msg, void *client_data)
Logging callback.
Definition grok.h:136
Copyright (C) 2016-2024 Grok Image Compression Inc.
Definition ICacheable.h:20
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition BufferedStream.h:239
Definition ILogger.h:26
Definition Logger.h:29
grk_msg_callback warning_handler
Definition Logger.h:67
void warn(const char *fmt,...) override
Definition Logger.h:44
grk_msg_callback error_handler
Definition Logger.h:66
grk_msg_callback info_handler
Definition Logger.h:68
void * info_data_
Definition Logger.h:65
void error(const char *fmt,...) override
Definition Logger.h:53
void * warning_data_
Definition Logger.h:64
Logger()
Definition Logger.h:30
void * error_data_
Definition Logger.h:63
void info(const char *fmt,...) override
Definition Logger.h:35
void log_message(grk_msg_callback msg_handler, void *l_data, char const *const format, Args &... args) noexcept
Definition Logger.h:74
static Logger logger_
Definition Logger.h:70