You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -435,25 +435,145 @@ The usage is `journalctl [OPTIONS...] [MATCHES...]`.
435
435
436
436
Because there are many options, the unordered list is used to explain:
437
437
438
-
*`-u` - Specify 'unit', which can be used multiple times in a single line command. Such as `journalctl -u crond.service -u sshd.service`
439
-
*`--system`
440
-
*`--user`
441
-
* ``
442
-
* ``
443
-
* ``
444
-
* ``
445
-
* ``
446
-
* ``
447
-
* ``
448
-
* ``
449
-
* ``
450
-
* ``
451
-
* ``
452
-
* ``
453
-
* ``
454
-
* ``
455
-
* ``
456
-
* ``
457
-
* ``
458
-
* ``
459
-
* ``
438
+
*`-u` - Specify 'unit', which can be used multiple times in a single line command. For example `journalctl -u crond.service -u sshd.service`
439
+
*`--system` - Show messages from system services and the kernel
440
+
*`--user` - Show messages from service of current user
441
+
*`-k` - Show kernel message log from the current boot
442
+
*`--since=DATA` or `-S` - Show entries not older than the specified date. The format of the date is "YYYY-MM-DD HH:MM:SS". For example `journalctl --since="2025-04-24 14:00:30`
443
+
*`--until=DATA` or `-U` - Show entries not newer than the specified date. The format of the date is "YYYY-MM-DD HH:MM:SS". For example `journalctl --since="2025-04-01 05:00:10" --until="2025-04-05 18:00:30"`
444
+
*`--list-boots` - Show terse information about recorded boots
445
+
*`-n N` - Controls the number of entries output. If "N" is not specified, the default value is 10
446
+
*`-p PRIORITY` - Specify priority or range of priorities. If you specify a single log priority keyword, this priority and entries higher than this priority will be displayed. For example `journalctl -p 3` or `journalctl -p err` Equivalent to `journalctl -p 0..3` or `journalctl -p emerg..err`
447
+
*`-b` - Query the log since the current boot ID was started. Do not confuse the boot ID with the index number of the kernel boot.
448
+
*`-f` - Dynamic query log, similar to the `tail -f` command
449
+
*`-x` - Add message explanations where available
450
+
*`-e` - Jump to the end page of the log, often used with the `-x` option
451
+
*`-r` - Reverse Log.
452
+
*`--disk-usage` - Display the disk space occupied by log files
453
+
*`--rotate` - Request immediate rotation of the journal files
454
+
*`--vacuum-size=BYTES` - Reduces the log file to the specified size. The old log content will be deleted gradually until the specified file size is met. The supported size suffixes are K, M, G, T
455
+
*`--vacuum-time=TIME` - You can delete old log records by specifying a time point, that is, log records earlier than that time point will be deleted. The supported time suffixes are s, m, h, days, months, weeks, years
456
+
*`--vacuum-files=INT` - How many log files are reserved
457
+
*`-N` - List all field names currently used. Users can use the "FIELD=VALUE" method to match related content. For example `journalctl _SYSTEMD_UNIT=sshd.service`.
458
+
*`-g` or `-grep=PATTERN`- Match log content through pattern, and support regular expression. By default, if PATTERN is all lowercase, matching log content is not case sensitive. You can adjust case sensitivity through the `--case-sensitive` option
459
+
*`--case-sensitive=[BOOLEAN]` - Adjust whether it is case sensitive.
460
+
*`-o` or `--output=STRING` - Change the output mode of journalctl. A STRING can be short, short-precise, short-iso, short-iso-precise, short-full, short-monotonic, short-unix, verbose, export, json, json-pretty, json-sse, cat, and with-unit
461
+
*`-q` or `--quiet` - Quiet output
462
+
*`--sync` - Synchronize unwritten journal messages to disk
463
+
464
+
### /etc/systemd/journald.conf
465
+
466
+
```bash
467
+
Shell > cat /etc/systemd/journald.conf
468
+
[Journal]
469
+
#Storage=auto
470
+
#Compress=yes
471
+
#Seal=yes
472
+
#SplitMode=uid
473
+
#SyncIntervalSec=5m
474
+
#RateLimitIntervalSec=30s
475
+
#RateLimitBurst=10000
476
+
#SystemMaxUse=
477
+
#SystemKeepFree=
478
+
#SystemMaxFileSize=
479
+
#SystemMaxFiles=100
480
+
#RuntimeMaxUse=
481
+
#RuntimeKeepFree=
482
+
#RuntimeMaxFileSize=
483
+
#RuntimeMaxFiles=100
484
+
#MaxRetentionSec=
485
+
#MaxFileSec=1month
486
+
#ForwardToSyslog=no
487
+
#ForwardToKMsg=no
488
+
#ForwardToConsole=no
489
+
#ForwardToWall=yes
490
+
#TTYPath=/dev/console
491
+
#MaxLevelStore=debug
492
+
#MaxLevelSyslog=debug
493
+
#MaxLevelKMsg=notice
494
+
#MaxLevelConsole=info
495
+
#MaxLevelWall=emerg
496
+
#LineMax=48K
497
+
```
498
+
499
+
Like the configuration files of other 'systemd' components, "[]" is used to contain the title, and below the title are specific key-value pairs. Please pay attention! There is no space on either side of the equal sign in the key-value pair. For the complete configuration manual page, refer to `man 5 journald.conf`
500
+
501
+
*`Storage=` - Controls the location of journald's data store. The default value is auto.
502
+
503
+
* volatile - Store the log data in memory, that is, the temporary file located in the **/run/log/journal/** directory.
504
+
* persistent - Store the log data in the **/var/log/journal/** directory, which needs to be created manually by the user. If this directory is not writable, log data will be written to the **/run/log/journal/** directory
505
+
* auto - Similar to persistent
506
+
* none - Do not save any logs, but the logs forwarded to other "targets" will not be affected
507
+
508
+
*`Compress=` - Whether to enable the compression function. The default value is yes.
509
+
*`Seal=` - Whether to use FSS (Forward Secure Sealing) to protect log entries from malicious tampering. The default value is yes.
510
+
*`SplitMode=` - Define the basis for splitting log files. The precondition (Storage=persistent) must be met before it takes effect. The default value is uid.
511
+
*`SyncIntervalSec=` - Define the time interval for synchronizing the log data in memory to the disk. Please note! This only takes effect for err, warning, notice, info, and debug log priorities. Other log priorities are immediately synchronized to disk. The default value is 5m.
512
+
*`RateLimitIntervalSec=` - Define the time interval for log generation frequency. The default value is 30s.
513
+
*`RateLimitBurst=` - The maximum number of entries generated by the log in a given time interval. The default value is 10000. If the log entries are greater than 10000 within a given time interval, the redundant logs will be discarded and new log entries will not be generated until the next time interval is reached.
514
+
*`SystemMaxUse=` - Controls the total size of all log files in the **/var/log/journal/** directory.
515
+
*`SystemKeepFree=` - Controls how much disk space should be reserved in the **/var/log/journal/** directory. Based on 1024, suffixes include K, M, G, T, P, E
516
+
*`SystemMaxFileSize=` - Limit the size of a single file in the **/var/log/journal/** directory. If the size exceeds the specified size, log rotation will occur
517
+
*`SystemMaxFiles=` - Specify how many files to keep in the **/var/log/journal/** directory. When the defined number is exceeded, the oldest log file will be deleted.
518
+
*`RuntimeMaxUse=` - Controls the total size of log data in the **/run/log/journal/** directory.
519
+
*`RuntimeKeepFree=` - Controls how much space to reserve in the **/run/log/journal/** directory.
520
+
*`RuntimeMaxFileSize=` - Controls the size of a single log file in the **/run/log/journal/** directory. When the specified size is reached, log rotation will occur.
521
+
*`RuntimeMaxFiles=` - How many files of logs need to be kept in the **/run/log/journal/** directory.
522
+
*`MaxRetentionSec=` - Define the retention time for log files, and if it exceeds the defined time, the old log files will be deleted. A value of 0 indicates that the function is turned off. The value suffix has year, month,week,day,h,m
523
+
*`MaxFileSec=` - Time based log rotation. Since file size based polling (`SystemMaxFileSize` and `RuntimeMaxFileSize`) already exists, time based log polling is usually not required. Set it to 0 to disable this function.
524
+
*`ForwardToSyslog=` -Whether to forward the collected log messages to the traditional syslog daemon. The default value is no.
525
+
*`ForwardToKMsg=` - Whether to forward the received log message to kmsg. The default value is no.
526
+
*`ForwardToConsole=` - Whether to forward the received log messages to the system console. The default value is no. If it is set to yes, you also need to configure `TTYPath`
527
+
*`ForwardToWall=` - Whether to send the received log message as a warning message to all logged in users. The default value is yes.
528
+
*`TTYPath=` - Specify the path of the console. `ForwardToConsole=yes` is required. The default value is /dev/console
529
+
*`MaxLevelStore=` - Set the maximum log level recorded to the log file. The default value is debug
530
+
*`MaxLevelSyslog=` - Set the maximum log level forwarded to the traditional syslog daemon. The default value is debug
531
+
*`MaxLevelKMsg=` - Set the maximum log level forwarded to kmsg. The default value is notice
532
+
*`MaxLevelConsole=` - Set the maximum log level forwarded to the system console. The default value is info
533
+
*`MaxLevelWall=` - Set the maximum log level sent to all logged in users. The default value is emerg
534
+
*`LineMax=` - The maximum allowable length (bytes) of each log record when converting the log stream to log records. With 1024 as the base, the suffix can be K, M, G, T. The default value is 48K
535
+
536
+
## Other instructions
537
+
538
+
If you do not change any configuration in **/etc/systemd/journald.conf**, `rsyslog` and `journald` can coexist without affecting each other.
539
+
540
+
```bash
541
+
Shell > cat /etc/rsyslog.conf
542
+
...
543
+
#### MODULES ####
544
+
545
+
module(load="imuxsock"# provides support for local system logging (e.g. via logger command)
546
+
SysSock.Use="off") # Turn off message reception via local log socket;
547
+
# local messages are retrieved through imjournal now.
548
+
module(load="imjournal"# provides access to the systemd journal
549
+
UsePid="system"# PID nummber is retrieved as the ID of the process the journal entry originates from
550
+
StateFile="imjournal.state") # File to store the position in the journal
551
+
#module(load="imklog") # reads kernel messages (the same are read from journald)
`journald` will forward the obtained log data to the socket `/run/systemd/journal/syslog` to facilitate the use of traditional log services (rsyslog, syslog-ng). However, we can learn from the configuration file that `rsyslog` does not collect logs from `journald` using sockets, but integrates through the input module (imjournal).
557
+
558
+
**Q: Can the operating system not use `journald` for logging?**
559
+
560
+
Yes. By default, `rsyslog` and `journald` can coexist in the operating system without affecting each other. For some performance oriented usage scenarios (such as data throughput and memory consumption), coexistence is not the best choice. You can make rsyslog run only in socket mode, which helps improve performance and record all logs in plain text. However, if you need structured logs, this change is not suitable. The relevant steps are as follows:
0 commit comments