glog and gcolor in quick #160
Replies: 3 comments 1 reply
-
new pkgs for Quick, now we have native glog and gcolor, so we can make our APIs even more complete. glog is the same idea as the logger middleware, that is, the same base and structure, the logs have become standard in Quick. We still need to carry out tests with examples demonstrating the possible combinations that can be made with gcolor and glogs in Quick. There is still a lot missing, but version 0.0.1 has been released, now it is time to play around and improve. I hope you like it 🩷🚀🥰💕🐧 @GuilhermeCaruso |
Beta Was this translation helpful? Give feedback.
-
Sorry for not responding so quickly, I spent the days optimizing and refactoring glog, and I got very close to zerolog in the Benchmark glog vs zerolog => we are close to them This is important for our CLI, because it can generate the examples with contexts etc. and logs etc. I'll send the example 🚀🔥🐧 Example glog with Ctx and api package main
import (
"context"
"encoding/json"
"fmt"
"time"
"github.com/jeffotoni/quick"
"github.com/jeffotoni/quick/pkg/glog"
"github.com/jeffotoni/quick/pkg/rand"
)
const KeyName string = "X-Trace-ID"
// curl -i -XPOST -H "Content-Type:application/json" localhost:8080/v1/user -d '{"name": "jeff", "year": 2025}'
func main() {
logger := glog.Set(glog.Config{
Format: "json",
Level: glog.DEBUG,
})
q := quick.New()
q.Post("/v1/user", func(c *quick.Ctx) error {
// creating a trace
traceID := c.Get("X-Trace-ID")
if traceID == "" {
traceID = rand.TraceID()
}
userID := rand.AlgoDefault(9000, 9000)
spanID := "span39393"
ctx, cancel := glog.CreateCtx().
Set("X-Trace-ID", traceID).
Set("X-User-ID", userID).
Set("X-Span-ID", spanID).
Timeout(10 * time.Second).
Build()
defer cancel()
c.Set("X-Trace-ID", traceID)
c.Set("X-User-ID", userID)
c.Set("X-Span-ID", spanID)
c.Set("Content-type", "application/json")
var d any
err := c.BodyParser(&d)
if err != nil {
logger.Error().
Time().
Level().
Str(KeyName, traceID).
Str("error", err.Error()).
Send()
return c.Status(500).JSON(quick.M{"msg": err.Error()})
}
logger.Debug().
Time().
Level().
Str(KeyName, traceID).
Str("func", "BodyParser").
Str("status", "success").
// Caller().
Send()
// call metodh
b, err := SaveSomeWhere(ctx, logger, d)
if err != nil {
logger.Error().
Time().
Level().
Str(KeyName, traceID).
Str("Error", err.Error()).
Send()
return c.Status(500).JSON(quick.M{"msg": err.Error()})
}
logger.Debug().
Time().
Level().
Str(KeyName, traceID).
Str("func", "SaveSomeWhere").
Int("code", quick.StatusOK).
Msg("api-post-fluent").
Send()
all := glog.GetCtxAll(ctx)
fmt.Printf("X-Trace-ID:%s X-User-ID:%s X-Span-ID:%s\n", all["X-Trace-ID"], all["X-User-ID"], all["X-Span-ID"])
return c.Status(quick.StatusOK).Send(b)
})
q.Listen("0.0.0.0:8080")
}
func SaveSomeWhere(ctx context.Context, logger *glog.Logger, data any) (b []byte, err error) {
traceID := glog.GetCtx(ctx, KeyName)
b, err = json.Marshal(data)
if err != nil {
logger.Error().
Time().
Level().
Str(KeyName, traceID).
Str("Error", err.Error()).
Send()
return
}
err = SendQueue(ctx, logger, b)
if err != nil {
logger.Error().
Time().
Level().
Str(KeyName, traceID).
Str("Error", err.Error()).
Send()
return nil, err
}
logger.Debug().
Time().
Level().
Str(KeyName, traceID).
Str("func", "Marshal").
Str("status", "success").
Send()
return
}
func SendQueue(ctx context.Context, logger *glog.Logger, data []byte) (err error) {
// send SQS
time.Sleep(time.Millisecond * 100)
logger.Debug().
Time().
Level().
Str(KeyName, glog.GetCtx(ctx, KeyName)).
Str("func", "SendSQS").
Str("status", "success").
Send()
return
} |
Beta Was this translation helpful? Give feedback.
-
Hello @jeffotoni Ok no worries i understand, good job. that's a good improvements. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
🎨 gcolor – Fluent ANSI Color Library in Go
We created a library called gcolor, with a fluent, modern and flexible API for styling terminal output in Go using ANSI escape codes.
Inspired by libraries like fatih/color, gookit/color and termenv, it allows you to compose styles elegantly with support for:
✅ Foreground and background colors
✅ Styles like Bold() and Underline()
✅ Fluent chaining (.Fg().Bg().Bold().Println())
✅ Sprint, Sprintf, Print, Println
✅ Integration with log.SetPrefix, log.Printf, etc.
✅ 100% test coverage with go test
✅ Examples documented in the official Go style
Example Full
🚀 Project glog – Modern and lightweight logger in Go
We have just created glog, a flexible, lightweight and powerful logging library for Go, inspired by modern best practices and the simplicity that every project needs.
✅ Features:
Example full
Beta Was this translation helpful? Give feedback.
All reactions