From d74a9942147767aa0635a76c52a3ee82681b687a Mon Sep 17 00:00:00 2001 From: some Date: Sun, 29 Sep 2024 13:15:28 -0400 Subject: [PATCH] Initial release --- .editorconfig | 35 +++++++++++++++++++++++++++++++++++ go.mod | 3 +++ log.go | 15 +++++++++++++++ plain.go | 29 +++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 .editorconfig create mode 100644 go.mod create mode 100644 log.go create mode 100644 plain.go diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0cf80d3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,35 @@ +root = true + +[*] +charset = utf-8 + +end_of_line = LF +insert_final_newline = true +trim_trailing_whitespace = true + +indent_style = space +indent_size = 2 + +[*.sh] +indent_style = space +indent_size = 4 + +[{*.html,*.js,*.css,*.scss}] +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab +indent_size = 8 + +[{{*.,}[Dd]ockerfile{.*,},{*.,}[Cc]ontainerfile{.*,}}] +indent_style = space +indent_size = 4 + +[*.proto] +indent_style = space +indent_size = 2 + +[{*.go,go.mod}] +indent_style = tab +indent_size = 8 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cb46897 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module somehole.com/minecraft/log + +go 1.23.1 diff --git a/log.go b/log.go new file mode 100644 index 0000000..cae4f2a --- /dev/null +++ b/log.go @@ -0,0 +1,15 @@ +package log + +type LogLevel uint8 + +const ( + LevelInfo LogLevel = iota + LevelWarn + LevelError + LevelDebug +) + +type Logger interface { + Log(level LogLevel, msg string) + Logf(level LogLevel, format string, a ...any) +} diff --git a/plain.go b/plain.go new file mode 100644 index 0000000..83c76a5 --- /dev/null +++ b/plain.go @@ -0,0 +1,29 @@ +package log + +import "fmt" + +type PlainLoggerLogLevel LogLevel + +func (level PlainLoggerLogLevel) String() (out string) { + switch level { + case PlainLoggerLogLevel(LevelInfo): + out = "[info]" + case PlainLoggerLogLevel(LevelWarn): + out = "[warn]" + case PlainLoggerLogLevel(LevelError): + out = "[error]" + case PlainLoggerLogLevel(LevelDebug): + out = "[debug]" + } + return +} + +type PlainLogger struct{} + +func (p *PlainLogger) Log(level LogLevel, msg string) { + fmt.Printf("%s %s\n", PlainLoggerLogLevel(level), msg) +} + +func (p *PlainLogger) Logf(level LogLevel, format string, a ...any) { + p.Log(level, fmt.Sprintf(format, a...)) +}