Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENABLE_LOGGING 不应该默认开启 #254

Closed
OwenChia opened this issue Feb 23, 2019 · 14 comments
Closed

ENABLE_LOGGING 不应该默认开启 #254

OwenChia opened this issue Feb 23, 2019 · 14 comments

Comments

@OwenChia
Copy link

OwenChia commented Feb 23, 2019

问题描述:
意外发现 /tmp 下有一个很大(200M+)的日志文件 /tmp/rime.fcitx-rime.INFO,打开看了下里面存有输入法输入的相关信息。
简单地浏览了下源码,似乎是因为 ENABLE_LOGGING 默认开启,发行版维护人员在打包的时候没有关掉导致。
因为目前不确定都有哪些发行版受影响,所以选择上报上游,希望上游能将这个选项的默认值改为 OFF。
另经过简单搜索,近 4 年前 fcitx-rime 项目曾有人报告过 “/tmp目录下面有局大的info文件”,但似乎并没有被解决。

目前已确定受影响的发行版:

建议:
输入信息被记录到一个文件中是一个安全隐患,可以造成这种隐患的选项不应该默认开启。

@nameoverflow
Copy link
Member

INFO 级的 logging 默认是关闭的吧?

@OwenChia
Copy link
Author

INFO 级的 logging 默认是关闭的吧?

我对 c/cpp 不熟悉,只是粗略的浏览了下,没有找到设置 logging 级别的地方,是通过配置文件设置的还是?
我本地环境是全新安装的 fcitx5 fcitx5-rime librime,未对日志级别进行过设置,发现存在那个日志文件后以日志中的关键字在相关的项目中搜索定位到这里的。

因日志已删除,无法提供,日志内容大致如下:

...
I0223 xx:xx:xx.xxxxxx 10022 engine.cc:99] process key: space
...

FYI:
add_definitions(-DRIME_ENABLE_LOGGING)
#ifdef RIME_ENABLE_LOGGING
DLOG
DLOG(INFO) << "process key: " << key_event;

@nameoverflow
Copy link
Member

nameoverflow commented Feb 23, 2019

no_logging.h 下的定义是使所有的 logging 都不生效。
Glog 中的 DLOG 是 debug 宏,在 release 下是不输出。
其它平台也没有在 release 下输出 debug 日志的问题,虽然不清楚 gentoo 的包,但是在别的发行版使用默认 build 产生的 release 库也没有过问题。
建议反馈发行版。

@OwenChia
Copy link
Author

OwenChia commented Feb 23, 2019

no_logging.h 下的定义是使所有的 logging 都不生效。

这个我看懂了,我会认为关掉那个选项就可以不输出也是因为这个文件

Glog 中的 DLOG 是 debug 宏,在 release 下是不输出的。

是我太草率了,抱歉!
我再去看看是不是我这里 glog 的问题。

@heyrict
Copy link

heyrict commented May 7, 2020

确认 Archlinux 发行版最新版本仍存在该问题。原因很有可能是 DLOG 被使用(详见输出)。

pacman -Qi librime

Name            : librime
Version         : 1:1.5.3-6
Description     : Rime input method engine
Architecture    : x86_64
URL             : https://github.com/rime/librime
Licenses        : GPL3
Groups          : None
Provides        : None
Depends On      : boost-libs  opencc  yaml-cpp  leveldb  librime-data  google-glog  marisa
Optional Deps   : None
Required By     : fcitx-rime
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 2.75 MiB
Packager        : Felix Yan <felixonmars@archlinux.org>
Build Date      : Sat 14 Mar 2020 08:59:44 PM CST
Install Date    : Fri 01 May 2020 11:11:32 PM CST
Install Reason  : Installed as a dependency for another package
Install Script  : No
Validated By    : Signature

因日志文件太大,仅上传部分计数

cat rime.fcitx-rime.INFO | cut -d" " -f 4 | sort | uniq -c | sort -n | tail -n 20

     74 poet.cc:164]
     84 config_component.cc:104]
     89 engine.cc:99]
    101 syllabifier.cc:187]
    126 script_translator.cc:505]
    131 script_translator.cc:491]
    140 poet.cc:152]
    154 dictionary.cc:85]
    177 config_data.cc:223]
    245 syllabifier.cc:52]
    316 syllabifier.cc:138]
    316 syllabifier.cc:86]
    701 user_dictionary.cc:212]
   1965 translator_commons.cc:105]
   4664 user_dictionary.cc:243]
   4664 user_dictionary.cc:492]
   4664 user_dictionary.cc:72]
  36495 user_dictionary.cc:215]
  36495 user_dictionary.cc:236]
  36495 user_dictionary.cc:238]

@heyrict
Copy link

heyrict commented May 7, 2020

正在准备向Archlinux 发行版提交反馈。因为我不太熟悉这个项目

请问是否将 CMakeLists.txt 中的

option(ENABLE_LOGGING "Enable logging with google-glog library" ON)

更改为

option(ENABLE_LOGGING "Enable logging with google-glog library" OFF)

可以解决?谢谢

@heyrict
Copy link

heyrict commented May 7, 2020

已找到暂时的解决方案。参照 Glog 文档:https://hpc.nih.gov/development/glog.html#flags

以使用 fcitx 为例:

# set log level to WARNING
GLOG_minloglevel=2 fcitx &

@lotem
Copy link
Member

lotem commented May 7, 2020

log level還在其次。INFO級別的日誌對用家定位問題也有幫助。
本案的疑點在於Release build不應該輸出DLOG。這部分日誌是開發者調試用的,如果在Release build打開,可能洩漏敏感內容。

@heyrict
Copy link

heyrict commented May 7, 2020

@lotem 谢谢回复,我也是刚刚发现这个问题,现在在查找 C++ 关于 Debug 与 Release build 的相关内容。

这是 archlinux 关于打包 librime 的文件,不知道是否与本案相关?

https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/librime


谢谢,已发现问题所在。原因是 Archlinux 发行版未使用 Release build.

解决方法是将 PKGBUILD 中

cmake . -Bbuild

更改为

cmake . -Bbuild -DCMAKE_BUILD_TYPE=Release

@lotem
Copy link
Member

lotem commented May 8, 2020

I read the discussion in https://bugs.archlinux.org/task/66584#comment189187
I have some finding that can answer some of the questions there.
@heyrict Can you help deliver my message?

For your reference:
Gentoo package uses the cmake flag -DCMAKE_BUILD_TYPE=Gentoo by default. That's similar to our situation, where CMAKE_BUILD_TYPE is None.
#316 (comment)

The differences among those CMAKE_BUILD_TYPE options that affect logging in librime is the -DNDEBUG macro, which is only defined by -DCMAKE_BUILD_TYPE=Release.
I think that makes the point, and answers Antonio's question:
strictly speaking, librime doesn't create a "debug" build with unspecified CMAKE_BUILD_TYPE; it's only the debug logs depend on that macro definition.

The fix in Gentoo actually supports a debug build variant corresponding to USE flag debug. That I believe is a non-goal of the PKGBUILD for Arch Linux.

In the comments, Doug mentioned "release tarball". I'm sure everyone in the thread is aware that a release tarball, in the context of open-source software, doesn't refer to artifacts of a release build, but a source tarball that can be used with multiple build configurations.
librime uses CMake to build its sources. I also added a wrapper Makefile which provides a default release target calling cmake specifically with -DCMAKE_BUILD_TYPE=Release, so that the conventional make && make install pattern creates a release build. (see instructions in README)
Somehow, the Arch Linux packager chose to invoke cmake directly in the PKGBUILD instead of calling the wrapper Makefile. This might have the benifit of easily customizing build options for the platform. But that's where the PKGBUILD's resulting compiler options begin to differ from that of a "release" build from the tarball.

@lotem lotem closed this as completed May 8, 2020
@heyrict
Copy link

heyrict commented May 9, 2020

@lotem Much thanks for your comments! The bug is now fixed in archlinux in librime 1:1.5.3-7.

@c02y
Copy link

c02y commented Apr 10, 2023

Archlinux librime 1:1.8.5-1 still has such issues, FYI: fcitx5-rime, I don't have the log file size problem yet since I just start to use rime, but my problem is there are so many unnecessary log files in /tmp.

image

@X1aomu
Copy link

X1aomu commented Apr 11, 2023

Archlinux librime 1:1.8.5-1 still has such issues, FYI: fcitx5-rime, I don't have the log file size problem yet since I just start to use rime, but my problem is there are so many unnecessary log files in /tmp.

image

FYI, just feel free to mount /tmp as tmpfs .

@c02y
Copy link

c02y commented Apr 11, 2023

Archlinux librime 1:1.8.5-1 still has such issues, FYI: fcitx5-rime, I don't have the log file size problem yet since I just start to use rime, but my problem is there are so many unnecessary log files in /tmp.
image

FYI, just feel free to mount /tmp as tmpfs .

It's already tmpfs, by default, /tmp is cleaned once I reboot.
image

Those files are all generated after I reboot a few hours ago, as you see from the date, maybe because I restart/depoly fcitx5/rime multiple times since I was trying to modify the config of rime.

BUT normally I don't need all those INFO/WARNING logs at all to fill the /tmp directory in the first place unless I turn the log on, is there any variable that I can turn it on or off in rime config file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants