Skip to content

Commit 5f20850

Browse files
authored
logging cleanup: remove filter in streambuf; use key_trace (#288)
1 parent 698e6e3 commit 5f20850

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
# Don't log key on any CI artifact.
7575
cmake -B build/${{ matrix.arch }} -G Ninja \
7676
-DCMAKE_Swift_COMPILER=`which swiftc` \
77-
-DVERBOSE_LOGGING=OFF \
77+
-DKEY_LOGGING=OFF \
7878
-DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} \
7979
-DCMAKE_BUILD_TYPE=${{ matrix.type }}
8080
cmake --build build/${{ matrix.arch }}

src/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ target_include_directories(Fcitx5Objs PRIVATE
2525
"${PROJECT_SOURCE_DIR}/fcitx5/src/im/keyboard"
2626
)
2727

28-
option(VERBOSE_LOGGING "Enable verbose logging" ON)
29-
if(VERBOSE_LOGGING)
30-
target_compile_definitions(Fcitx5Objs PRIVATE VERBOSE_LOGGING)
28+
# This should be disabled in CI even for debug build.
29+
option(KEY_LOGGING "Enable key logging" ON)
30+
if(KEY_LOGGING)
31+
target_compile_definitions(Fcitx5Objs PRIVATE KEY_LOGGING)
3132
endif()
3233

3334
target_link_libraries(Fcitx5Objs

src/fcitx.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,15 @@ void Fcitx::setupLog() {
112112
static native_streambuf log_streambuf;
113113
static std::ostream stream(&log_streambuf);
114114
fcitx::Log::setLogStream(stream);
115-
#ifdef VERBOSE_LOGGING
116-
fcitx::Log::setLogRule("*=5,notimedate");
115+
#ifdef NDEBUG
116+
std::string logRule = "*=4";
117117
#else
118-
fcitx::Log::setLogRule("*=4,notimedate");
118+
std::string logRule = "*=5";
119119
#endif
120+
#ifndef KEY_LOGGING
121+
logRule += ",key_trace=0";
122+
#endif
123+
fcitx::Log::setLogRule(logRule + ",notimedate");
120124
}
121125

122126
void Fcitx::setupEnv() {

src/nativestreambuf.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* SPDX-License-Identifier: GPL-3.0-only
66
* SPDX-FileCopyrightText: Copyright 2023 Qijia Liu
77
*/
8-
#ifndef FCITX5_MACOS_NATIVESTREAMBUF_H
9-
#define FCITX5_MACOS_NATIVESTREAMBUF_H
8+
#pragma once
109

1110
#include <array>
1211
#include <iostream>
@@ -104,16 +103,10 @@ class native_streambuf : public std::streambuf {
104103
}
105104

106105
void write_log(const char_type *text) const {
107-
#ifdef NDEBUG
108-
if (prio != OS_LOG_TYPE_DEBUG) {
109-
std::cerr << text;
110-
}
111-
#else
106+
#ifndef NDEBUG
112107
os_log_with_type(logger, prio, "%{public}s",
113108
text + (should_offset ? 1 : 0));
114-
std::cerr << text;
115109
#endif
110+
std::cerr << text;
116111
}
117112
};
118-
119-
#endif // FCITX5_MACOS_NATIVESTREAMBUF_H

0 commit comments

Comments
 (0)