?
本文檔使用 php中文網(wǎng)手冊 發(fā)布
大journald
日志驅(qū)動程序?qū)⑷萜魅罩景l(fā)送到systemd
日刊.日志條目可以使用journalctl
命令,通過使用journal
API,或使用docker logs
命令。
除了日志消息本身的文本之外,journald
日志驅(qū)動程序?qū)⒁韵略獢?shù)據(jù)與每條消息一起存儲在日記中:
Field | Description |
---|---|
CONTAINER_ID | The container ID truncated to 12 characters. |
CONTAINER_ID_FULL | The full 64-character container ID. |
CONTAINER_NAME | The container name at the time it was started. If you use docker rename to rename a container, the new name is not reflected in the journal entries. |
CONTAINER_TAG | The container tag (log tag option documentation). |
CONTAINER_PARTIAL_MESSAGE | A field that flags log integrity. Improve logging of long log lines. |
使用journald
驅(qū)動程序作為默認日志記錄驅(qū)動程序,設(shè)置log-driver
和log-opt
控件中的適當值的鍵。daemon.json
文件,該文件位于/etc/docker/
在linux主機上或C:\ProgramData\docker\config\daemon.json
在WindowsServer上。有關(guān)+配置Docker的更多信息,請使用daemon.json
,見+daemon.json...
下面的示例將日志驅(qū)動程序設(shè)置為journald
*
{ "log-driver": "journald"}
重新啟動Docker以使更改生效。
若要為特定容器配置日志驅(qū)動程序,請使用--log-driver
標志上docker run
命令。
$ docker run --log-driver=journald ...
使用--log-opt NAME=VALUE
標志指定附加journald
日志驅(qū)動程序選項。
tag
指定要設(shè)置的模板CONTAINER_TAG
價值journald
原木。請參閱日志標記選項文檔若要自定義日志標記格式,請執(zhí)行以下操作。
labels
,,,env
,和eng-regex
大labels
和env
每個選項都采用逗號分隔的鍵列表。如果有碰撞label
和env
鍵的值。env
優(yōu)先考慮。每個選項都會向日記中添加附加元數(shù)據(jù)和每條消息。
env-regex
與env
.將其設(shè)置為正則表達式以匹配與日志記錄相關(guān)的環(huán)境變量.。它用于高級日志標記選項...
中記錄的值。CONTAINER_NAME
字段是在啟動時設(shè)置的容器的名稱。如果你用docker rename
若要重命名容器,請使用新名稱未反映在日記里。日記賬條目將繼續(xù)使用原始名稱。
journalctl
使用journalctl
命令檢索日志消息??梢詰?yīng)用篩選器表達式將檢索到的消息限制為與特定容器關(guān)聯(lián)的消息:
$ sudo journalctl CONTAINER_NAME=webserver
您可以使用其他篩選器進一步限制檢索的消息。大-b
標志僅檢索上次系統(tǒng)啟動后生成的消息:
$ sudo journalctl -b CONTAINER_NAME=webserver
大-o
標志指定重試日志消息的格式。使用-o json
返回JSON格式的日志消息。
$ sudo journalctl -o json CONTAINER_NAME=webserver
journal
API此示例使用systemd
用于檢索容器日志的Python模塊:
import systemd.journal reader = systemd.journal.Reader()reader.add_match('CONTAINER_NAME=web') for msg in reader: print '{CONTAINER_ID_FULL}: {MESSAGE}'.format(**msg)