All Projects → ssgreg → journald

ssgreg / journald

Licence: MIT license
Go implementation of systemd Journal's native API for logging

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to journald

Systemdlogger
Exports systemd logs to an external service, eg cloudwatch, elasticsearch
Stars: ✭ 91 (+167.65%)
Mutual labels:  systemd
Fluent Plugin Systemd
This is a fluentd input plugin. It reads logs from the systemd journal.
Stars: ✭ 124 (+264.71%)
Mutual labels:  systemd
Ansible Role Hardening
Ansible role to apply a security baseline. Systemd edition.
Stars: ✭ 188 (+452.94%)
Mutual labels:  systemd
Sleepto
An alternative to traditional task schedulers
Stars: ✭ 98 (+188.24%)
Mutual labels:  systemd
Asus Fan Control
🌀 Fan control for ASUS devices running Linux.
Stars: ✭ 120 (+252.94%)
Mutual labels:  systemd
Pia Tools
Shell script to automate privateinternetaccess port forwarding and starting/stopping transmission when connected/disconnected and other stuff
Stars: ✭ 130 (+282.35%)
Mutual labels:  systemd
Localslackirc
IRC gateway for slack, running on localhost for one user
Stars: ✭ 84 (+147.06%)
Mutual labels:  systemd
Systemd Ngrok
Automatically start ngrok by systemd
Stars: ✭ 241 (+608.82%)
Mutual labels:  systemd
Go Systemd
Go bindings to systemd socket activation, journal, D-Bus, and unit files
Stars: ✭ 1,756 (+5064.71%)
Mutual labels:  systemd
Procsd
Manage your application processes in production hassle-free like Heroku CLI with Procfile and Systemd
Stars: ✭ 181 (+432.35%)
Mutual labels:  systemd
Log2ram
ramlog like for systemd (Put log into a ram folder)
Stars: ✭ 1,751 (+5050%)
Mutual labels:  systemd
Capistrano Mb
[unmaintained] Capistrano tasks for deploying Rails from scratch to Ubuntu 16.04 and 18.04
Stars: ✭ 117 (+244.12%)
Mutual labels:  systemd
Netctl
Profile based systemd network management
Stars: ✭ 163 (+379.41%)
Mutual labels:  systemd
Selfhosted
rootless docker compose + traefik
Stars: ✭ 97 (+185.29%)
Mutual labels:  systemd
Container Linux Update Operator
A Kubernetes operator to manage updates of Container Linux by CoreOS
Stars: ✭ 208 (+511.76%)
Mutual labels:  systemd
Graphite Metrics
metric collectors for various stuff not (or poorly) handled by other monitoring daemons
Stars: ✭ 85 (+150%)
Mutual labels:  systemd
Graceful
graceful reload golang http server, zero downtime, compatible with systemd, supervisor
Stars: ✭ 129 (+279.41%)
Mutual labels:  systemd
Dplatform Shell
Deploy self-hosted apps easily: simple, bloat-free, independent installation
Stars: ✭ 245 (+620.59%)
Mutual labels:  systemd
Chkservice
Systemd units manager with ncurses, terminal interface
Stars: ✭ 219 (+544.12%)
Mutual labels:  systemd
Systemd Service Hardening
Basic guide to harden systemd services
Stars: ✭ 165 (+385.29%)
Mutual labels:  systemd

journald

GoDoc Build Status Go Report Status GoCover

Package journald offers Go implementation of systemd Journal's native API for logging. Key features are:

  • based on a connection-less socket
  • work with messages of any size and type
  • client can use any number of separate sockets

Installation

Install the package with:

go get github.com/ssgreg/journald

Usage: The Best Way

The Best Way to use structured logs (systemd Journal, etc.) is logf - the fast, asynchronous, structured logger in Go with zero allocation count and it's journald driver logfjournald. This driver uses journald package. The following example creates the new logf logger with logfjournald appender.

package main

import (
    "runtime"

    "github.com/ssgreg/logf"
    "github.com/ssgreg/logfjournald"
)

func main() {
    // Create journald Appender with default journald Encoder.
    appender, appenderClose := logfjournald.NewAppender(logfjournald.NewEncoder.Default())
    defer appenderClose()

    // Create ChannelWriter with journald Encoder.
    writer, writerClose := logf.NewChannelWriter(logf.ChannelWriterConfig{
        Appender: appender,
    })
    defer writerClose()

    // Create Logger with ChannelWriter.
    logger := logf.NewLogger(logf.LevelInfo, writer)

    logger.Info("got cpu info", logf.Int("count", runtime.NumCPU()))
}

The JSON representation of the journal entry this generates:

{
  "TS": "2018-11-01T07:25:18Z",
  "PRIORITY": "6",
  "LEVEL": "info",
  "MESSAGE": "got cpu info",
  "COUNT": "4",
}

Usage: AS-IS

Let's look at what the journald provides as Go APIs for logging:

package main

import (
    "github.com/ssgreg/journald"
)

func main() {
    journald.Print(journald.PriorityInfo, "Hello World!")
}

The JSON representation of the journal entry this generates:

{
    "PRIORITY": "6",
    "MESSAGE":  "Hello World!",
    "_PID":     "3965",
    "_COMM":    "simple",
    "...":      "..."
}

The primary reason for using the Journal's native logging APIs is not just plain logs: it is to allow passing additional structured log messages from the program into the journal. This additional log data may the be used to search the journal for, is available for consumption for other programs, and might help the administrator to track down issues beyond what is expressed in the human readable message text. Here's an example how to do that with journals.Send:

package main

import (
    "os"
    "runtime"

    "github.com/ssgreg/journald"
)

func main() {
    journald.Send("Hello World!", journald.PriorityInfo, map[string]interface{}{
        "HOME":        os.Getenv("HOME"),
        "TERM":        os.Getenv("TERM"),
        "N_GOROUTINE": runtime.NumGoroutine(),
        "N_CPUS":      runtime.NumCPU(),
        "TRACE":       runtime.ReadTrace(),
    })
}

This will write a log message to the journal much like the earlier examples. However, this times a few additional, structured fields are attached:

{
    "PRIORITY":     "6",
    "MESSAGE":      "Hello World!",
    "HOME":         "/root",
    "TERM":         "xterm",
    "N_GOROUTINE":  "2",
    "N_CPUS":       "4",
    "TRACE":        [103,111,32,49,46,56,32,116,114,97,99,101,0,0,0,0],
    "_PID":         "4037",
    "_COMM":        "send",
    "...":          "..."
}

Our structured message includes seven fields. The first two we passed are well-known fields:

  1. MESSAGE= is the actual human readable message part of the structured message.
  2. PRIORITY= is the numeric message priority value as known from BSD syslog formatted as an integer string.

Applications may relatively freely define additional fields as they see fit (we defined four pretty arbitrary ones in our example). A complete list of the currently well-known fields is available here.

Thanks to http://0pointer.de/blog/ for the inspiration.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].