https://github.com/mdigger/connect-dev-log
A high-performance logging interceptor for ConnectRPC with protocol-agnostic request/response logging, protobuf message formatting, and streaming support.
https://github.com/mdigger/connect-dev-log
connect-rpc connectrpc golang grpc grpc-log interceptor
Last synced: 9 months ago
JSON representation
A high-performance logging interceptor for ConnectRPC with protocol-agnostic request/response logging, protobuf message formatting, and streaming support.
- Host: GitHub
- URL: https://github.com/mdigger/connect-dev-log
- Owner: mdigger
- License: mit
- Created: 2025-06-27T15:00:41.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-06-29T23:41:50.000Z (9 months ago)
- Last Synced: 2025-06-30T00:26:18.687Z (9 months ago)
- Topics: connect-rpc, connectrpc, golang, grpc, grpc-log, interceptor
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# devlog - ConnectRPC Call Logger
[](https://pkg.go.dev/github.com/mdigger/connect-dev-log)
[](LICENSE)
A feature-rich RPC call logger for ConnectRPC with protocol-agnostic support and structured logging capabilities.
## Features
- **Protocol Support**: Works with gRPC, Connect, and gRPC-Web protocols
- **Structured Logging**: Clear formatting for requests, responses, and errors
- **Protobuf Integration**: Built-in support for Protocol Buffer message formatting
- **Header/Metadata Logging**: Optional logging of request/response headers and metadata
- **Error Diagnostics**: Detailed error information including ConnectRPC error codes
- **Streaming Support**: Tracks bidirectional streaming messages with counters
- **Thread-Safe**: Safe for concurrent use across goroutines
- **Customizable**: Configurable timestamp formats, header visibility, and message formatting
## Installation
```bash
go get github.com/mdigger/connect-dev-log
```
## Usage
### Basic Setup
```go
import (
"os"
"connectrpc.com/connect"
devlog "github.com/mdigger/connect-dev-log"
)
func main() {
logger := devlog.New(os.Stdout)
client := connect.NewClient[YourRequest, YourResponse](
http.DefaultClient,
"http://localhost:8080",
connect.WithInterceptors(logger),
)
// Use client as normal...
}
```
### With Custom Options
```go
logger := devlog.New(
os.Stdout,
devlog.WithTimeFormat(time.DateTime),
devlog.WithHeaders(true),
)
```
### Sample Output
```
[2023-11-15T14:23:45.123456Z] /package.Service/Method unary [::1]:54321
Request:
{"field":"value"}
Response:
{"result":"success"}
Completed in: 12.345ms
```
## Configuration Options
| Option | Description | Default |
|--------|-------------|---------|
| `WithTimeFormat` | Sets timestamp format (empty string disables) | `time.RFC3339Nano` |
| `WithHeaders` | Enables/disables header logging | `false` |
| `WithFormatter` | Custom protobuf message formatter | `protojson.MarshalOptions` |
## Streaming Support
The logger provides detailed tracking for streaming RPCs, including:
- Individual message logging for send/receive
- Message counters
- Stream duration metrics
- Client/Server disconnect detection
## Performance Considerations
- Uses a buffer pool to minimize allocations
- Thread-safe implementation with mutex protection
## Limitations
- Client-side streaming logging not yet implemented (`WrapStreamingClient`)
- No built-in log level filtering (handle at writer level)
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.