{"id":16426301,"url":"https://github.com/probablyarth/flush","last_synced_at":"2026-06-08T21:31:33.728Z","repository":{"id":256840759,"uuid":"856583125","full_name":"probablyArth/flush","owner":"probablyArth","description":"flush logs somewhere with first class plugins support","archived":false,"fork":false,"pushed_at":"2024-09-15T13:39:44.000Z","size":141,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T03:23:56.342Z","etag":null,"topics":["log","logging","logs","plugins","ts","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@probablyarth/flush","language":"TypeScript","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/probablyArth.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":"2024-09-12T20:34:32.000Z","updated_at":"2024-10-04T14:19:31.000Z","dependencies_parsed_at":"2024-11-10T12:45:54.137Z","dependency_job_id":null,"html_url":"https://github.com/probablyArth/flush","commit_stats":null,"previous_names":["probablyarth/flush"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/probablyArth/flush","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probablyArth%2Fflush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probablyArth%2Fflush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probablyArth%2Fflush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probablyArth%2Fflush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/probablyArth","download_url":"https://codeload.github.com/probablyArth/flush/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probablyArth%2Fflush/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34082130,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"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":["log","logging","logs","plugins","ts","typescript"],"created_at":"2024-10-11T08:08:25.524Z","updated_at":"2026-06-08T21:31:33.711Z","avatar_url":"https://github.com/probablyArth.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flush\n\nThe Flush processor is a TypeScript package designed to handle log message processing at different log levels, with the ability to offload the processing to different output systems. By default, it logs messages to the console, but it can be easily extended to other output systems such as file storage, cloud logging, or custom destinations..\n\n# Features\n\n- Log Level Filtering: Only log messages above a defined level are processed.\n- Customizable Processors: Ability to use custom processors for different logging needs (e.g., cloud, files, etc.).\n- Timestamp Handling: Automatically appends a timestamp to each log message if not provided.\n- Extensible Design: Easily extend the OffloadProcessor to implement custom logging behavior.\n\n# Installation\n\nTo install the package, run the following:\n\n```bash\nnpm install @probablyarth/flush\n```\n\n# Usage\n\n### Basic Setup\n\nHere’s how you can use the package for basic logging with console output:\n\n```typescript\nimport { Flush } from '@probablyarth/flush';\n\n// Create a new instance of Flush and set the log level\nconst flush = new Flush\u003c{ user: string }\u003e('debug');\n\n// Log a message with metadata\nflush.flush({\n  level: 'debug',\n  message: 'This is an info log',\n  metadata: { user: 'John Doe' },\n});\n```\n\n### Custom Processor\n\nYou can easily create your own processor by extending the OffloadProcessor class and overriding its methods. For example, here’s how to log messages to a custom storage:\n\n```typescript\nimport { OffloadProcessor } from '@probablyarth/flush';\n\nclass CustomProcessor\u003cM\u003e implements OffloadProcessor\u003cM\u003e {\n  async process(input: Input\u003cM\u003e) {\n    // Replace this with custom logic (e.g., saving to a file or cloud service)\n    console.log(`Custom Processor: [${input.level}] ${input.message}`);\n  }\n\n  async onCompleted(_: undefined): Promise\u003cvoid\u003e {\n    // Custom completion logic\n    return;\n  }\n\n  async onError(error: Error): Promise\u003cvoid\u003e {\n    // Custom error handling logic\n    console.error('Error in processing: ', error);\n  }\n}\n\n// Use the custom processor\nconst customFlush = new Flush\u003c{ issue: string }\u003e(\n  'debug',\n  new CustomProcessor()\n);\ncustomFlush.flush({\n  level: 'warn',\n  message: 'This is a warning with custom processor',\n  metadata: { issue: 'High Memory Usage' },\n});\n```\n\n# Log Levels\n\nThe package uses a predefined set of log levels, each with a corresponding priority. You can set the log level on the Flush class to filter out messages that do not meet the priority threshold.\n\n```typescript\nLEVELS = {\n  DEBUG: { level: 0 },\n  WARN: { level: 1 },\n  ERROR: { level: 2 },\n};\n```\n\nWhen you flush a message, only those at or above the defined log level will be processed.\n\n# API\n\n### `ConsoleProcessor\u003cM\u003e`\n\nA simple processor that logs messages to the console.\n\n- process(input: Input\u003cM\u003e): Logs the message and metadata.\n- onCompleted(\\_: undefined): Placeholder method that does nothing.\n- onError(error: Error): Handles error during processing.\n\n### `Flush\u003cM\u003e`\n\nThe core class that controls the flushing of log messages based on log levels.\n\nConstructor\n\n```typescript\nnew Flush(level: Level, processor: OffloadProcessor\u003cM\u003e = new ConsoleProcessor\u003cM\u003e())\n```\n\n- level: The minimum log level required to process a log.\n- processor: An optional custom processor to handle log output. Defaults to ConsoleProcessor.\n  `flush(input: PartialMember\u003cInput\u003cM\u003e, 'timestamp'\u003e)`\n\nProcesses a log entry if it meets the log level threshold. Automatically appends a timestamp if one isn’t provided.\n\n- `input`: Log entry object, requires `level`, `message`, and `metadata`. The `timestamp` is optional.\n\n# Contributing\n\nContributions are welcome! If you find any issues or have feature suggestions, feel free to open an issue or a pull request on GitHub.\n\n# License\n\nThis project is licensed under the MIT License.\n\n---\n\nHappy Logging!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprobablyarth%2Fflush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprobablyarth%2Fflush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprobablyarth%2Fflush/lists"}