Skip to content

Commit

Permalink
Add ability to enable / disable access log.
Browse files Browse the repository at this point in the history
In high frequency environments it can be a little bit noisy.
  • Loading branch information
lukaszraczylo committed Oct 9, 2023
1 parent 5f44ce7 commit 3b1af9c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ I wanted to monitor the queries and responses of our graphql endpoint, but we di
* `CACHE_TTL` - the cache TTL (default: `60s`)
* `LOG_LEVEL` - the log level (default: `info`)
* `BLOCK_SCHEMA_INTROSPECTION` - blocks the schema introspection (default: `false`)
* `ENABLE_ACCESS_LOG` - enable the access log (default: `false`)

### Caching

Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func parseConfig() {
c.Logger = libpack_logging.NewLogger()
c.Client.GQLClient = graphql.NewConnection()
c.Client.GQLClient.SetEndpoint(c.Server.HostGraphQL)
c.Server.AccessLog = envutil.GetBool("ENABLE_ACCESS_LOG", false)
cfg = &c
enableCache() // takes close to no resources, but can be used with dynamic query cache
}
Expand Down
4 changes: 3 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func processGraphQLRequest(c *fiber.Ctx) error {
}
time_taken := time.Since(t)

cfg.Logger.Info("Request processed", map[string]interface{}{"ip": c.IP(), "user_id": extracted_user_id, "op_type": opType, "op_name": opName, "time": time_taken, "cache": was_cached})
if cfg.Server.AccessLog {
cfg.Logger.Info("Request processed", map[string]interface{}{"ip": c.IP(), "user_id": extracted_user_id, "op_type": opType, "op_name": opName, "time": time_taken, "cache": was_cached})
}
cfg.Monitoring.Increment(libpack_monitoring.MetricsSucceeded, nil)

labels := map[string]string{
Expand Down
1 change: 1 addition & 0 deletions struct_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type config struct {
PortGraphQL int
PortMonitoring int
HostGraphQL string
AccessLog bool
}

Client struct {
Expand Down

0 comments on commit 3b1af9c

Please sign in to comment.