jsonlogger

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: GPL-3.0 Imports: 2 Imported by: 2

README

JsonLogger Go Report Card

A Go (golang) json logging library for use with GCP Logs Explorer

Installation

As a library

go get github.com/brettcodling/jsonlogger

Usage

package main

import github.com/brettcodling/jsonlogger"

func main() {
  // You can use the built in log level methods (Info, Debug, Warn, Error)
  jsonlogger.Info("Info level log")
  
  // You can pass a context interface to the log as long as it can be marshalled to json
  err := ...
  jsonlogger.Error("Error!!!", map[string]string{"error": err.Error()})
  
  // You can also manually populate the JsonLog struct and call Log()
  jsonlogger.JsonLog{
    Message:  "Manual log",
    Context:  map[string]int{"test": 1}
    Severity: "INFO",
    Type:     "log",
  }.Log()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, context ...interface{})

Debug will log a json message with a severity of DEBUG

func Error

func Error(msg string, context ...interface{})

Error will log a json message with a severity of ERROR

func Info

func Info(msg string, context ...interface{})

Info will log a json message with a severity of INFO

func Warn

func Warn(msg string, context ...interface{})

Warn will log a json message with a severity of WARNING

Types

type JsonLog

type JsonLog struct {
	Message  string      `json:"message"`
	Context  interface{} `json:"context"`
	Type     string      `json:"type"`
	Severity string      `json:"severity"`
}

func (JsonLog) Log

func (jLog JsonLog) Log()

log will log a json message If the message cannot be marshalled the json error will be logged

Jump to

Keyboard shortcuts

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