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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master

- Add `log_rpc` config option (default: `true`) to suppress per-request RPC trace logs. ([@noah44846][])

## 1.6.4 (2026-04-02)

- Require MFA to publish the gem.
Expand Down
10 changes: 10 additions & 0 deletions docs/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ AnyCable.logger = MyLogger.new

**IMPORTANT:** When using with Rails, AnyCable automatically sets its logger to `Rails.logger`, so AnyCable-specific logging options are no-op.

## Suppressing RPC trace logs

Per-request RPC trace logs (connect/command/disconnect and broadcast enqueue/perform) can be suppressed with `log_rpc`:

```sh
$ ANYCABLE_LOG_RPC=false bundle exec anycable

This is useful when using with Rails, where AnyCable.logger is replaced by Rails.logger and log_level has no effect on AnyCable-specific logs. Errors are always logged regardless of this setting.
```

## gRPC logging

AnyCable does not log any GRPC internal events by default. You can turn GRPC logger on by setting `log_grpc` parameter to true:
Expand Down
4 changes: 2 additions & 2 deletions lib/anycable/broadcast_adapters/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def initialize(url: AnyCable.config.http_broadcast_url, secret: AnyCable.config.

def raw_broadcast(payload)
ensure_thread_is_alive
AnyCable.logger.info "Enqueue: #{payload}"
AnyCable.logger.info "Enqueue: #{payload}" if AnyCable.config.log_rpc?
queue << payload
end

Expand Down Expand Up @@ -102,7 +102,7 @@ def perform_request(payload)
build_http do |http|
req = Net::HTTP::Post.new(url, {"Content-Type" => "application/json"}.merge(headers))
req.body = payload
AnyCable.logger.info "Perform: #{payload}"
AnyCable.logger.info "Perform: #{payload}" if AnyCable.config.log_rpc?
http.request(req)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/anycable/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def usages
### Logging options
log_file: nil,
log_level: "info",
log_rpc: true, # Set to false to suppress per-request RPC trace logs (connect/command/disconnect/broadcast). Errors are always logged.
debug: false, # Shortcut to enable debug level and verbose logging

### Health check options
Expand Down
2 changes: 1 addition & 1 deletion lib/anycable/rpc/handlers/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module RPC
module Handlers
module Command
def command(message)
logger.debug("RPC Command: #{message.inspect}")
logger.debug("RPC Command: #{message.inspect}") if AnyCable.config.log_rpc?

socket = build_socket(env: message.env)

Expand Down
2 changes: 1 addition & 1 deletion lib/anycable/rpc/handlers/connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module RPC
module Handlers
module Connect
def connect(request)
logger.debug("RPC Connect: #{request.inspect}")
logger.debug("RPC Connect: #{request.inspect}") if AnyCable.config.log_rpc?

socket = build_socket(env: request.env)

Expand Down
2 changes: 1 addition & 1 deletion lib/anycable/rpc/handlers/disconnect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module RPC
module Handlers
module Disconnect
def disconnect(request)
logger.debug("RPC Disconnect: #{request.inspect}")
logger.debug("RPC Disconnect: #{request.inspect}") if AnyCable.config.log_rpc?

socket = build_socket(env: request.env)

Expand Down