diff --git a/README.md b/README.md index ba64454..73fe27d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main.go b/main.go index 9c4b97b..58eb9cd 100644 --- a/main.go +++ b/main.go @@ -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 } diff --git a/server.go b/server.go index 5116fc5..906cdfb 100644 --- a/server.go +++ b/server.go @@ -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{ diff --git a/struct_config.go b/struct_config.go index 493228c..ee580bb 100644 --- a/struct_config.go +++ b/struct_config.go @@ -17,6 +17,7 @@ type config struct { PortGraphQL int PortMonitoring int HostGraphQL string + AccessLog bool } Client struct {