Skip to content

Commit 81cb4eb

Browse files
committed
docs: updated datafx's README.
1 parent 959693e commit 81cb4eb

File tree

8 files changed

+30
-36
lines changed

8 files changed

+30
-36
lines changed

connfx/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ import (
4444

4545
func main() {
4646
// Create logger using logfx
47-
logger := logfx.NewLogger(os.Stdout, &logfx.Config{
48-
Level: "INFO",
49-
PrettyMode: true,
50-
})
47+
logger := logfx.NewLoggerWithDefaults()
5148

5249
// Create connection registry
5350
registry := connfx.NewRegistryWithDefaults(logger)

datafx/README.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,27 @@ datafx depends on connfx for connection management. You configure connections th
2323
### Connection Configuration (via connfx)
2424

2525
```go
26-
// Redis configuration example
26+
// Redis/Valkey configuration example
2727
redisConfig := &connfx.ConfigTarget{
2828
Protocol: "redis",
29-
Host: "localhost",
30-
Port: 6379,
3129
DSN: "redis://localhost:6379",
3230
}
3331

3432
// PostgreSQL configuration example
3533
postgresConfig := &connfx.ConfigTarget{
3634
Protocol: "postgres",
37-
Host: "localhost",
38-
Port: 5432,
3935
DSN: "postgres://user:pass@localhost:5432/dbname",
4036
}
4137

4238
// MongoDB configuration example
4339
mongoConfig := &connfx.ConfigTarget{
4440
Protocol: "mongodb",
45-
Host: "localhost",
46-
Port: 27017,
4741
DSN: "mongodb://localhost:27017/mydb",
4842
}
4943

5044
// AMQP/RabbitMQ configuration example
5145
amqpConfig := &connfx.ConfigTarget{
5246
Protocol: "amqp",
53-
Host: "localhost",
54-
Port: 5672,
5547
DSN: "amqp://guest:guest@localhost:5672/",
5648
}
5749
```
@@ -78,10 +70,10 @@ type Product struct {
7870

7971
// Example message types for queues
8072
type OrderEvent struct {
81-
OrderID string `json:"order_id"`
82-
CustomerID string `json:"customer_id"`
83-
Amount float64 `json:"amount"`
84-
Timestamp time.Time `json:"timestamp"`
73+
OrderID string `json:"order_id"`
74+
CustomerID string `json:"customer_id"`
75+
Amount float64 `json:"amount"`
76+
Timestamp time.Time `json:"timestamp"`
8577
}
8678

8779
type NotificationMessage struct {
@@ -121,14 +113,12 @@ func main() {
121113
ctx := context.Background()
122114

123115
// Setup connection registry
124-
logger := logfx.NewLogger(os.Stdout, &logfx.Config{Level: logfx.LevelInfo})
116+
logger := logfx.NewLoggerWithDefaults()
125117
registry := connfx.NewRegistryWithDefaults(logger)
126118

127119
// Configure connection
128120
config := &connfx.ConfigTarget{
129121
Protocol: "redis",
130-
Host: "localhost",
131-
Port: 6379,
132122
DSN: "redis://localhost:6379",
133123
}
134124

@@ -323,7 +313,7 @@ func main() {
323313
ctx := context.Background()
324314

325315
// Setup connection registry
326-
logger := logfx.NewLogger(os.Stdout, &logfx.Config{Level: logfx.LevelInfo})
316+
logger := logfx.NewLoggerWithDefaults()
327317
registry := connfx.NewRegistryWithDefaults(logger)
328318

329319
// Configure AMQP connection

httpfx/http_service_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"net"
77
"net/http"
8-
"os"
98
"testing"
109
"time"
1110

@@ -86,7 +85,7 @@ func TestNewHTTPService(t *testing.T) { //nolint:funlen
8685
t.Run(tt.name, func(t *testing.T) {
8786
t.Parallel()
8887

89-
logger := logfx.NewLogger(os.Stdout, &logfx.Config{}) //nolint:exhaustruct
88+
logger := logfx.NewLoggerWithDefaults()
9089

9190
router := httpfx.NewRouter("/")
9291
metricsProvider := setupTestMetricsProvider(t)
@@ -121,7 +120,7 @@ func TestNewHTTPService(t *testing.T) { //nolint:funlen
121120
func TestHTTPService_Start(t *testing.T) { //nolint:funlen
122121
t.Parallel()
123122

124-
logger := logfx.NewLogger(os.Stdout, &logfx.Config{}) //nolint:exhaustruct
123+
logger := logfx.NewLoggerWithDefaults()
125124

126125
router := httpfx.NewRouter("/")
127126
metricsProvider := setupTestMetricsProvider(t)

logfx/level.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const (
2424
LevelPanic slog.Level = slog.Level(16)
2525
)
2626

27+
const DefaultLogLevel = "INFO"
28+
2729
func LevelEncoder(l slog.Level) string {
2830
str := func(base string, val slog.Level) string {
2931
if val == 0 {

logfx/logger.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"io"
66
"log/slog"
7+
"os"
78
)
89

910
type Logger struct {
@@ -26,17 +27,20 @@ func NewLogger(w io.Writer, config *Config) *Logger {
2627
return logger
2728
}
2829

29-
func NewLoggerAsDefault(w io.Writer, config *Config) *Logger {
30-
logger := NewLogger(w, config)
31-
slog.SetDefault(logger.Logger)
32-
33-
return logger
30+
func NewLoggerWithDefaults() *Logger {
31+
return NewLogger(os.Stdout, &Config{ //nolint:exhaustruct
32+
Level: DefaultLogLevel,
33+
})
3434
}
3535

3636
func NewLoggerFromSlog(slog *slog.Logger) *Logger {
3737
return &Logger{Logger: slog}
3838
}
3939

40+
func (l *Logger) SetAsDefault() {
41+
slog.SetDefault(l.Logger)
42+
}
43+
4044
// Trace logs at [LevelTrace].
4145
func (l *Logger) Trace(msg string, args ...any) {
4246
l.Log(context.Background(), LevelTrace, msg, args...)

processfx/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
func main() {
3232
ctx := context.Background()
33-
logger := logfx.NewLogger(os.Stdout, &logfx.Config{Level: "info"})
33+
logger := logfx.NewLoggerWithDefaults()
3434

3535
// Create process manager
3636
process := processfx.New(ctx, logger)
@@ -73,7 +73,7 @@ func main() {
7373
```go
7474
func main() {
7575
ctx := context.Background()
76-
logger := logfx.NewLogger(os.Stdout, &logfx.Config{Level: "info"})
76+
logger := logfx.NewLoggerWithDefaults()
7777

7878
process := processfx.New(ctx, logger)
7979

@@ -204,7 +204,7 @@ ProcessFX automatically handles these OS signals:
204204
```go
205205
func runApplication() {
206206
ctx := context.Background()
207-
logger := logfx.NewLogger(os.Stdout, &logfx.Config{Level: "info"})
207+
logger := logfx.NewLoggerWithDefaults()
208208

209209
process := processfx.New(ctx, logger)
210210

@@ -264,7 +264,7 @@ func runApplication() {
264264
```go
265265
func runWithDatabase() {
266266
ctx := context.Background()
267-
logger := logfx.NewLogger(os.Stdout, &logfx.Config{Level: "info"})
267+
logger := logfx.NewLoggerWithDefaults()
268268

269269
process := processfx.New(ctx, logger)
270270

@@ -309,7 +309,7 @@ func runWithDatabase() {
309309
```go
310310
func runHTTPServer() {
311311
ctx := context.Background()
312-
logger := logfx.NewLogger(os.Stdout, &logfx.Config{Level: "info"})
312+
logger := logfx.NewLoggerWithDefaults()
313313

314314
process := processfx.New(ctx, logger)
315315

sampleapp/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ The application uses structured logging with LogFX:
292292

293293
```go
294294
// Create logger with configuration
295-
logger := logfx.NewLoggerAsDefault(os.Stdout, &config.Log)
295+
logger := logfx.NewLogger(os.Stdout, &config.Log)
296+
logger.SetAsDefault()
296297

297298
// Use throughout the application
298299
logger.Info("Application started",

sampleapp/appcontext.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func NewAppContext(ctx context.Context) (*AppContext, error) {
3636
}
3737

3838
// logger
39-
appContext.Logger = logfx.NewLoggerAsDefault(os.Stdout, &appContext.Config.Log)
39+
appContext.Logger = logfx.NewLogger(os.Stdout, &appContext.Config.Log)
40+
appContext.Logger.SetAsDefault()
4041

4142
// metrics
4243
appContext.Metrics = metricsfx.NewMetricsProvider(appContext.Metrics)

0 commit comments

Comments
 (0)