ember.cpp 0.1.0
C++ inference engine for Llama-family and paperkiln models (CPU, CUDA, WebAssembly)
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6#include <fstream>
7#include <sstream>
8#include <iomanip>
9
10// Windows header protection
11#ifdef _WIN32
12#ifndef NOMINMAX
13#define NOMINMAX
14#endif
15#ifndef WIN32_LEAN_AND_MEAN
16#define WIN32_LEAN_AND_MEAN
17#endif
18// Undefine common Windows macros that might conflict
19#ifdef ERROR
20#undef ERROR
21#endif
22#ifdef DEBUG
23#undef DEBUG
24#endif
25#ifdef INFO
26#undef INFO
27#endif
28#ifdef WARNING
29#undef WARNING
30#endif
31#ifdef CRITICAL
32#undef CRITICAL
33#endif
34#endif // _WIN32
35
52class Logger {
53
54 public:
55 // Explicitly scoped enumeration to avoid conflicts with Windows macros
56 enum class Level : int {
57 DEBUG = 0,
58 INFO = 1,
59 WARNING = 2,
60 ERROR = 3,
61 CRITICAL = 4,
62 OFF = 5
63 };
64
65 static void set_level(Level new_level);
66 static Level get_level();
67 static void set_logfile(const std::string& filename);
68 static void enable_console(bool enabled);
69
70 static void debug(const std::string& message);
71 static void info(const std::string& message);
72 static void warning(const std::string& message);
73 static void error(const std::string& message);
74 static void critical(const std::string& message);
75 static void fatal(const std::string& message);
76
77 // Helper to convert pointer to string for logging
78 static std::string ptrToString(const void* ptr);
79
80 // Helper to convert uint16_t to hex string for logging
81 static std::string uint16ToHex(uint16_t val);
82
83 // Templated helper to convert unsigned integral types to hex string
84 template <typename T>
85 static std::string to_hex(T val);
86
87 // Helper for vector stats (if it's part of public API, otherwise private)
88 static void log_vector_stats(const std::string& name, const std::vector<float>& v, int n_show = 5);
89 static void log_vector_stats_int8(const std::string& name, const std::vector<int8_t>& v, int n_show = 5);
90
91 private:
93 static std::ofstream log_file_stream_;
94 static std::string log_file_path_;
95 static bool console_enabled_;
97
98 static void log_internal(Level level, const std::string& message);
99 static std::string level_to_string(Level level);
101};
Static logging class for application-wide logging.
Definition logger.h:52
static void log_vector_stats(const std::string &name, const std::vector< float > &v, int n_show=5)
Definition logger.cpp:160
static bool log_file_truncated_
Definition logger.h:96
static std::string log_file_path_
Definition logger.h:94
static void debug(const std::string &message)
Definition logger.cpp:131
static std::string to_hex(T val)
Definition logger.cpp:233
static void log_internal(Level level, const std::string &message)
Definition logger.cpp:101
static void warning(const std::string &message)
Definition logger.cpp:139
static std::string ptrToString(const void *ptr)
Definition logger.cpp:225
static void ensure_logfile_open_and_truncated()
Definition logger.cpp:71
static bool console_enabled_
Definition logger.h:95
static void set_level(Level new_level)
Definition logger.cpp:34
static void enable_console(bool enabled)
Definition logger.cpp:54
static std::string level_to_string(Level level)
Definition logger.cpp:59
static Level current_level_
Definition logger.h:92
static Level get_level()
Definition logger.cpp:39
Level
Definition logger.h:56
static std::string uint16ToHex(uint16_t val)
Definition logger.cpp:242
static std::ofstream log_file_stream_
Definition logger.h:93
static void info(const std::string &message)
Definition logger.cpp:135
static void error(const std::string &message)
Definition logger.cpp:143
static void fatal(const std::string &message)
Definition logger.cpp:151
static void log_vector_stats_int8(const std::string &name, const std::vector< int8_t > &v, int n_show=5)
Definition logger.cpp:195
static void critical(const std::string &message)
Definition logger.cpp:147
static void set_logfile(const std::string &filename)
Definition logger.cpp:44
std::vector< float > v
const char * name
size_t j