Skip to content

Commit 2681638

Browse files
committed
common : reimplement the logger (wip) [no ci]
1 parent 5bb2c5d commit 2681638

File tree

14 files changed

+512
-891
lines changed

14 files changed

+512
-891
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ OBJ_LLAMA = \
926926
OBJ_COMMON = \
927927
common/common.o \
928928
common/arg.o \
929+
common/log.o \
929930
common/console.o \
930931
common/ngram-cache.o \
931932
common/sampling.o \
@@ -1163,6 +1164,11 @@ common/arg.o: \
11631164
common/arg.h
11641165
$(CXX) $(CXXFLAGS) -c $< -o $@
11651166

1167+
common/log.o: \
1168+
common/log.cpp \
1169+
common/log.h
1170+
$(CXX) $(CXXFLAGS) -c $< -o $@
1171+
11661172
common/sampling.o: \
11671173
common/sampling.cpp \
11681174
common/sampling.h \

common/CMakeLists.txt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,23 @@ endif()
5151
set(TARGET common)
5252

5353
add_library(${TARGET} STATIC
54+
arg.cpp
55+
arg.h
5456
base64.hpp
55-
common.h
5657
common.cpp
57-
arg.h
58-
arg.cpp
59-
sampling.h
60-
sampling.cpp
61-
console.h
58+
common.h
6259
console.cpp
63-
json.hpp
60+
console.h
6461
json-schema-to-grammar.cpp
65-
train.h
66-
train.cpp
67-
ngram-cache.h
62+
json.hpp
63+
log.cpp
64+
log.h
6865
ngram-cache.cpp
66+
ngram-cache.h
67+
sampling.cpp
68+
sampling.h
69+
train.cpp
70+
train.h
6971
)
7072

7173
if (BUILD_SHARED_LIBS)

common/arg.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#include "arg.h"
22

3+
#include "log.h"
34
#include "sampling.h"
45

56
#include <algorithm>
6-
#include <string>
7-
#include <vector>
8-
#include <set>
7+
#include <climits>
8+
#include <cstdarg>
99
#include <fstream>
1010
#include <regex>
11-
#include <cstdarg>
12-
#include <climits>
11+
#include <set>
12+
#include <string>
13+
#include <thread>
14+
#include <vector>
1315

1416
#include "json-schema-to-grammar.h"
1517

@@ -1950,35 +1952,19 @@ gpt_params_context gpt_params_parser_init(gpt_params & params, llama_example ex,
19501952
).set_examples({LLAMA_EXAMPLE_BENCH}));
19511953
#ifndef LOG_DISABLE_LOGS
19521954
// TODO: make this looks less weird
1953-
add_opt(llama_arg(
1954-
{"--log-test"},
1955-
"Log test",
1956-
[](gpt_params &) { log_param_single_parse("--log-test"); }
1957-
));
19581955
add_opt(llama_arg(
19591956
{"--log-disable"},
19601957
"Log disable",
1961-
[](gpt_params &) { log_param_single_parse("--log-disable"); }
1962-
));
1963-
add_opt(llama_arg(
1964-
{"--log-enable"},
1965-
"Log enable",
1966-
[](gpt_params &) { log_param_single_parse("--log-enable"); }
1967-
));
1968-
add_opt(llama_arg(
1969-
{"--log-new"},
1970-
"Log new",
1971-
[](gpt_params &) { log_param_single_parse("--log-new"); }
1972-
));
1973-
add_opt(llama_arg(
1974-
{"--log-append"},
1975-
"Log append",
1976-
[](gpt_params &) { log_param_single_parse("--log-append"); }
1958+
[](gpt_params &) {
1959+
gpt_log_pause(gpt_log_main());
1960+
}
19771961
));
19781962
add_opt(llama_arg(
19791963
{"--log-file"}, "FNAME",
1980-
"Log file",
1981-
[](gpt_params &, const std::string & value) { log_param_pair_parse(false, "--log-file", value); }
1964+
"Log to file",
1965+
[](gpt_params &, const std::string & value) {
1966+
gpt_log_set_file(gpt_log_main(), value.c_str());
1967+
}
19821968
));
19831969
#endif // LOG_DISABLE_LOGS
19841970

common/common.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#endif
44

55
#include "common.h"
6+
#include "log.h"
67
// Change JSON_ASSERT from assert() to GGML_ASSERT:
78
#define JSON_ASSERT GGML_ASSERT
89
#include "json.hpp"
@@ -25,6 +26,7 @@
2526
#include <unordered_map>
2627
#include <unordered_set>
2728
#include <vector>
29+
#include <thread>
2830

2931
#if defined(__APPLE__) && defined(__MACH__)
3032
#include <sys/types.h>
@@ -48,7 +50,6 @@
4850
#if defined(LLAMA_USE_CURL)
4951
#include <curl/curl.h>
5052
#include <curl/easy.h>
51-
#include <thread>
5253
#include <future>
5354
#endif
5455

common/common.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
#include "llama.h"
66

7-
#define LOG_NO_FILE_LINE_FUNCTION
8-
#include "log.h"
9-
107
#include <string>
118
#include <vector>
9+
#include <sstream>
1210

1311
#ifdef _WIN32
1412
#define DIRECTORY_SEPARATOR '\\'

0 commit comments

Comments
 (0)