loguago

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: MIT Imports: 4 Imported by: 2

README

loguago

Zerolog wrapper for Gopher-Lua | godoc

For those interested in helping out, I will gladly accept recommendations, ideas and PRs!

Example usage:

package main

import (
	"fmt"
	"io/ioutil"
	"os"

	"github.com/rs/zerolog"
	lua "github.com/yuin/gopher-lua"
	"github.com/rucuriousyet/loguago"
)

func main() {
	state := lua.NewState()
	defer state.Close()

	// create a standard zerolog instance with your desired config (just an example)
	zlogger := zerolog.New(os.Stdout).With().Str("unit", "my-lua-module").Logger()
	
	// wrap the zerolog instance as a loguago logger
	logger := loguago.NewLogger(zlogger)

	// load the loguago logger as a Gopher-Lua module with the module name "logger" (used for require)
	state.PreloadModule("logger", logger.Loader)
  
  	// the rest of your program lives here
  	// ...
}
local logger = require("logger")

-- the following functions all have the same signature but different names to
-- allow for log levelling. `logger.<level>(message, fields)`
logger.info("msg", {name="seth", isCoder=true})
logger.debug
logger.warn
logger.error

-- each logging function takes a message and a table with an indeterminate
-- number of fields to provide context within the log messages. For example, (depending
-- on how you configure the zerolog instance) this:
logger.info("foo bar!", {name="seth", age=1000, engineer=true})
-- should produce something like: "1494567715 |INFO| foo bar! name=seth age=1000 engineer=true"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

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

Logger is a simple type used to manage the state and backing zerolog.Logger

func NewLogger

func NewLogger(logger zerolog.Logger) *Logger

NewLogger creates and returns a new logger using an existing zerolog.Logger

func (*Logger) Loader

func (logmod *Logger) Loader(state *lua.LState) int

Loader is the default stub used by the Gopher-Lua PreloadModule function.

Jump to

Keyboard shortcuts

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