tech:systemd_journalctl_journal_logs
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| tech:systemd_journalctl_journal_logs [2025/03/24 15:06] – créée - modification externe 127.0.0.1 | tech:systemd_journalctl_journal_logs [2026/06/30 21:46] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Systemd journalctl journal logs | ||
| + | |||
| + | Voir https:// | ||
| + | |||
| + | |||
| + | ## Requête sur les logs, chercher et trouver | ||
| + | |||
| + | Trouver les logs entres deux dates | ||
| + | |||
| + | Voir [[find_entre_deux_dates]] | ||
| + | |||
| + | ~~~bash | ||
| + | journalctl --since " | ||
| + | journalctl --since yesterday -p err | ||
| + | ~~~ | ||
| + | |||
| + | Par service et/ou par PID | ||
| + | ~~~bash | ||
| + | journalctl -u pacemaker.service --since " | ||
| + | journalctl _SYSTEMD_UNIT=avahi-daemon.service _PID=28097 + _SYSTEMD_UNIT=dbus.service | ||
| + | ~~~ | ||
| + | |||
| + | Voir aussi | ||
| + | ~~~bash | ||
| + | ps -f -p 28097 | ||
| + | systemctl status 28097 | ||
| + | |||
| + | # Par PPID | ||
| + | ps -f --ppid 1 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | Erreur au boot | ||
| + | ~~~bash | ||
| + | journalctl -b -p err | ||
| + | ~~~ | ||
| + | |||
| + | tailf | ||
| + | ~~~bash | ||
| + | # dmesg -l warn | ||
| + | journalctl -f -p warning | ||
| + | ~~~ | ||
| + | |||
| + | Ouvrir un fichier spécifique | ||
| + | ~~~bash | ||
| + | journalctl --file / | ||
| + | ~~~ | ||
| + | |||
| + | Filtrer les logs json | ||
| + | ~~~bash | ||
| + | journalctl -u nginx -o json-pretty | ||
| + | ~~~ | ||
| + | |||
| + | Les commandes sudo | ||
| + | ~~~ | ||
| + | # journalctl -b -t sudo -p 5 -u session-*.scope | ||
| + | Sep 12 08:19:01 vmdeb01 sudo[601]: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ### Options sur le forme | ||
| + | |||
| + | Arguments : | ||
| + | * `--no-pager` | ||
| + | * `-f` : tail -f | ||
| + | |||
| + | ## Configuration | ||
| + | |||
| + | |||
| + | |||
| + | ### Rendre persistant journalctl | ||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | Par défaut journalctl affiche uniquement les logs du dernier boot | ||
| + | |||
| + | ~~~ | ||
| + | # journalctl --boot=-1 | ||
| + | Failed to look up boot -1: Cannot assign requested address | ||
| + | ~~~ | ||
| + | |||
| + | Pour avoir les logs persistant : | ||
| + | |||
| + | |||
| + | `/ | ||
| + | ~~~ini | ||
| + | [Journal] | ||
| + | # | ||
| + | Storage=persistent | ||
| + | Compress=yes | ||
| + | |||
| + | # | ||
| + | SystemMaxUse=250M | ||
| + | |||
| + | # | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | mkdir / | ||
| + | systemd-tmpfiles --create --prefix / | ||
| + | systemctl restart systemd-journald | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Journalctl et container | ||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | | | | | ||
| + | | ---------------- | ------------------------------------------------------------------------------- | | ||
| + | |CONTAINER_ID | ||
| + | |CONTAINER_ID_FULL | The full 64-character container ID. | | ||
| + | |CONTAINER_NAME | ||
| + | |CONTAINER_TAG, | ||
| + | |CONTAINER_PARTIAL_MESSAGE | A field that flags log integrity. Improve logging of long log lines. | | ||
| + | |IMAGE_NAME | ||
| + | |||
| + | |||
| + | ### Retrieve log messages with journalctl | ||
| + | |||
| + | Use the journalctl command to retrieve log messages. You can apply filter expressions to limit the retrieved messages to those associated with a specific container: | ||
| + | |||
| + | ~~~bash | ||
| + | sudo journalctl CONTAINER_NAME=webserver | ||
| + | ~~~ | ||
| + | |||
| + | You can use additional filters to further limit the messages retrieved. The `-b` flag only retrieves messages generated since the last system boot: | ||
| + | |||
| + | ~~~bash | ||
| + | sudo journalctl -b CONTAINER_NAME=webserver | ||
| + | ~~~ | ||
| + | |||
| + | The -o flag specifies the format for the retrieved log messages. Use `-o json` to return the log messages in JSON format. | ||
| + | |||
| + | ~~~bash | ||
| + | sudo journalctl -o json CONTAINER_NAME=webserver | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | View logs for a container with a TTY enabled | ||
| + | |||
| + | If TTY is enabled on a container you may see [10B blob data] in the output when retrieving log messages. The reason for that is that \r is appended to the end of the line and journalctl doesn' | ||
| + | |||
| + | ~~~bash | ||
| + | sudo journalctl -b CONTAINER_NAME=webserver --all | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### Journalctl container et Python | ||
| + | |||
| + | Retrieve log messages with the journal API | ||
| + | This example uses the systemd Python module to retrieve container logs: | ||
| + | |||
| + | ~~~python | ||
| + | import systemd.journal | ||
| + | |||
| + | reader = systemd.journal.Reader() | ||
| + | reader.add_match(' | ||
| + | |||
| + | for msg in reader: | ||
| + | print ' | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Autres | ||
| + | |||
| + | `/ | ||
| + | ~~~ini | ||
| + | [Journal] | ||
| + | RateLimitInterval=10s | ||
| + | RateLimitBurst=6000 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Pb | ||
| + | |||
| + | ### Pb plus de logs avec journalctl ni dans / | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | # journalctl | ||
| + | No journal files were found. | ||
| + | -- No entries -- | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Solution | ||
| + | ~~~bash | ||
| + | systemctl restart systemd-journald | ||
| + | systemctl restart rsyslog.service | ||
| + | ~~~ | ||
| + | |||
