modulepackage
0.0.0-20180529133218-9a0802d16187
Repository: https://github.com/ssgreg/journalhook.git
Documentation: pkg.go.dev
# README
Systemd's
Journal hook for logrus

Installation
Install the package with:
go get -u github.com/ssgreg/journalhook
Usage
package main
import (
"os"
"github.com/sirupsen/logrus"
"github.com/ssgreg/journalhook"
fun main() {
log := logrus.New()
hook, err := journalhook.NewJournalHook()
if err == nil {
log.Hooks.Add(hook)
}
logEntry := log.WithFields(logrus.Fields{
"n_goroutine": runtime.NumGoroutine(),
"executable": os.Args[0],
"trace": runtime.ReadTrace(),
})
logEntry.Info("Hello World!")
// Make sure that journal connection will be successfully closed
// and no message will be lost.
logrus.Exit(0)
}
This is how it will look like:
{
"__CURSOR": "s=f81e8eb7fd0941b089528d889c929c1f;i=f1;b=40582011948a4b1998bf5ca928517a0f;m=2345f2fc69;t=557cb96d25735;x=e26ade807f4bab79",
"__REALTIME_TIMESTAMP": "1503906803898165",
"__MONOTONIC_TIMESTAMP": "151497407593",
"_BOOT_ID": "40582011948a4b1998bf5ca928517a0f",
"PRIORITY": "6",
"_UID": "0",
"_GID": "0",
"_CAP_EFFECTIVE": "a80425fb",
"_MACHINE_ID": "78b67a34f030403aa4dc97056d5efced",
"_HOSTNAME": "64620c2b0d13",
"_TRANSPORT": "journal",
"MESSAGE": "Hello World!",
"N_GOROUTINE": "2",
"TRACE": [ 103, 111, 32, 49, 46, 56, 32, 116, 114, 97, 99, 101, 0, 0, 0, 0 ],
"_COMM": "usage",
"EXECUTABLE": "./usage",
"_PID": "7533",
"_SOURCE_REALTIME_TIMESTAMP": "1503906803896890"
}
# Packages
No description provided by the author
# Functions
ErrToMsg sets Message to the contents of the associated error, if Message is not already set.
NewJournalHook creates a hook to be added to an instance of logger.
NewJournalHookWithErrToMsg creates a hook, which converts associated errors to messages, to be added to an instance of logger.
NewJournalHookWithLevels creates a hook to be added to an instance of logger.
NormalizeFieldName returns field name acceptable by journald.
# Structs
JournalHook is the systemd-journald hook for logrus.