Skip to content

Commit 4dcd47d

Browse files
authored
logs : fix mingw-like builds (fixes #2898) (#2911)
* fix mingw-like builds * formatting * make LOG_COMPAT easier to override and extend * simplify win detection * fix for #2940
1 parent 18705a3 commit 4dcd47d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ ifdef LLAMA_SERVER_VERBOSE
7979
CXXFLAGS += -DSERVER_VERBOSE=$(LLAMA_SERVER_VERBOSE)
8080
endif
8181

82+
ifdef LLAMA_DISABLE_LOGS
83+
CFLAGS += -DLOG_DISABLE_LOGS
84+
CXXFLAGS += -DLOG_DISABLE_LOGS
85+
endif # LLAMA_DISABLE_LOGS
86+
8287
# warnings
8388
CFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith \
8489
-Wmissing-prototypes -Werror=implicit-int
@@ -343,11 +348,6 @@ k_quants.o: k_quants.c k_quants.h
343348
$(CC) $(CFLAGS) -c $< -o $@
344349
endif # LLAMA_NO_K_QUANTS
345350

346-
ifdef LLAMA_DISABLE_LOGS
347-
CFLAGS += -DLOG_DISABLE_LOGS
348-
CXXFLAGS += -DLOG_DISABLE_LOGS
349-
endif # LLAMA_DISABLE_LOGS
350-
351351
#
352352
# Print build information
353353
#

common/log.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ inline std::string log_filename_generator_impl(const std::string & log_file_base
154154
// #include "log.h"
155155
//
156156
#ifndef LOG_NO_TIMESTAMPS
157-
#ifndef _WIN32
157+
#ifndef _MSC_VER
158158
#define LOG_TIMESTAMP_FMT "[%" PRIu64 "] "
159159
#define LOG_TIMESTAMP_VAL , (std::chrono::duration_cast<std::chrono::duration<std::uint64_t>>(std::chrono::system_clock::now().time_since_epoch())).count()
160160
#else
@@ -167,7 +167,7 @@ inline std::string log_filename_generator_impl(const std::string & log_file_base
167167
#endif
168168

169169
#ifdef LOG_TEE_TIMESTAMPS
170-
#ifndef _WIN32
170+
#ifndef _MSC_VER
171171
#define LOG_TEE_TIMESTAMP_FMT "[%" PRIu64 "] "
172172
#define LOG_TEE_TIMESTAMP_VAL , (std::chrono::duration_cast<std::chrono::duration<std::uint64_t>>(std::chrono::system_clock::now().time_since_epoch())).count()
173173
#else
@@ -187,7 +187,7 @@ inline std::string log_filename_generator_impl(const std::string & log_file_base
187187
// #include "log.h"
188188
//
189189
#ifndef LOG_NO_FILE_LINE_FUNCTION
190-
#ifndef _WIN32
190+
#ifndef _MSC_VER
191191
#define LOG_FLF_FMT "[%24s:%5d][%24s] "
192192
#define LOG_FLF_VAL , __FILE__, __LINE__, __FUNCTION__
193193
#else
@@ -200,7 +200,7 @@ inline std::string log_filename_generator_impl(const std::string & log_file_base
200200
#endif
201201

202202
#ifdef LOG_TEE_FILE_LINE_FUNCTION
203-
#ifndef _WIN32
203+
#ifndef _MSC_VER
204204
#define LOG_TEE_FLF_FMT "[%24s:%5d][%24s] "
205205
#define LOG_TEE_FLF_VAL , __FILE__, __LINE__, __FUNCTION__
206206
#else
@@ -224,7 +224,7 @@ enum LogTriState
224224
// INTERNAL, DO NOT USE
225225
// USE LOG() INSTEAD
226226
//
227-
#ifndef _WIN32
227+
#ifndef _MSC_VER
228228
#define LOG_IMPL(str, ...) \
229229
{ \
230230
if (LOG_TARGET != nullptr) \
@@ -247,7 +247,7 @@ enum LogTriState
247247
// INTERNAL, DO NOT USE
248248
// USE LOG_TEE() INSTEAD
249249
//
250-
#ifndef _WIN32
250+
#ifndef _MSC_VER
251251
#define LOG_TEE_IMPL(str, ...) \
252252
{ \
253253
if (LOG_TARGET != nullptr) \
@@ -284,7 +284,7 @@ enum LogTriState
284284
// Main LOG macro.
285285
// behaves like printf, and supports arguments the exact same way.
286286
//
287-
#ifndef _WIN32
287+
#ifndef _MSC_VER
288288
#define LOG(...) LOG_IMPL(__VA_ARGS__, "")
289289
#else
290290
#define LOG(str, ...) LOG_IMPL("%s" str, "", __VA_ARGS__, "")
@@ -298,14 +298,14 @@ enum LogTriState
298298
// Secondary target can be changed just like LOG_TARGET
299299
// by defining LOG_TEE_TARGET
300300
//
301-
#ifndef _WIN32
301+
#ifndef _MSC_VER
302302
#define LOG_TEE(...) LOG_TEE_IMPL(__VA_ARGS__, "")
303303
#else
304304
#define LOG_TEE(str, ...) LOG_TEE_IMPL("%s" str, "", __VA_ARGS__, "")
305305
#endif
306306

307307
// LOG macro variants with auto endline.
308-
#ifndef _WIN32
308+
#ifndef _MSC_VER
309309
#define LOGLN(...) LOG_IMPL(__VA_ARGS__, "\n")
310310
#define LOG_TEELN(...) LOG_TEE_IMPL(__VA_ARGS__, "\n")
311311
#else
@@ -461,7 +461,7 @@ inline void log_test()
461461
LOG("13 Hello World this time in yet new file?\n")
462462
log_set_target(log_filename_generator("llama_autonamed", "log"));
463463
LOG("14 Hello World in log with generated filename!\n")
464-
#ifdef _WIN32
464+
#ifdef _MSC_VER
465465
LOG_TEE("15 Hello msvc TEE without arguments\n")
466466
LOG_TEE("16 Hello msvc TEE with (%d)(%s) arguments\n", 1, "test")
467467
LOG_TEELN("17 Hello msvc TEELN without arguments\n")

0 commit comments

Comments
 (0)