{"id":26989931,"url":"https://github.com/fdesjardins/bunyan-postgres-stream","last_synced_at":"2025-04-03T21:22:55.708Z","repository":{"id":10213516,"uuid":"64987383","full_name":"fdesjardins/bunyan-postgres-stream","owner":"fdesjardins","description":"A bunyan stream for PostgreSQL","archived":false,"fork":false,"pushed_at":"2023-01-11T02:35:16.000Z","size":1357,"stargazers_count":3,"open_issues_count":18,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T22:04:47.419Z","etag":null,"topics":["bunyan","bunyan-stream","logging","nodejs","postgresql"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fdesjardins.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}},"created_at":"2016-08-05T03:59:00.000Z","updated_at":"2023-08-26T13:47:37.000Z","dependencies_parsed_at":"2023-01-13T15:48:25.793Z","dependency_job_id":null,"html_url":"https://github.com/fdesjardins/bunyan-postgres-stream","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdesjardins%2Fbunyan-postgres-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdesjardins%2Fbunyan-postgres-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdesjardins%2Fbunyan-postgres-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdesjardins%2Fbunyan-postgres-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fdesjardins","download_url":"https://codeload.github.com/fdesjardins/bunyan-postgres-stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246847130,"owners_count":20843442,"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","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":["bunyan","bunyan-stream","logging","nodejs","postgresql"],"created_at":"2025-04-03T21:22:55.056Z","updated_at":"2025-04-03T21:22:55.702Z","avatar_url":"https://github.com/fdesjardins.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bunyan-postgres-stream\n\n[![Build Status](https://travis-ci.org/fdesjardins/bunyan-postgres-stream.svg?branch=master)](https://travis-ci.org/fdesjardins/bunyan-postgres-stream)\n[![NPM Version](http://img.shields.io/npm/v/bunyan-postgres-stream.svg?style=flat)](https://www.npmjs.org/package/bunyan-postgres-stream)\n[![Coverage Status](https://coveralls.io/repos/github/fdesjardins/bunyan-postgres-stream/badge.svg?branch=master)](https://coveralls.io/github/fdesjardins/bunyan-postgres-stream?branch=master)\n\nStore your Bunyan logs in PostgreSQL.\n\nThis module creates a Bunyan stream that maps the default log fields to table columns and also records the entire log message in a `jsonb` column to support your custom fields.\n\nRequires PostgreSQL 9.4 or above for use with `jsonb` column types.\n\n## Install\n\n```\n$ npm install --save bunyan-postgres-stream\n```\n\n## Usage\n\nFirst, create the table you want to store your logs in:\n\n```sql\ncreate table if not exists \"public\".\"logs\" (\n  \"id\" serial primary key,\n  \"name\" text,\n  \"level\" integer,\n  \"hostname\" text,\n  \"msg\" text,\n  \"pid\" integer,\n  \"time\" timestamptz,\n  \"content\" jsonb\n)\n```\n\nThen, use the package as a Bunyan stream:\n\n```js\nconst bunyan = require('bunyan')\nconst bunyanPostgresStream = require('./')\n\nconst stream = bunyanPostgresStream({\n  connection: {\n    host: 'localhost',\n    user: 'postgres',\n    password: 'password',\n    database: 'db'\n  },\n  tableName: 'logs'\n})\n\nconst log = bunyan.createLogger({\n  name: 'postgres stream',\n  level: 'info',\n  stream\n})\n\nlog.info('something happened')\n\n// explicity dispose of the database connection pool\nstream.end()\n```\n\n## API\n\n### bunyanPostgresStream(options)\n\n#### options\n\n##### connection\n\nType: `object`\n\nOne of the following:\n\n- a valid node-postgres connection options object\n- an initialized knex.js instance (see [examples/knex.js](./examples/knex.js))\n\n##### tableName\n\nType: `string`\n\nThe name of the table that will contain the logs.\n\n## Contributing\n\nPull requests welcome.\n\n## License\n\nMIT © [Forrest Desjardins](https://github.com/fdesjardins)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdesjardins%2Fbunyan-postgres-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffdesjardins%2Fbunyan-postgres-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdesjardins%2Fbunyan-postgres-stream/lists"}