add newLogger call

This commit is contained in:
Pedro Pérez 2024-11-14 08:15:13 +01:00
parent dc48e215ec
commit 72ff6d3d9e
2 changed files with 6 additions and 5 deletions

View File

@ -2,13 +2,14 @@ package main
import ( import (
"log/slog" "log/slog"
"net/http"
"ron" "ron"
) )
func main() { func main() {
r := ron.New() r := ron.New(func(e *ron.Engine) {
e.LogLevel = slog.LevelDebug
})
htmlRender := ron.NewHTMLRender() htmlRender := ron.NewHTMLRender()
r.Renderer = htmlRender r.Renderer = htmlRender
@ -19,11 +20,11 @@ func main() {
r.GET("/html", helloWorldHTML) r.GET("/html", helloWorldHTML)
r.GET("/component", componentHTML) r.GET("/component", componentHTML)
slog.Info("Server is running at http://localhost:8080") r.Run(":8080")
http.ListenAndServe(":8080", r)
} }
func helloWorld(c *ron.Context) { func helloWorld(c *ron.Context) {
slog.Info("Dummy info message")
c.W.Write([]byte("hello world")) c.W.Write([]byte("hello world"))
} }

2
ron.go
View File

@ -40,7 +40,6 @@ func DefaultEngine() *Engine {
func New(opts ...EngineOptions) *Engine { func New(opts ...EngineOptions) *Engine {
config := DefaultEngine() config := DefaultEngine()
return config.apply(opts...) return config.apply(opts...)
} }
func (e *Engine) apply(opts ...EngineOptions) *Engine { func (e *Engine) apply(opts ...EngineOptions) *Engine {
@ -58,6 +57,7 @@ func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
func (e *Engine) Run(addr string) error { func (e *Engine) Run(addr string) error {
newLogger(e.LogLevel)
return http.ListenAndServe(addr, e) return http.ListenAndServe(addr, e)
} }