Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
9b90315f37
|
|||
|
3c7686a219
|
|||
|
575fd286e5
|
|||
|
eb5f6c9adb
|
|||
|
4652539e77
|
28
README.adoc
Normal file
28
README.adoc
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
= lol
|
||||||
|
|
||||||
|
== location of log
|
||||||
|
|
||||||
|
This is a very simple, but practical library for logging in applications. Its
|
||||||
|
main feature is printing source code locations to make debugging easier.
|
||||||
|
|
||||||
|
to use:
|
||||||
|
|
||||||
|
[source,go]
|
||||||
|
----
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"lol.mleku.dev"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
err := errorf.E("this is a pretend error")
|
||||||
|
if chk.E(err) {
|
||||||
|
log.E.F("you saw it print the error creating it, checking it, and now here is a log")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
There are more variants, different error levels, a level setting that can be
|
||||||
|
changed while running. See the handy shortcut packages in chk, errorf and log
|
||||||
|
for more details.
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
# lol
|
|
||||||
|
|
||||||
location of log
|
|
||||||
|
|
||||||
This is a very simple, but practical library for logging in applications. Its
|
|
||||||
main feature is printing source code locations to make debugging easier.
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
package chk
|
package chk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mleku/lol"
|
"lol.mleku.dev"
|
||||||
)
|
)
|
||||||
|
|
||||||
var F, E, W, I, D, T lol.Chk
|
var F, E, W, I, D, T lol.Chk
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
package errorf
|
package errorf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mleku/lol"
|
"lol.mleku.dev"
|
||||||
)
|
)
|
||||||
|
|
||||||
var F, E, W, I, D, T lol.Err
|
var F, E, W, I, D, T lol.Err
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module github.com/mleku/lol
|
module lol.mleku.dev
|
||||||
|
|
||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
|
|||||||
26
log.go
26
log.go
@@ -13,7 +13,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/fatih/color"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -89,12 +88,12 @@ var (
|
|||||||
// LevelSpecs specifies the id, string name and color-printing function
|
// LevelSpecs specifies the id, string name and color-printing function
|
||||||
LevelSpecs = []LevelSpec{
|
LevelSpecs = []LevelSpec{
|
||||||
{Off, "", NoSprint},
|
{Off, "", NoSprint},
|
||||||
{Fatal, "FTL", color.New(color.BgRed, color.FgHiWhite).Sprint},
|
{Fatal, "☠️", fmt.Sprint},
|
||||||
{Error, "ERR", color.New(color.FgHiRed).Sprint},
|
{Error, "🚨", fmt.Sprint},
|
||||||
{Warn, "WRN", color.New(color.FgHiYellow).Sprint},
|
{Warn, "⚠️", fmt.Sprint},
|
||||||
{Info, "INF", color.New(color.FgHiGreen).Sprint},
|
{Info, "ℹ️", fmt.Sprint},
|
||||||
{Debug, "DBG", color.New(color.FgHiBlue).Sprint},
|
{Debug, "🔎", fmt.Sprint},
|
||||||
{Trace, "TRC", color.New(color.FgHiMagenta).Sprint},
|
{Trace, "👻", fmt.Sprint},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -185,7 +184,7 @@ func JoinStrings(a ...any) (s string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var msgCol = color.New(color.FgBlue).Sprint
|
var msgCol = fmt.Sprint
|
||||||
|
|
||||||
// GetPrinter returns a full logger that writes to the provided io.Writer.
|
// GetPrinter returns a full logger that writes to the provided io.Writer.
|
||||||
func GetPrinter(l int32, writer io.Writer, skip int) LevelPrinter {
|
func GetPrinter(l int32, writer io.Writer, skip int) LevelPrinter {
|
||||||
@@ -325,16 +324,7 @@ func New(writer io.Writer, skip int) (l *Log, c *Check, errorf *Errorf) {
|
|||||||
|
|
||||||
// TimeStamper generates the timestamp for logs.
|
// TimeStamper generates the timestamp for logs.
|
||||||
func TimeStamper() (s string) {
|
func TimeStamper() (s string) {
|
||||||
ts := time.Now().Format("150405.000000")
|
s = fmt.Sprint(time.Now().UnixMicro())
|
||||||
ds := time.Now().Format("2006-01-02")
|
|
||||||
s += color.New(color.FgBlue).Sprint(ds[0:4])
|
|
||||||
s += color.New(color.FgHiBlue).Sprint(ds[5:7])
|
|
||||||
s += color.New(color.FgBlue).Sprint(ds[8:])
|
|
||||||
s += color.New(color.FgHiBlue).Sprint(ts[0:2])
|
|
||||||
s += color.New(color.FgBlue).Sprint(ts[2:4])
|
|
||||||
s += color.New(color.FgHiBlue).Sprint(ts[4:6])
|
|
||||||
s += color.New(color.FgBlue).Sprint(ts[7:])
|
|
||||||
s += " "
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mleku/lol"
|
"lol.mleku.dev"
|
||||||
)
|
)
|
||||||
|
|
||||||
var F, E, W, I, D, T lol.LevelPrinter
|
var F, E, W, I, D, T lol.LevelPrinter
|
||||||
|
|||||||
Reference in New Issue
Block a user