Help us shape the future of Go! Take the 2026 Go Developer Survey

log

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

README

log GoDoc

Common usage

local log = require("log")
local info = log.new()

info:print("ok", " ", 1.2)
-- ok 1.2

info:println("ok", 1.2)
-- ok 1.2

info:printf("%s %f", "ok", 1.2)
-- ok 1.2

Set prefix

local log = require("log")
local info = log.new()

info:set_prefix("[INFO] ")
info:printf("%s %f", "ok", 1.2)
-- [INFO] ok 1.2

Set flags

local log = require("log")
local info = log.new()

info:set_prefix("[INFO] ")
info:set_flags({date=true, time=true})
info:printf("%s %f", "ok", 1.2)
-- [INFO] 2019/05/23 22:23:03 ok 1.2

info:set_flags({date=true, time=true, longfile=true})
info:printf("%s %f", "ok", 1.2)
-- [INFO] 2019/05/23 22:23:03 ./a/b/c.lua:17: ok 1.2

Output

local log = require("log")

local info, err = log.new("/path/to/file.log")
info:close() -- don't forget
info:set_output("/path/to/file2.log") -- write to new file
info:close()

-- prefix
local info, err = log.new("/path/to/file.log", "[INFO] ")
info:print("ok")
info:close() -- don't forget

-- flags
local logger_flags = {
    date=true,
    time=true,
    microseconds=true,
    utc=true,
    longfile = true,
}
local info, err = log.new("/path/to/file.log", "[INFO] ", logger_flags)
info:print("ok")
info:close() -- don't forget

-- to stdout/stderr
local info, err = log.new("/path/to/file.log")
info:close() -- don't forget
info:set_output("STDOUT") -- to STDOUT
info:set_output("-") -- to STDOUT
info:set_output("STDERR") -- to STDERR

loglevel - usage similar to slf4j

local log = require 'loglevel'
log.set_default_output('some-file-on-disk') -- defaults to "STDOUT"

-- Logs go to /dev/null
log.DEBUG:print('foobar')
log.DEBUG:printf('foo bar %s', 'baz')

-- Logs go to some-file-on-disk (the default_output setting)
log.set_level('DEBUG') -- defaults to "INFO"
log.DEBUG:print('foobar')
log.DEBUG:printf('foo bar %s', 'baz')

-- Other loggers
log.DEBUG:print('debug')
log.INFO:print('info')
log.WARN:print('warn')
log.ERROR:print('error')

-- Log levels
log.set_level('DEBUG')
log.set_level('INFO')
log.set_level('WARN')
log.set_level('ERROR')

Documentation

Overview

Package plugin implements golang packege log functionality for lua.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(L *lua.LState) int

Close logger_ud:close() return error

func LoadLogLevel

func LoadLogLevel(L *lua.LState) int

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func New

func New(L *lua.LState) int

New (filepath|STDOUT|STDERR, prefix, flag_config={}) return (logger_ud, err)

func Preload

func Preload(L *lua.LState)

Preload adds log to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

	local log = require("log")
 or for levelled logging
	local log = require("loglevel")

func Print

func Print(L *lua.LState) int

Print logger_ud:print(args...)

func Printf

func Printf(L *lua.LState) int

Printf logger_ud:printf(args...)

func Println

func Println(L *lua.LState) int

Println logger_ud:println(args...)

func SetFlags

func SetFlags(L *lua.LState) int

SetFlags logger_ud:set_flags(config={})

config = {
  date = false, -- print date
  time = false, -- print time
  microseconds = false, -- print microseconds
  utc = false, -- use utc
  longfile = false -- print lua code line
}

func SetOutput

func SetOutput(L *lua.LState) int

SetOutput logger_ud:set_output(filepath|STDOUT|STDERR) return error

func SetPrefix

func SetPrefix(L *lua.LState) int

SetPrefix logger_ud:prefix()

Types

This section is empty.

Jump to

Keyboard shortcuts

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