package journal
import "github.com/coreos/go-systemd/v22/journal"
Package journal provides write bindings to the local systemd journal. It is implemented in pure Go and connects to the journal directly over its unix socket.
To read from the journal, see the "sdjournal" package, which wraps the sd-journal a C API.
http://www.freedesktop.org/software/systemd/man/systemd-journald.service.html
Package journal provides write bindings to the local systemd journal. It is implemented in pure Go and connects to the journal directly over its unix socket.
To read from the journal, see the "sdjournal" package, which wraps the sd-journal a C API.
http://www.freedesktop.org/software/systemd/man/systemd-journald.service.html
Index ¶
- func Enabled() bool
- func Print(priority Priority, format string, a ...interface{}) error
- func Send(message string, priority Priority, vars map[string]string) error
- func StderrIsJournalStream() (bool, error)
- func StdoutIsJournalStream() (bool, error)
- type Priority
Examples ¶
Functions ¶
func Enabled ¶
func Enabled() bool
Enabled checks whether the local systemd journal is available for logging.
func Print ¶
Print prints a message to the local systemd journal using Send().
func Send ¶
Send a message to the local systemd journal. vars is a map of journald fields to values. Fields must be composed of uppercase letters, numbers, and underscores, but must not start with an underscore. Within these restrictions, any arbitrary field name may be used. Some names have special significance: see the journalctl documentation (http://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html) for more details. vars may be nil.
func StderrIsJournalStream ¶
StderrIsJournalStream returns whether the process stderr is connected to the Journal's stream transport.
This can be used for automatic protocol upgrading described in Journal Native Protocol.
Returns true if JOURNAL_STREAM environment variable is present, and stderr's device and inode numbers match it.
Error is returned if unexpected error occurs: e.g. if JOURNAL_STREAM environment variable
is present, but malformed, fstat syscall fails, etc.
Code:play
Example¶
package main
import (
"fmt"
"os"
"github.com/coreos/go-systemd/v22/journal"
)
func main() {
// NOTE: this is just an example. Production code
// will likely use this to setup a logging library
// to write messages to either journal or stderr.
ok, err := journal.StderrIsJournalStream()
if err != nil {
panic(err)
}
if ok {
// use journal native protocol
journal.Send("this is a message logged through the native protocol", journal.PriInfo, nil)
} else {
// use stderr
fmt.Fprintln(os.Stderr, "this is a message logged through stderr")
}
}
func StdoutIsJournalStream ¶
StdoutIsJournalStream returns whether the process stdout is connected to the Journal's stream transport.
Returns true if JOURNAL_STREAM environment variable is present, and stdout's device and inode numbers match it.
Error is returned if unexpected error occurs: e.g. if JOURNAL_STREAM environment variable is present, but malformed, fstat syscall fails, etc.
Most users should probably use StderrIsJournalStream.
Types ¶
type Priority ¶
type Priority int
Priority of a journal message
Source Files ¶
- Version
- v22.5.0 (latest)
- Published
- Nov 7, 2022
- Platform
- linux/amd64
- Imports
- 14 packages
- Last checked
- 2 days ago –
Tools for package owners.