https://github.com/ringsaturn/mlog
https://github.com/ringsaturn/mlog
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ringsaturn/mlog
- Owner: ringsaturn
- Created: 2024-07-15T02:19:05.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-15T02:22:04.000Z (11 months ago)
- Last Synced: 2025-03-25T05:44:57.199Z (2 months ago)
- Language: Go
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
```go
package mainimport (
"context""github.com/ringsaturn/mlog"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.uber.org/zap"
)func DefaultComponentLevels() map[options.LogComponent]options.LogLevel {
return map[options.LogComponent]options.LogLevel{
options.LogComponentAll: options.LogLevelDebug,
options.LogComponentCommand: options.LogLevelDebug,
options.LogComponentTopology: options.LogLevelDebug,
options.LogComponentServerSelection: options.LogLevelDebug,
options.LogComponentConnection: options.LogLevelDebug,
}
}func main() {
ctx := context.Background()var l, _ = zap.NewDevelopment()
loggerOpts := options.Logger()
loggerOpts.Sink = mlog.New(l)
loggerOpts.ComponentLevels = DefaultComponentLevels()client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017").SetLoggerOptions(loggerOpts))
if err != nil {
panic(err)
}
defer client.Disconnect(ctx)err = client.Ping(ctx, nil)
if err != nil {
panic(err)
}_ = client.Database("wp").Collection("pm25").FindOne(ctx, nil)
}
```