journalhook

package module
v0.0.0-...-6590c07 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2017 License: MIT Imports: 4 Imported by: 0

README

Systemd's Journal hook for logrus

Build Status Go Report Status

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"
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JournalHook

type JournalHook struct {
	Journal      *journald.Journal
	LogrusLevels []logrus.Level
}

JournalHook is the systemd-journald hook for logrus.

func NewJournalHook

func NewJournalHook() (*JournalHook, error)

NewJournalHook creates a hook to be added to an instance of logger.

func NewJournalHookWithLevels

func NewJournalHookWithLevels(levels []logrus.Level) (*JournalHook, error)

NewJournalHookWithLevels creates a hook to be added to an instance of logger. It's also allowed to specify logrus levels to fire events for.

func (*JournalHook) Fire

func (h *JournalHook) Fire(entry *logrus.Entry) error

Fire writes a log entry to the systemd journal.

func (*JournalHook) Levels

func (h *JournalHook) Levels() []logrus.Level

Levels returns a slice of Levels the hook is fired for.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL