Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/log.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ output:
level: INFO
- type: stdout
level: INFO
directory: ./logs/
directory: ../logs/

components:
- app
Expand Down
7 changes: 6 additions & 1 deletion src/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"log/slog"
log2 "mist/multilogger"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -114,7 +115,11 @@ func (a *App) Shutdown(ctx context.Context) error {
}

func main() {
log, err := createLogger("app")
cfg, err := log2.GetLogConfig()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get log config: %v\n", err)
}
log, err := log2.CreateLogger("app", &cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create logger: %v\n", err)
os.Exit(1)
Expand Down
1 change: 1 addition & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ require github.com/redis/go-redis/v9 v9.10.0
require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cu
github.com/redis/go-redis/v9 v9.10.0 h1:FxwK3eV8p/CQa0Ch276C7u2d0eNC9kCmAYQ7mCXCzVs=
github.com/redis/go-redis/v9 v9.10.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7 changes: 5 additions & 2 deletions src/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"context"
"fmt"
"log/slog"
"mist/multilogger"
"os"
"os/signal"
"sync"
Expand Down Expand Up @@ -54,7 +56,8 @@ func TestIntegration(t *testing.T) {
defer os.Unsetenv("ENV")

redisAddr := "localhost:6379"
schedulerLog, err := createLogger("scheduler")
config, _ := multilogger.GetLogConfig()
schedulerLog, err := multilogger.CreateLogger("scheduler", &config)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create logger: %v\n", err)
os.Exit(1)
Expand All @@ -68,7 +71,7 @@ func TestIntegration(t *testing.T) {
scheduler := NewScheduler(redisAddr, schedulerLog)
defer scheduler.Close()

supervisorLog, err := createLogger("supervisor")
supervisorLog, err := multilogger.CreateLogger("supervisor", &config)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create logger: %v\n", err)
os.Exit(1)
Expand Down
141 changes: 0 additions & 141 deletions src/log.go

This file was deleted.

1 change: 0 additions & 1 deletion src/log_test.go

This file was deleted.

44 changes: 44 additions & 0 deletions src/multilogger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# multilogger

`multilogger` lets you log to multiple io.Writer instances at once, with JSON structured logs, file rotation, and flexible metadata.

---

## Overview


Multilogger allows you to write logs to multiple io.Writer targets (e.g. stdout, files, etc.) simultaneously, each with its own log level.
It’s ideal for tracking runtime activity across components such as schedulers, supervisors, and the main application.
If the configuration fails or a destination cannot be initialized, multilogger automatically falls back to a stderr logger.
File rotation is handled using [lumberjack](https://github.com/natefinch/lumberjack). Environment variables are able to override the log levels configured in the log.yaml file.

---

## Example Usage
```go
// Create Multilogger
config := multilogger.GetLogConfig()
logger, _ := multilogger.CreateLogger("app", &config)
logger.Info("starting app")
```

```go
// Set Global Log Level
os.Setenv("LOG_LEVEL", "DEBUG")
```

```go
// Configure Log Levels By io.Writer
os.Setenv("FILE_LOG_LEVEL", "DEBUG")
os.Setenv("STDOUT_LOG_LEVEL", "INFO")
```

```go
// Add Metadata
config := multilogger.GetLogConfig()
logger, _ := multilogger.CreateLogger("app", &config)
logger = logger.WithGroup("jobInfo")
logger.Info("job started", "job_id", "abc123")
```

---
Loading