Log
c.Log calls the API's Log group. The entries of the systemd journal.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
List(ctx, hostname, params) | *Response[Collection[LogEntry]] | log:read | List the entries of the journal. |
List
func (s *LogService) List(
ctx context.Context,
hostname string,
params LogListParams,
) (*Response[Collection[LogEntry]], error)
List the entries of the journal.
Runs journalctl --output=json, the newest entries last: the last 100 unless lines says, of one unit when unit says, since a time when since says, and at a priority or above when priority says. A priority is its name, such as err or info. The hand-written log domain read the Debian family only; this reads each Linux host that has journald.
It sends GET /api/node/{hostname}/log, and needs the permission log:read.
The examples of the method's definition:
The newest entries, go run log.go list:
resp, err := c.Log.List(ctx, target, client.LogListParams{})
The last entry of one unit at info or above, go run log.go list-2:
resp, err := c.Log.List(ctx, target, client.LogListParams{
Lines: 1,
Priority: client.Priority("info"),
Since: "1 hour ago",
Unit: "nginx.service",
})
Types
The fields of each type are the properties of its schema in the API's spec.
LogEntry
| Field | Type | Description |
|---|---|---|
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Message | string | The message. |
PID | int | The process that wrote it. |
Priority | Priority | |
Status | RowStatus | What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran. |
Timestamp | string | When journald recorded it, in RFC 3339. |
Unit | string | The syslog identifier that wrote it. |
Priority
Only the entries at this priority or above.
A string, one of emerg, alert, crit, err, warning, notice, info,
debug.
RowStatus
What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.
A string, one of ok, failed, skipped, timeout.
Example
examples/sdk/client/log.go
runs each example of this page. With no argument, it lists them.