(WIP): Working on the loggers
This commit is contained in:
parent
194c738d07
commit
745a59ecaa
@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/haydenhargreaves/Potion/internal/app/server"
|
import (
|
||||||
|
"github.com/haydenhargreaves/Potion/internal/app/server"
|
||||||
|
"github.com/haydenhargreaves/Potion/internal/infrastructure/logging"
|
||||||
|
"github.com/haydenhargreaves/Potion/internal/infrastructure/logging/loggers"
|
||||||
|
)
|
||||||
|
|
||||||
const PORT = 3000
|
const PORT = 3000
|
||||||
|
|
||||||
@ -8,5 +12,8 @@ func main() {
|
|||||||
s := server.Init(PORT).Setup()
|
s := server.Init(PORT).Setup()
|
||||||
defer s.DB.Close()
|
defer s.DB.Close()
|
||||||
|
|
||||||
|
logger := loggers.NewConsoleLogger()
|
||||||
|
logger.Log(logging.LogLevelDebug, "%s", "Hello world")
|
||||||
|
|
||||||
s.Start()
|
s.Start()
|
||||||
}
|
}
|
||||||
|
|||||||
16
internal/infrastructure/logging/logger.go
Normal file
16
internal/infrastructure/logging/logger.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package logging
|
||||||
|
|
||||||
|
type LogLevel string
|
||||||
|
|
||||||
|
const (
|
||||||
|
LogLevelTrace LogLevel = "TRACE"
|
||||||
|
LogLevelDebug LogLevel = "DEBUG"
|
||||||
|
LogLevelInformation LogLevel = "INFORMATION"
|
||||||
|
LogLevelWarning LogLevel = "WARNING"
|
||||||
|
LogLevelError LogLevel = "ERROR"
|
||||||
|
LogLevelFatal LogLevel = "FATAL"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Logger interface {
|
||||||
|
Log(level LogLevel, format string, v ...any)
|
||||||
|
}
|
||||||
32
internal/infrastructure/logging/loggers/console_logger.go
Normal file
32
internal/infrastructure/logging/loggers/console_logger.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package loggers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/haydenhargreaves/Potion/internal/infrastructure/logging"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: Implement the Logger interface
|
||||||
|
|
||||||
|
type ConsoleLogger struct {
|
||||||
|
writer io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ logging.Logger = (*ConsoleLogger)(nil)
|
||||||
|
|
||||||
|
func NewConsoleLogger() ConsoleLogger {
|
||||||
|
|
||||||
|
return ConsoleLogger{
|
||||||
|
writer: os.Stdout,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ConsoleLogger) Log(level logging.LogLevel, format string, v ...any) {
|
||||||
|
prefix := fmt.Appendf(nil, "[%s] ", level)
|
||||||
|
bytes := fmt.Appendf(prefix, format, v...)
|
||||||
|
|
||||||
|
// WARN: Do we need to worry about errors?
|
||||||
|
_, _ = l.writer.Write(bytes)
|
||||||
|
}
|
||||||
3
internal/infrastructure/logging/loggers/file_logger.go
Normal file
3
internal/infrastructure/logging/loggers/file_logger.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package loggers
|
||||||
|
|
||||||
|
// TODO: Implement the Logger interface
|
||||||
Loading…
x
Reference in New Issue
Block a user