first commit

This commit is contained in:
2026-02-25 22:39:00 +03:00
commit 928d17af74
13 changed files with 1351 additions and 0 deletions

34
examples/basic/main.go Normal file
View File

@@ -0,0 +1,34 @@
package main
import (
"log/slog"
"strings"
"github.com/VexoraDevelopment/consolex"
)
func main() {
logFile, err := consolex.SetupDefaultSlog(consolex.LoggerConfig{
LogFilePath: "server.log",
ArchiveDir: "logs",
Level: slog.LevelDebug,
Theme: consolex.NordTheme(),
FieldProvider: consolex.StaticFieldProvider{
"addr": consolex.New().Black().BgCyan().Bold(),
"proto_id": consolex.New().White().BgBlue().Bold(),
},
FieldTransform: consolex.FieldTransformFunc(func(key, value string) (string, bool) {
if key == "dimension" {
return "\"" + strings.ToUpper(strings.Trim(value, "\"")) + "\"", true
}
return "", false
}),
})
if err != nil {
panic(err)
}
defer logFile.Close()
slog.Info("Listener running.", "addr", "[::]:19132")
slog.Debug("Loading dimension...", "dimension", "overworld")
}

47
examples/pipeline/main.go Normal file
View File

@@ -0,0 +1,47 @@
package main
import (
"log/slog"
"github.com/VexoraDevelopment/consolex"
)
func main() {
profile := consolex.DefaultProfile()
profile.HideKeys["name"] = false
profile.HideKeys["dimension"] = false
logFile, err := consolex.SetupDefaultSlog(consolex.LoggerConfig{
LogFilePath: "server.log",
ArchiveDir: "logs",
Level: slog.LevelDebug,
Theme: consolex.DefaultTheme(),
Profile: profile,
Processors: []consolex.Processor{
consolex.ProcessorFunc(func(rec *consolex.LogRecord) {
// Example: force showing key for world pointer fields in compact layout.
for i := range rec.Fields {
if rec.Fields[i].Key == "ptr" {
rec.Fields[i].ShowKey = true
}
}
}),
},
FieldProvider: consolex.FieldStyleFunc(func(key, value string) (consolex.Chalk, bool) {
switch key {
case "name":
return consolex.New().Black().BgYellow(), true
case "ptr":
return consolex.New().White().BgMagenta(), true
default:
return consolex.Chalk{}, false
}
}),
})
if err != nil {
panic(err)
}
defer logFile.Close()
slog.Info("world register", "name", "hub_snow", "ptr", "0xc004ba0ea0")
}