log in linux

log in linux

Due to the particularity of the kernel, we cannot use conventional methods to view kernel information. Several methods are described below.

1 printk() prints kernel messages.

2 The daemon (daemon process) that manages kernel memory
The most popular logger in the Linux system is Sysklogd. The Sysklogd logger consists of two daemon processes (klogd syslogd) and a configuration file (syslog.conf). klogd does not use configuration files, it is responsible for intercepting kernel messages, it can be used independently or as a client of syslogd. By default, syslogd uses /etc/syslog.conf as the configuration file, which is responsible for intercepting application messages, and can also intercept kernel messages forwarded to it by klogd. Support for internet/unix domain sockets allows these two tools to be used for local and remote logging.

3 dmesg command
dmesg is used to display the boot information, and the kernel will store the boot information in the ring buffer. If you don't have time to check the information when you start it, you can use dmesg to check it. The boot information is also stored in the /var/log directory, in a file named dmesg.

  more   /var/log/dmesg

4 /proc/kmsg
This file is used to retrieve kernel messages generated with printk. Only one process with superuser privileges can read this file at any time. These messages can also be retrieved with the syslog system call. These messages are usually retrieved using the tool dmesg or the daemon klogd.
The log of /proc/kmsg is a simple kernel log
. When booting, part of the log will pass through the serial port to the serial port log, and it will be determined by the printk level.
All others will go to /proc/kmsg, which is a cache ring buffer

5. syslogd This is when the systemd process starts, the log of the application layer will be written into a memory cache,

Both logread and logcat read logs from this memory cache, which can be configured through LOGI, LOGD log level

Generally, the log in this cache will be written into a file to prevent loss, but currently Quyuan has not done so, because this cache has 10m, which is enough

insert image description here
For the description of syslogd klogd,
please refer to:
https://blog.csdn.net/weixin_30362233/article/details/98494787

Guess you like

Origin blog.csdn.net/weixin_41903639/article/details/129321853