{"id":15157965,"url":"https://github.com/gajus/slonik-interceptor-query-logging","last_synced_at":"2025-09-20T22:31:50.751Z","repository":{"id":34231159,"uuid":"172356175","full_name":"gajus/slonik-interceptor-query-logging","owner":"gajus","description":"Logs Slonik queries.","archived":false,"fork":false,"pushed_at":"2024-05-07T18:30:05.000Z","size":2702,"stargazers_count":12,"open_issues_count":12,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T01:37:26.913Z","etag":null,"topics":["interceptor","logging","middleware","postgresql","slonik"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gajus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-24T15:43:12.000Z","updated_at":"2025-02-11T02:42:59.000Z","dependencies_parsed_at":"2024-05-07T19:49:40.904Z","dependency_job_id":null,"html_url":"https://github.com/gajus/slonik-interceptor-query-logging","commit_stats":{"total_commits":32,"total_committers":4,"mean_commits":8.0,"dds":0.09375,"last_synced_commit":"3423e4d963fc17b5662b8cbc50a8d886d5fcd56b"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/gajus/slonik-interceptor-query-logging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gajus","download_url":"https://codeload.github.com/gajus/slonik-interceptor-query-logging/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fslonik-interceptor-query-logging/sbom","scorecard":{"id":417382,"data":{"date":"2025-08-11","repo":{"name":"github.com/gajus/slonik-interceptor-query-logging","commit":"3423e4d963fc17b5662b8cbc50a8d886d5fcd56b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.8,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":1,"reason":"Found 3/27 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 6 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"48 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-h5c3-5r3r-rr8q","Warn: Project is vulnerable to: GHSA-rmvr-2pp2-xj38","Warn: Project is vulnerable to: GHSA-xx4v-prfh-6cgc","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-23wx-cgxq-vpwx","Warn: Project is vulnerable to: GHSA-f6v4-cf5j-vf3w","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97","Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j","Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22","Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj","Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g","Warn: Project is vulnerable to: GHSA-hj9c-8jmm-8c52","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-x2pg-mjhr-2m5x","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-pgw7-wx7w-2w33","Warn: Project is vulnerable to: GHSA-3cvr-822r-rqcc","Warn: Project is vulnerable to: GHSA-q768-x9m6-m9qp","Warn: Project is vulnerable to: GHSA-8qr4-xgw6-wmr3","Warn: Project is vulnerable to: GHSA-f772-66g8-q5h3","Warn: Project is vulnerable to: GHSA-5r9g-qh6m-jxff","Warn: Project is vulnerable to: GHSA-r6ch-mqf9-qc9w","Warn: Project is vulnerable to: GHSA-wqq4-5wpv-mx2g","Warn: Project is vulnerable to: GHSA-3787-6prv-h9w3","Warn: Project is vulnerable to: GHSA-9qxr-qj54-h672","Warn: Project is vulnerable to: GHSA-m4v8-wqvr-p9f7","Warn: Project is vulnerable to: GHSA-c76h-2ccp-4975","Warn: Project is vulnerable to: GHSA-cxrh-j4jr-qwg3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T00:15:59.717Z","repository_id":34231159,"created_at":"2025-08-19T00:15:59.718Z","updated_at":"2025-08-19T00:15:59.718Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276169317,"owners_count":25596952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-20T02:00:10.207Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interceptor","logging","middleware","postgresql","slonik"],"created_at":"2024-09-26T20:21:19.282Z","updated_at":"2025-09-20T22:31:50.335Z","avatar_url":"https://github.com/gajus.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slonik-interceptor-query-logging\n\n[![Travis build status](http://img.shields.io/travis/gajus/slonik-interceptor-query-logging/master.svg?style=flat-square)](https://travis-ci.com/github/gajus/slonik-interceptor-query-logging)\n[![Coveralls](https://img.shields.io/coveralls/gajus/slonik-interceptor-query-logging.svg?style=flat-square)](https://coveralls.io/github/gajus/slonik-interceptor-query-logging)\n[![NPM version](http://img.shields.io/npm/v/slonik-interceptor-query-logging.svg?style=flat-square)](https://www.npmjs.org/package/slonik-interceptor-query-logging)\n[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)\n[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social\u0026label=Follow)](https://twitter.com/kuizinas)\n\nLogs [Slonik](https://github.com/gajus/slonik) queries.\n\n\u003e [!WARNING]\n\u003e Deprecated in favor of https://github.com/gajus/slonik monorepo.\n\n## API\n\n```ts\nimport {\n  createQueryLoggingInterceptor\n} from 'slonik-interceptor-query-logging';\n```\n\n```ts\n/**\n * @property logValues Dictates whether to include parameter values used to execute the query. (default: true)\n */\ntype UserConfigurationType = {|\n  +logValues: boolean\n|};\n\n(userConfiguration: UserConfigurationType) =\u003e InterceptorType;\n```\n\n## Example usage\n\nNote: You must export `ROARR_LOG=true` environment variable for logs to be printed. Refer to [Roarr](https://github.com/gajus/roarr) documentation for more information.\n\n```ts\nimport {\n  createPool\n} from 'slonik';\nimport {\n  createQueryLoggingInterceptor\n} from 'slonik-interceptor-query-logging';\n\nconst interceptors = [\n  createQueryLoggingInterceptor()\n];\n\nconst pool = createPool('postgres://', {\n  interceptors\n});\n\nawait connection.any(sql`\n  SELECT\n    id,\n    code_alpha_2\n  FROM country\n`);\n```\n\nProduces log:\n\n```json\n{\"context\":{\"package\":\"slonik\",\"poolId\":\"01D4G1EHYPYX1DZ073G08QEPED\",\"logLevel\":30,\"processId\":769420982,\"stats\":{\"idleConnectionCount\":0,\"totalConnectionCount\":1,\"waitingRequestCount\":0}},\"message\":\"created a new client connection\",\"sequence\":0,\"time\":1551021590799,\"version\":\"1.0.0\"}\n{\"context\":{\"package\":\"slonik\",\"poolId\":\"01D4G1EHYPYX1DZ073G08QEPED\",\"logLevel\":30,\"processId\":769420982,\"stats\":{\"idleConnectionCount\":0,\"totalConnectionCount\":1,\"waitingRequestCount\":0}},\"message\":\"client is checked out from the pool\",\"sequence\":1,\"time\":1551021590801,\"version\":\"1.0.0\"}\n{\"context\":{\"package\":\"slonik\",\"poolId\":\"01D4G1EHYPYX1DZ073G08QEPED\",\"connectionId\":\"01D4G1EJ8DZFX79EN8CRE5Z7VS\",\"queryId\":\"01D4G1EJB9P3SJ3V0SSVRTZ800\",\"logLevel\":20,\"sql\":\"SELECT id, code_alpha_2 FROM country\",\"stackTrace\":[],\"values\":[]},\"message\":\"executing query\",\"sequence\":2,\"time\":1551021590890,\"version\":\"1.0.0\"}\n{\"context\":{\"package\":\"slonik\",\"poolId\":\"01D4G1EHYPYX1DZ073G08QEPED\",\"connectionId\":\"01D4G1EJ8DZFX79EN8CRE5Z7VS\",\"queryId\":\"01D4G1EJB9P3SJ3V0SSVRTZ800\",\"logLevel\":20,\"executionTime\":\"65ms\",\"rowCount\":250},\"message\":\"query execution result\",\"sequence\":3,\"time\":1551021590918,\"version\":\"1.0.0\"}\n{\"context\":{\"package\":\"slonik\",\"poolId\":\"01D4G1EHYPYX1DZ073G08QEPED\",\"logLevel\":30,\"processId\":769420982,\"stats\":{\"idleConnectionCount\":0,\"totalConnectionCount\":0,\"waitingRequestCount\":0}},\"message\":\"client connection is closed and removed from the client pool\",\"sequence\":4,\"time\":1551021600922,\"version\":\"1.0.0\"}\n```\n\nUse [`roarr-cli`](https://github.com/gajus/roarr-cli) to pretty print the logs.\n\nUsing `roarr pretty-print` will produce logs in the following format:\n\n```yaml\n[2019-02-24T15:19:50.799Z] INFO (30) (@slonik): created a new client connection\npoolId:    01D4G1EHYPYX1DZ073G08QEPED\nprocessId: 769420982\nstats:\n  idleConnectionCount:  0\n  totalConnectionCount: 1\n  waitingRequestCount:  0\n\n[2019-02-24T15:19:50.801Z] INFO (30) (@slonik): client is checked out from the pool\npoolId:    01D4G1EHYPYX1DZ073G08QEPED\nprocessId: 769420982\nstats:\n  idleConnectionCount:  0\n  totalConnectionCount: 1\n  waitingRequestCount:  0\n\n[2019-02-24T15:19:50.890Z] DEBUG (20) (@slonik): executing query\npoolId:       01D4G1EHYPYX1DZ073G08QEPED\nconnectionId: 01D4G1EJ8DZFX79EN8CRE5Z7VS\nqueryId:      01D4G1EJB9P3SJ3V0SSVRTZ800\nsql:          SELECT id, code_alpha_2 FROM country\nstackTrace:\n  (empty array)\nvalues:\n  (empty array)\n\n[2019-02-24T15:19:50.918Z] DEBUG (20) (@slonik): query execution result\npoolId:        01D4G1EHYPYX1DZ073G08QEPED\nconnectionId:  01D4G1EJ8DZFX79EN8CRE5Z7VS\nqueryId:       01D4G1EJB9P3SJ3V0SSVRTZ800\nexecutionTime: 65ms\nrowCount:      250\n\n[2019-02-24T15:20:00.922Z] INFO (30) (@slonik): client connection is closed and removed from the client pool\npoolId:    01D4G1EHYPYX1DZ073G08QEPED\nprocessId: 769420982\nstats:\n  idleConnectionCount:  0\n  totalConnectionCount: 0\n  waitingRequestCount:  0\n```\n\n## Logging `auto_explain`\n\n`executionTime` log property describes how long it took for the client to execute the query, i.e. it includes the overhead of waiting for a connection and the network latency, among other things. However, it is possible to get the real query execution time by using [`auto_explain` module](https://www.postgresql.org/docs/current/auto-explain.html).\n\nThere are several pre-requisites:\n\n```sql\n-- Load the extension.\nLOAD 'auto_explain';\n-- or (if you are using AWS RDS):\nLOAD '$libdir/plugins/auto_explain';\n\n-- Enable logging of all queries.\nSET auto_explain.log_analyze=true;\nSET auto_explain.log_format=json;\nSET auto_explain.log_min_duration=0;\nSET auto_explain.log_timing=true;\n\n-- Enables Slonik to capture auto_explain logs.\nSET client_min_messages=log;\n```\n\nThis can be configured using `afterPoolConnection` interceptor, e.g.\n\n```ts\nconst pool = createPool('postgres://localhost', {\n  interceptors: [\n    {\n      afterPoolConnection: async (connection) =\u003e {\n        await connection.query(sql`LOAD 'auto_explain'`);\n        await connection.query(sql`SET auto_explain.log_analyze=true`);\n        await connection.query(sql`SET auto_explain.log_format=json`);\n        await connection.query(sql`SET auto_explain.log_min_duration=0`);\n        await connection.query(sql`SET auto_explain.log_timing=true`);\n        await connection.query(sql`SET client_min_messages=log`);\n      }\n    }\n  ]\n});\n\n```\n\nSlonik logging interceptor recognises and parses the `auto_explain` JSON message e.g.\n\n```yaml\n[2018-12-31T21:15:21.010Z] INFO (30) (@slonik): notice message\nnotice:\n  level:   notice\n  message:\n    Query Text: SELECT count(*) FROM actor\n    Plan:\n      Node Type:           Aggregate\n      Strategy:            Plain\n      Partial Mode:        Simple\n      Parallel Aware:      false\n      Startup Cost:        4051.33\n      Total Cost:          4051.34\n      Plan Rows:           1\n      Plan Width:          8\n      Actual Startup Time: 26.791\n      Actual Total Time:   26.791\n      Actual Rows:         1\n      Actual Loops:        1\n      Plans:\n        -\n          Node Type:           Seq Scan\n          Parent Relationship: Outer\n          Parallel Aware:      false\n          Relation Name:       actor\n          Alias:               actor\n          Startup Cost:        0\n          Total Cost:          3561.86\n          Plan Rows:           195786\n          Plan Width:          0\n          Actual Startup Time: 0.132\n          Actual Total Time:   15.29\n          Actual Rows:         195786\n          Actual Loops:        1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fslonik-interceptor-query-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgajus%2Fslonik-interceptor-query-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fslonik-interceptor-query-logging/lists"}