Skip to content

Commit

Permalink
add config to enable or disable http logs (#2709)
Browse files Browse the repository at this point in the history
* add config to enable or disable http logs

* update doc
  • Loading branch information
tclemos authored Oct 30, 2023
1 parent 6c79d61 commit 836c456
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ func Test_Defaults(t *testing.T) {
path: "RPC.MaxNativeBlockHashBlockRange",
expectedValue: uint64(60000),
},
{
path: "RPC.EnableHttpLog",
expectedValue: true,
},
{
path: "RPC.WebSockets.Enabled",
expectedValue: true,
Expand Down
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ BatchRequestsLimit = 20
MaxLogsCount = 10000
MaxLogsBlockRange = 10000
MaxNativeBlockHashBlockRange = 60000
EnableHttpLog = true
[RPC.WebSockets]
Enabled = true
Host = "0.0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ GlobalQueue=1024
| - [MaxLogsCount](#RPC_MaxLogsCount ) | No | integer | No | - | MaxLogsCount is a configuration to set the max number of logs that can be returned<br />in a single call to the state, if zero it means no limit |
| - [MaxLogsBlockRange](#RPC_MaxLogsBlockRange ) | No | integer | No | - | MaxLogsBlockRange is a configuration to set the max range for block number when querying TXs<br />logs in a single call to the state, if zero it means no limit |
| - [MaxNativeBlockHashBlockRange](#RPC_MaxNativeBlockHashBlockRange ) | No | integer | No | - | MaxNativeBlockHashBlockRange is a configuration to set the max range for block number when querying<br />native block hashes in a single call to the state, if zero it means no limit |
| - [EnableHttpLog](#RPC_EnableHttpLog ) | No | boolean | No | - | EnableHttpLog allows the user to enable or disable the logs related to the HTTP<br />requests to be captured by the server. |

### <a name="RPC_Host"></a>8.1. `RPC.Host`

Expand Down Expand Up @@ -1022,6 +1023,21 @@ native block hashes in a single call to the state, if zero it means no limit
MaxNativeBlockHashBlockRange=60000
```

### <a name="RPC_EnableHttpLog"></a>8.16. `RPC.EnableHttpLog`

**Type:** : `boolean`

**Default:** `true`

**Description:** EnableHttpLog allows the user to enable or disable the logs related to the HTTP
requests to be captured by the server.

**Example setting the default value** (true):
```
[RPC]
EnableHttpLog=true
```

## <a name="Synchronizer"></a>9. `[Synchronizer]`

**Type:** : `object`
Expand Down
5 changes: 5 additions & 0 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@
"type": "integer",
"description": "MaxNativeBlockHashBlockRange is a configuration to set the max range for block number when querying\nnative block hashes in a single call to the state, if zero it means no limit",
"default": 60000
},
"EnableHttpLog": {
"type": "boolean",
"description": "EnableHttpLog allows the user to enable or disable the logs related to the HTTP\nrequests to be captured by the server.",
"default": true
}
},
"additionalProperties": false,
Expand Down
4 changes: 4 additions & 0 deletions jsonrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ type Config struct {
// MaxNativeBlockHashBlockRange is a configuration to set the max range for block number when querying
// native block hashes in a single call to the state, if zero it means no limit
MaxNativeBlockHashBlockRange uint64 `mapstructure:"MaxNativeBlockHashBlockRange"`

// EnableHttpLog allows the user to enable or disable the logs related to the HTTP
// requests to be captured by the server.
EnableHttpLog bool `mapstructure:"EnableHttpLog"`
}

// WebSocketsConfig has parameters to config the rpc websocket support
Expand Down
8 changes: 6 additions & 2 deletions jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (s *Server) handle(w http.ResponseWriter, req *http.Request) {
respLen = s.handleBatchRequest(req, w, data)
}
metrics.RequestDuration(start)
combinedLog(req, start, http.StatusOK, respLen)
s.combinedLog(req, start, http.StatusOK, respLen)
}

// validateRequest returns a non-zero response code and error message if the
Expand Down Expand Up @@ -517,7 +517,11 @@ func RPCErrorResponseWithData(code int, message string, data *[]byte, err error,
return nil, types.NewRPCErrorWithData(code, message, data)
}

func combinedLog(r *http.Request, start time.Time, httpStatus, dataLen int) {
func (s *Server) combinedLog(r *http.Request, start time.Time, httpStatus, dataLen int) {
if !s.config.EnableHttpLog {
return
}

log.Infof("%s - - %s \"%s %s %s\" %d %d \"%s\" \"%s\"",
r.RemoteAddr,
start.Format("[02/Jan/2006:15:04:05 -0700]"),
Expand Down

0 comments on commit 836c456

Please sign in to comment.