Skip to content

Commit

Permalink
feat: update logger
Browse files Browse the repository at this point in the history
  • Loading branch information
devanbenz committed Jan 22, 2024
1 parent 662e3d5 commit 9353f43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
11 changes: 6 additions & 5 deletions internal/db/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ import (
var migrations embed.FS

func RunMigrations(db *sql.DB) {
log.Debug("Running migrations...")
logger := log.NewLogger()
logger.Debug("Running migrations...")
driver, err := mysql.WithInstance(db, &mysql.Config{})
if err != nil {
log.Fatal("Error getting MySQL driver", err)
logger.Fatal("Error getting MySQL driver", err)
}
source, _ := iofs.New(migrations, "migrations")
m, err := migrate.NewWithInstance("iofs", source, "mysql", driver)
if err != nil {
log.Fatal("Error connecting to database", err)
logger.Fatal("Error connecting to database", err)
}
if err := m.Up(); err != nil && fmt.Sprintf("%s", err) != "no change" {
log.Fatal("Error running migrations", err)
logger.Fatal("Error running migrations", err)
}
log.Debug("Done!")
logger.Debug("Done!")
}
15 changes: 6 additions & 9 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package log

import (
"encoding/json"
"github.com/rs/zerolog"
"io"
"net/http"

Expand All @@ -18,33 +17,31 @@ type Logger interface {
Request(msg string, r *http.Request)
}

type Log struct {
*zerolog.Logger
}
type Log struct{}

func NewLogger() *Log {
log.Debug().Msg("Logger started")
return &Log{}
}

func (l Log) Info(msg string) {
l.Logger.Info().Msg(msg)
log.Info().Msg(msg)
}

func (l Log) Debug(msg string) {
l.Logger.Debug().Msg(msg)
log.Debug().Msg(msg)
}

func (l Log) Error(msg string, err error) {
l.Logger.Error().Err(err).Msg(msg)
log.Error().Err(err).Msg(msg)
}

func (l Log) Fatal(msg string, err error) {
l.Logger.Fatal().Err(err).Msg(msg)
log.Fatal().Err(err).Msg(msg)
}

func (l Log) Warn(msg string) {
l.Logger.Warn().Msg(msg)
log.Warn().Msg(msg)
}

func (l Log) Request(msg string, r *http.Request) {
Expand Down

0 comments on commit 9353f43

Please sign in to comment.