Nik Afiq 657b6aeb22 feat: implement initial application structure with health and hello endpoints
- Add bootstrap package to initialize application components including logger, tracer, and HTTP server.
- Create config package to load runtime settings from environment variables.
- Implement observability features including logging, metrics, and tracing.
- Add health check and hello use cases with corresponding HTTP handlers.
- Introduce middleware for request ID, access logging, metrics, and recovery.
- Set up HTTP router with defined routes for health and hello endpoints.
- Include tests for health and hello endpoints to ensure proper functionality.
- Add OpenTelemetry collector configuration for trace exporting.
2026-03-05 21:22:43 +09:00

34 lines
693 B
Go

package observability
import (
"fmt"
"log/slog"
"os"
"strings"
)
func NewLogger(level string) (*slog.Logger, error) {
parsed, err := parseLevel(level)
if err != nil {
return nil, err
}
handler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: parsed})
return slog.New(handler), nil
}
func parseLevel(level string) (slog.Level, error) {
switch strings.ToLower(strings.TrimSpace(level)) {
case "debug":
return slog.LevelDebug, nil
case "info", "":
return slog.LevelInfo, nil
case "warn", "warning":
return slog.LevelWarn, nil
case "error":
return slog.LevelError, nil
default:
return slog.LevelInfo, fmt.Errorf("unsupported LOG_LEVEL: %s", level)
}
}