{"id":24908530,"url":"https://github.com/stacksjs/clarity","last_synced_at":"2026-04-27T22:01:11.510Z","repository":{"id":275296057,"uuid":"925639612","full_name":"stacksjs/clarity","owner":"stacksjs","description":"🔎  Modern debugging \u0026 logging library. For server \u0026 browser.","archived":false,"fork":false,"pushed_at":"2026-04-21T22:23:07.000Z","size":21754,"stargazers_count":4,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-22T00:28:49.088Z","etag":null,"topics":["debug","debugger","library","logger","logging","typescript"],"latest_commit_sha":null,"homepage":"https://stacks-clarity.netlify.app","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/stacksjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["stacksjs","chrisbbreuer"],"open_collective":"stacksjs"}},"created_at":"2025-02-01T11:20:18.000Z","updated_at":"2026-04-21T14:57:11.000Z","dependencies_parsed_at":"2025-02-01T14:24:19.551Z","dependency_job_id":"0943ab14-3331-4feb-b7a0-d1e111ca5cd4","html_url":"https://github.com/stacksjs/clarity","commit_stats":null,"previous_names":["stacksjs/clarity"],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/stacksjs/clarity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fclarity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fclarity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fclarity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fclarity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stacksjs","download_url":"https://codeload.github.com/stacksjs/clarity/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fclarity/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32354686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"ssl_error","status_checked_at":"2026-04-27T20:07:00.910Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["debug","debugger","library","logger","logging","typescript"],"created_at":"2025-02-02T02:20:15.093Z","updated_at":"2026-04-27T22:01:11.504Z","avatar_url":"https://github.com/stacksjs.png","language":"TypeScript","funding_links":["https://github.com/sponsors/stacksjs","https://github.com/sponsors/chrisbbreuer","https://opencollective.com/stacksjs"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\".github/art/cover.jpg\" alt=\"Social Card of this repo\"\u003e\u003c/p\u003e\n\n[![npm version][npm-version-src]][npm-version-href]\n[![GitHub Actions][github-actions-src]][github-actions-href]\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n\u003c!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] --\u003e\n\u003c!-- [![Codecov][codecov-src]][codecov-href] --\u003e\n\n# clarity\n\n\u003e A modern `debug` client for TypeScript, offering powerful logging capabilities with colored output, performance tracking, log rotation, and both CLI \u0026 library support.\n\n## Features\n\n- 🚀 **Performance** _High-Performance Logging_\n- 🎯 **Domain-Specific** _Domain-Specific Namespaces_\n- 🤞 **Buffering** _Fingers-Crossed Log Buffering_\n- 🔄 **Rotation** _Automatic Log Rotation \u0026 Cleanup_\n- 🔐 **Encryption** _Encrypted Log Storage_\n\n### Output \u0026 Formatting\n\n- 🎨 **Rich Color-Coded** _Console Output_\n- 📊 **Multiple Log Levels** _`debug`, `info`, `success`, `warn`, `error`_\n- 🔠 **Format String Support** _`%s`, `%d`, `%j`, etc._\n- ⚡ **Built-in Performance Tracking** _`start`, `end`, `time`_\n\n### Platform Support\n\n- 🌐 **Universal** _Browser \u0026 Server support_\n- 🛠️ **CLI \u0026 Library** _Access APIs via CLI or programmatically_\n- 💻 **Fully Typed** _First-Class TypeScript support_\n- 📦 **Lightweight** _Zero external dependencies_\n\n## Ghostty support\n\nClarity detects modern terminals like Ghostty and emits OSC 8 hyperlinks and optional terminal titles for a better UX.\n\n- Hyperlinks (OSC 8)\n  - Markdown-style links in messages like `[docs](https://ghostty.org/docs)` render as clickable links in Ghostty and other capable terminals.\n  - Local file paths in links (e.g. `[open log](./logs/app.log)`) become clickable `file://` links when the file exists.\n  - Disable/force with env vars: `NO_OSC8=1` to disable, `FORCE_OSC8=1` to force-enable.\n\n- Terminal title (OSC 2)\n  - You can set the window/tab title when running in a TTY:\n\n  ```ts\n  import { Logger } from '@stacksjs/clarity'\n  const logger = new Logger('build')\n  logger.setTerminalTitle('Clarity • Build running')\n  ```\n\n- Detection\n  - Ghostty is detected via `TERM_PROGRAM=Ghostty`.\n  - Other terminals with OSC 8 support are detected heuristically (`TERM_PROGRAM=iTerm.app|WezTerm|vscode`, `VTE_VERSION\u003e=5000`, Windows Terminal, kitty, etc.).\n\nIf your terminal doesn’t support OSC 8 or styling is disabled, Clarity falls back to plain text without underlines or clickable links.\n\n## Install\n\n```bash\nbun add @stacksjs/clarity\nnpm install @stacksjs/clarity\n```\n\n## Get Started\n\nThere are two ways of using clarity: _as a library or as a CLI._\n\n### Library\n\nGiven the npm package is installed:\n\n```ts\nimport { Logger } from '@stacksjs/clarity'\n\n// Configure the logger\nconst logger = new Logger('parser', {\n  // Optional configuration\n  maxLogSize: 5 _ 1024 _ 1024, // 5MB\n\n  rotation: {\n    maxLogFiles: 10,\n    compress: true,\n  },\n\n  encrypted: true,\n})\n\n// Basic logging\nlogger.info('Starting parser...')\nlogger.success('Document parsed successfully')\nlogger.warning('Legacy format detected')\nlogger.error('Failed to parse document')\n\n// Performance tracking\nconst end = logger.info('Starting expensive operation...')\n// ... do work ...\nend('Operation completed') // automatically includes time taken\n\n// Domain-specific logging\nconst parseLogger = logger.extend('json')\nparseLogger.info('Parsing JSON...') // outputs with [parser:json] prefix\n\n// Debug mode\nlogger.debug('Additional debug information')\n\n// Format string support\nlogger.info('Found %d errors in %s', 3, 'document.txt')\n\n// Conditional execution\nlogger.only(() =\u003e {\n  // Only runs when logging is enabled\n  logger.info('Additional diagnostics...')\n})\n```\n\n_To learn more about the Library usage, please refer to the [Library documentation](https://stacks-clarity.netlify.app/library)._\n\n### Common Usage Examples\n\n#### Basic Logging with Different Levels\n\n```ts\nimport { Logger } from '@stacksjs/clarity'\n\nconst logger = new Logger('app')\n\n// Different log levels\nawait logger.debug('Debug information for developers')\nawait logger.info('General information about application state')\nawait logger.success('Operation completed successfully')\nawait logger.warn('Warning: approaching rate limit')\nawait logger.error('Failed to connect to database')\n```\n\n#### Performance Tracking\n\n```ts\nimport { Logger } from '@stacksjs/clarity'\n\nconst logger = new Logger('performance')\n\n// Track operation duration\nconst end = logger.time('Starting database query')\nawait db.query('SELECT _ FROM users')\nawait end() // Outputs: \"Starting database query completed in 123ms\"\n\n// Track multiple operations\nconst end1 = logger.time('Operation 1')\nconst end2 = logger.time('Operation 2')\nawait Promise.all([\n  someAsyncOperation().then(end1),\n  anotherAsyncOperation().then(end2)\n])\n```\n\n#### Domain-Specific Logging\n\n```ts\nimport { Logger } from '@stacksjs/clarity'\n\nconst logger = new Logger('api')\n\n// Create sub-loggers for specific domains\nconst authLogger = logger.extend('auth')\nconst dbLogger = logger.extend('database')\nconst cacheLogger = logger.extend('cache')\n\nawait authLogger.info('User authenticated') // [api:auth] User authenticated\nawait dbLogger.error('Connection failed') // [api:database] Connection failed\nawait cacheLogger.debug('Cache miss') // [api:cache] Cache miss\n```\n\n#### Advanced Configuration\n\n```ts\nimport { Logger } from '@stacksjs/clarity'\n\nconst logger = new Logger('app', {\n  // Log level and format\n  level: 'debug',\n  format: 'json',\n  timestamp: new Date(),\n\n  // Log rotation settings\n  rotation: {\n    maxSize: 5 _ 1024 _ 1024, // 5MB\n    maxFiles: 10,\n    frequency: 'daily',\n    compress: true,\n  },\n\n  // Fingers-crossed buffering\n  fingersCrossed: {\n    activationLevel: 'error',\n    bufferSize: 50,\n    flushOnDeactivation: true,\n  }\n})\n```\n\n#### Structured Logging\n\n```ts\nimport { Logger } from '@stacksjs/clarity'\n\nconst logger = new Logger('api', { format: 'json' })\n\n// Log structured data\nawait logger.info('User action', {\n  userId: 123,\n  action: 'login',\n  timestamp: new Date(),\n  metadata: {\n    ip: '192.168.1.1',\n    userAgent: 'Mozilla/5.0...'\n  }\n})\n\n// Log errors with stack traces\ntry {\n  throw new Error('Database connection failed')\n}\ncatch (error) {\n  await logger.error('Failed to execute query', {\n    error: error.message,\n    stack: error.stack,\n    query: 'SELECT _ FROM users'\n  })\n}\n```\n\n#### Conditional Logging\n\n```ts\nimport { Logger } from '@stacksjs/clarity'\n\nconst logger = new Logger('app')\n\n// Only execute logging code if the level is enabled\nlogger.only(() =\u003e {\n  const expensiveOperation = calculateSomething()\n  logger.debug('Operation result:', expensiveOperation)\n})\n\n// Conditional logging with levels\nif (logger.shouldLog('debug')) {\n  const metrics = gatherMetrics() // expensive operation\n  await logger.debug('System metrics:', metrics)\n}\n```\n\n### CLI\n\n```bash\n# Watch logs in real-time\nclarity watch --level debug --name \"parser:_\"\nclarity watch --json --timestamp\n\n# Log a one-off message\nclarity log \"Starting deployment\" --level info --name \"deploy\"\n\n# Export logs to a file\nclarity export --format json --output logs.json --level error\nclarity export --start 2024-01-01 --end 2024-01-31\n\n# Show and follow last N lines\nclarity tail --lines 50 --level error --follow\nclarity tail --name \"api:_\"\n\n# Search through logs\nclarity search \"error connecting to database\" --level error\nclarity search \"deployment\" --start 2024-01-01 --case-sensitive\n\n# Clear log history\nclarity clear --level debug --before 2024-01-01\nclarity clear --name \"temp:_\"\n\n# Configure log rotation\nclarity config set --key maxLogSize --value 5242880  # 5MB\nclarity config set --key maxLogFiles --value 10\nclarity config set --key compressLogs --value true\n\n# Other configuration\nclarity config set --level debug\nclarity config list\n\n# Utility commands\nclarity --help    # Show help information\nclarity --version # Show version number\n```\n\nAll commands support the following common options:\n\n- `--level`: Filter by log level (debug, info, warning, error)\n- `--name`: Filter by logger name (supports patterns like \"parser:_\")\n- `--verbose`: Enable verbose output\n\n#### Command Reference\n\n- `watch`: Monitor logs in real-time with filtering and formatting options\n- `log`: Send one-off log messages with specified level and name\n- `export`: Save logs to a file in various formats with date range filtering\n- `tail`: Show and optionally follow the last N lines of logs\n- `search`: Search through logs using patterns with date range and case sensitivity options\n- `clear`: Clear log history with level, name, and date filtering\n- `config`: Manage clarity configuration (get, set, list)\n\n_To learn more about the CLI usage, please refer to the [CLI documentation](https://stacks-clarity.netlify.app/cli)._\n\n## Configuration\n\nClarity can be configured programmatically, using environment variables, or through the CLI:\n\n### Programmatic Configuration\n\n```typescript\nimport { Logger } from '@stacksjs/clarity'\n\nconst logger = new Logger('app', {\n  // Log Levels\n  level: 'debug',\n  defaultName: 'app',\n  verbose: true,\n\n  // Output Format\n  format: 'json',\n  timestamp: true,\n  colors: true,\n\n  // Log Rotation\n  rotation: {\n    frequency: 'daily',\n    maxLogSize: 10 _ 1024 _ 1024, // 10MB\n    maxLogFiles: 5,\n    compress: true,\n  },\n\n  encrypt: true,\n  logDirectory: '~/.clarity/logs',\n})\n```\n\n### Environment Variables\n\n```bash\n# Enable logging\nDEBUG=true\nDEBUG=parser # enable specific logger\nDEBUG=parser:* # enable logger and all subdomains\n\n# Control log level\nLOG_LEVEL=debug # show all logs\nLOG_LEVEL=error # show only errors\n```\n\n### CLI Configuration\n\n```bash\n# Configure logging\nclarity config set --key level --value debug\nclarity config set --key maxLogSize --value 5242880 # 5MB\n```\n\n## Testing\n\n```bash\nbun test\n```\n\n## Changelog\n\nPlease see our [releases](https://github.com/stacksjs/clarity/releases) page for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/stacksjs/stacks/blob/main/.github/CONTRIBUTING.md) for details.\n\n## Community\n\nFor help, discussion about best practices, or any other conversation that would benefit from being searchable:\n\n[Discussions on GitHub](https://github.com/stacksjs/clarity/discussions)\n\nFor casual chit-chat with others using this package:\n\n[Join the Stacks Discord Server](https://discord.gg/stacksjs)\n\n## Postcardware\n\n“Software that is free, but hopes for a postcard.” We love receiving postcards from around the world showing where `clarity` is being used! We showcase them on our website too.\n\nOur address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎\n\n## Sponsors\n\nWe would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.\n\n- [JetBrains](https://www.jetbrains.com/)\n- [The Solana Foundation](https://solana.com/)\n\n## Credits\n\n- [debug](https://github.com/debug-js/debug)\n- [@open-draft/logger](https://github.com/open-draft/logger)\n- [Chris Breuer](https://github.com/chrisbbreuer)\n- [All Contributors](https://github.com/stacksjs/clarity/contributors)\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/clarity/blob/main/LICENSE.md) for more information.\n\nMade with 💙\n\n\u003c!-- Badges --\u003e\n[npm-version-src]: https://img.shields.io/npm/v/@stacksjs/clarity?style=flat-square\n[npm-version-href]: https://npmjs.com/package/@stacksjs/clarity\n[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/clarity/ci.yml?style=flat-square\u0026branch=main\n[github-actions-href]: https://github.com/stacksjs/clarity/actions?query=workflow%3Aci\n\n\u003c!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/clarity/main?style=flat-square\n[codecov-href]: https://codecov.io/gh/stacksjs/clarity --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fclarity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstacksjs%2Fclarity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fclarity/lists"}