Browse Source

En cours de développement

master
mls-361 2 months ago
parent
commit
1869e94795
  1. 12
      internal/api/api.go
  2. 8
      internal/config/data/logger.go
  3. 4
      internal/logger/logger.go
  4. 21
      internal/middleware/log.go

12
internal/api/api.go

@ -35,7 +35,11 @@ func newAPI(ccs *components.Components) *api {
}
}
func (api *api) middleware(hf jsonapi.HandlerFunc) jsonapi.Handler {
func (api *api) debug(hf jsonapi.HandlerFunc) jsonapi.Handler {
return middleware.Debug(hf, api.logger)
}
func (api *api) trace(hf jsonapi.HandlerFunc) jsonapi.Handler {
return middleware.Trace(hf, api.logger)
}
@ -89,12 +93,12 @@ func Build(ccs *components.Components) {
api := newAPI(ccs)
router := ccs.Router
router.Get("/status", api.middleware(func(r *jsonapi.Request) {
router.Get("/status", api.debug(func(r *jsonapi.Request) {
r.RenderOK()
}))
router.Post("/job/create", api.middleware(api.createJob))
router.Get("/job/next/:namespace", api.middleware(api.nextJob))
router.Post("/job/create", api.debug(api.createJob))
router.Get("/job/next/:namespace", api.trace(api.nextJob))
}
/*

8
internal/config/data/logger.go

@ -25,6 +25,14 @@ func defaultLogger() *Logger {
}
func (l *Logger) validate() error {
if l.Level == "" {
l.Level = _defaultLoggerLevel
}
if l.Output == "" {
l.Output = _defaultLoggerOutput
}
return nil
}

4
internal/logger/logger.go

@ -15,7 +15,9 @@ import (
// AFAIRE.
func Build(ccs *components.Components) (components.Logger, error) {
app := ccs.Application
return logger.New(app.ID(), app.Name(), "trace", logger.NewStderrOutput())
cfg := ccs.Config
return logger.New(app.ID(), app.Name(), cfg.Logger().Level, logger.NewStderrOutput())
}
/*

21
internal/middleware/trace.go → internal/middleware/log.go

@ -12,6 +12,27 @@ import (
"forge.chapril.org/armen/armen/internal/components"
)
// Debug AFAIRE.
func Debug(next jsonapi.Handler, logger components.Logger) jsonapi.Handler {
return jsonapi.HandlerFunc(func(r *jsonapi.Request) {
logger.Debug( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Request",
"id", r.ID(),
"from", r.RemoteAddr,
"method", r.Method,
"uri", r.URL.RequestURI(),
)
next.Serve(r)
logger.Debug( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Response",
"id", r.ID(),
"status", r.Status(),
)
})
}
// Trace AFAIRE.
func Trace(next jsonapi.Handler, logger components.Logger) jsonapi.Handler {
return jsonapi.HandlerFunc(func(r *jsonapi.Request) {
Loading…
Cancel
Save