jsonlog

package module
v0.0.0-...-1a4e861 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2018 License: MIT Imports: 5 Imported by: 0

README

jsonlog-go

jsonlog-go is a logging package for doing logs compatible with inter-application communication.

jsonlog-go logs are structured as follows:

{
  "unix": "(Unix timestamp)",
  "type": "(log type; info, warning, error or fatal)",
  "timestamp": "(RFC3339 timestamp)",
  "message": "(log message)"
}

There's aswell an optional data tag that can be any type, including nil.

Documentation

Index

Constants

View Source
const (
	// Info is an informational message.
	Info = LogType(iota)

	// Warning is an warning message.
	Warning

	// Error is an error message.
	Error

	// Fatal is an fatal error message.
	Fatal
)

Variables

This section is empty.

Functions

func GetTypeName

func GetTypeName(t LogType) string

Gets the typename belonging to the logtype.

func Log

func Log(t LogType, message string) error

Log prints out a log as json format, newlines will be converted to escaped \n.

func LogData

func LogData(t LogType, message string, data interface{}) error

LogData prints out a log in json format, newlines will be converted to escaped \n. LogData allows attaching a data object which will be in a "data" tag.

Types

type LogType

type LogType uint8

LogType is the type of log to be displayed.

type Timestamp

type Timestamp struct {
	// contains filtered or unexported fields
}

Timestamp is a point in time.

func TimeNow

func TimeNow() Timestamp

TimeNow creates a new timestamp for the current time.

func (Timestamp) String

func (t Timestamp) String() (string, string, error)

String returns the timestamp as a string. first value is the RFC3339 version. second value is UNIX time version.

Jump to

Keyboard shortcuts

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