{"id":21842343,"url":"https://github.com/beerush-id/logger","last_synced_at":"2026-02-05T22:01:26.955Z","repository":{"id":239409391,"uuid":"797870995","full_name":"beerush-id/logger","owner":"beerush-id","description":"Unify Your JavaScript Logging Experience","archived":false,"fork":false,"pushed_at":"2025-01-03T12:17:19.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-17T06:27:12.649Z","etag":null,"topics":["javascript-library","logging","logs","typescript-library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beerush-id.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-05-08T16:43:05.000Z","updated_at":"2025-01-03T12:17:23.000Z","dependencies_parsed_at":"2024-05-12T08:28:27.099Z","dependency_job_id":"eb81e750-6f27-4280-b9ac-76b1b0aec2c1","html_url":"https://github.com/beerush-id/logger","commit_stats":null,"previous_names":["beerush-id/logger"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/beerush-id/logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beerush-id%2Flogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beerush-id%2Flogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beerush-id%2Flogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beerush-id%2Flogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beerush-id","download_url":"https://codeload.github.com/beerush-id/logger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beerush-id%2Flogger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29135919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T21:59:57.939Z","status":"ssl_error","status_checked_at":"2026-02-05T21:59:57.628Z","response_time":65,"last_error":"SSL_read: 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":["javascript-library","logging","logs","typescript-library"],"created_at":"2024-11-27T22:11:37.620Z","updated_at":"2026-02-05T22:01:26.937Z","avatar_url":"https://github.com/beerush-id.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @beerush/logger: Unify Your JavaScript Logging Experience\n\nWelcome to @beerush/logger - where consistency in logging across Libraries, Frameworks, and Applications becomes a\nreality. This versatile logger, free of dependencies, is designed to standardize logging, offering a range of adaptable\nadapters tailored to different environments. Embrace a unified approach to all levels of logging with @beerush/logger.\nStart simplifying your logging process today!\n\n![Logger](./preview.jpg)\n\n## 🐞 Background\n\nThe Javascript ecosystem is remarkably rich with a vast selection of libraries and frameworks. However, managing the\ndisplay and distribution of logs can pose a significant challenge.\n\nWithin a development environment, it might be preferable to log everything. However, in production, logging may need to\nbe limited to errors only. It is particularly important to streamline this process when you are deploying your project\nto a serverless environment or any other cloud service where debugging can be complicated.\n\nThe straightforward console.log might suffice for your project, but it does not offer control over logging for the\nlibrary or framework in use. Our library aims to address this by providing a simple, user-friendly logger that can be\nemployed across various environments.\n\nEvery library, framework, and application can utilize the same logger for consistency and efficiency. Moreover, this\nallows for control over the log level and the destination of the logs.\n\n## ⛩️ Installation\n\nYou can install the package via package manager such as bun, npm, or yarn.\n\n```bash\nbun add @beerush/logger\n```\n\n## 🪄 Usage\n\nYou can use it in your typescript files like shown below:\n\n**Initialization** in `./logger.ts`\n\n```typescript\nimport { createLogger, LogLevel } from '@beerush/logger';\nimport { consoleAdapter } from '@beerush/logger/console';\n\n// Create a new logger instance and export it for use in other modules.\nexport const logger = createLogger();\n\n// Use the console adapter to log to the console.\nlogger.use(consoleAdapter());\n\nlogger.info('Hello, World!'); // Logs an informational message.\n```\n\n```bash Console Output\n📜 [5/9/2024, 2:07:14 PM] Hello, World!\n```\n\nYou can also reuse the logger in your application. For instance, in your app.ts file:\n\n**Logging** in `./app.ts`\n\n```typescript\nimport { logger } from './logger.ts';\n\nlogger.info('Hello, World! App is running on port 3000.'); // Logs an informational message.\n```\n\n```bash Console Output\n📜 [5/9/2024, 2:07:14 PM] Hello, World! App is running on port 3000.\n```\n\n### Adapters\n\nAdapter is a function that receives a log and handles it in a specific way. For example, an adapter might send the log\nto a remote server, write it to a file, or log it to the console.\n\nEach adapter can have its own severity level and options. For example, the Console adapter will capture all logs in\ndevelopment, but nothing in production, and the Sentry adapter will capture WARNING and ERROR in production, but nothing\nin development.\n\nYou can add an adapter to a logger using the `use`\nmethod of the logger.\n\n\n\u003e Adapters are applied in the order they are added, and shared across all loggers created from the same logger.\n\n\u003e Using the same adapter multiple times will overwrite the previous one.\n\n**Example:**\n\n```typescript\nimport { logger } from './logger.ts';\nimport { consoleAdapter } from '@beerush/logger/console';\nimport { fileAdapter } from '@beerush/logger/adapters/file';\n\nlogger.use(consoleAdapter({ level: LogLevel.DEBUG })); // Register a console adapter.\nlogger.info('Hello, World!'); // Logs an informational message to the console.\nlogger.verbose('Detailed information!'); // Ignored because the log level is DEBUG.\n\nlogger.use(fileAdapter({ location: './logs', level: LogLevel.ERROR })); // Register a file adapter.\nlogger.error('An error occurred!'); // Logs an error message to the console and to a file.\nlogger.info('Hello, World!'); // Logs to the console, and logs to a file is ignored because the log level is ERROR.\n```\n\n### Log Levels\n\nThe logger supports various log levels, each with its own significance. The log levels are as follows:\n\n* **ERROR**: This level is used for error messages. These logs represent errors that might have allowed the application\n  to continue running, but with unexpected behavior.\n* **WARN**: This level is used for potentially harmful situations. These logs might lead to an error.\n* **INFO**: This level is used for informational messages. These logs represent the progress of the application.\n* **DEBUG**: This level is used for general debugging information. These logs are usually only needed for debugging.\n* **VERBOSE**: This level is used for detailed debugging information. These logs are usually only needed for debugging.\n\n\u003e The logger will log all logs with a level greater than or equal to the log level of the logger. For example, setting\n\u003e the adapter level to INFO will log all logs with a level of INFO, WARN, or ERROR, but not DEBUG or VERBOSE.\n\n### Log Tracking\n\nThe logger supports tracking logs. Tracking logs are useful for tracking the execution of a specific part of the code.\nThis is useful for debugging and analytics. You can track logs using the `track` method of the logger.\n\n\u003e Tracking logs are not logged to the console by default. You can use specific adapters to log tracking logs.\n\n**Example:**\n\n```typescript\nimport { logger } from './logger.ts';\n\nlogger.track('User logged in', { userId: 1 }); // Track a user login.\n```\n\n### Log Colors\n\nThe console adapter uses different colors for different log levels when logging to the console. The colors are as\nfollows:\n\n* **VERBOSE**: Purple\n* **DEBUG**: Blue\n* **INFO**: Green\n* **WARN**: Yellow\n* **ERROR**: Red\n\n### Log Format\n\nThe logger formats the logs in a specific way when logging to the console. The format is as follows:\n\n* If the log message is a string, it is prefixed with a specific emoji based on the log level.\n* If the log message is not a string, it is logged as is.\n* If the log has an error, it is logged after the message.\n* If the log has extra information, it is logged after the error (if any).\n\n### Log Tags\n\nThe logger supports tagging logs. Tags are useful for categorizing logs. For example, you might want to tag logs with\nthe name of the module they are coming from. You can create a new logger with specific tags using the `create` method of\nan existing logger.\n\n**Example:**\n\n```typescript\nimport { logger } from './logger.ts';\n\nconst moduleLogger = logger.create({ tags: ['module'] });\nmoduleLogger.info('Hello, World!'); // Logs an informational message with the tag 'module'.\n```\n\n```bash Console Output\n📜 [module][5/9/2024, 2:07:14 PM] Hello, World!\n```\n\n### Conditional Adapter\n\nYou may want to adjust the log level based on your environment. For example, in your **Hono** app, you might want to\ndisable console logging in production. You can create a middleware that adjusts the log level based on the environment\nas shown below:\n\n```typescript\nimport { logger } from './logger.ts';\nimport type { Context } from 'hono';\n\nexport default async function loggerMiddleware(ctx: Context, next: () =\u003e void) {\n  // Override the logger level based on the environment.\n  if (ctx.env.PRODUCTION) {\n    logger.use(consoleAdapter({ level: LogLevel.OFF }));\n  } else {\n    logger.use(consoleAdapter({ level: LogLevel.DEBUG }));\n  }\n\n  ctx.set('logger', logger);\n  await next();\n}\n```\n\n### Custom Adapter\n\nIn case you want to log your data to an external service which is not supported by the built-in adapters, you can create\na custom adapter. A custom adapter is an object with a `name` and an `emit` method. The `emit` method is called with the\nlog object when a log is emitted. You can create a custom adapter as shown below:\n\n```typescript\nimport type { Log } from '@beerush/logger';\nimport { logger } from './logger.ts';\n\nlogger.use({\n  name: 'custom-adapter',\n  emit: async (log: Log) =\u003e {\n    await fetch('https://example.com/log', {\n      method: 'POST',\n      body: JSON.stringify(log),\n      headers: {\n        'Content-Type': 'application/json'\n      }\n    });    \n  }\n});\n\nlogger.info('Hello, World!'); // This will log the message to the external service.\n\n```\n\n## 🗃️ Built-in Adapters\n\n- [x] Logger module.\n- [x] [Console adapter](./src/adapters/console/readme.md)\n- [x] [Webhook adapter](./src/adapters/webhook/readme.md).\n- [x] [File adapter](./src/adapters/file/readme.md).\n- [x] [Sentry adapter](./src/adapters/sentry/readme.md).\n- [ ] [Mixpanel adapter](./src/adapters/mixpanel/readme.md).\n- [ ] [Slack adapter](./src/adapters/slack/readme.md).\n- [ ] [Discord adapter](./src/adapters/discord/readme.md).\n\n## License\n\nThe `@beerush/logger` is licensed under the MIT License, ensuring a wide range of opportunities for open source use and\nfurther development.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeerush-id%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeerush-id%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeerush-id%2Flogger/lists"}