{"id":24628150,"url":"https://github.com/gavinbirkhoff/swiftlet-log","last_synced_at":"2025-03-20T02:28:48.194Z","repository":{"id":222419616,"uuid":"743180627","full_name":"GavinBirkhoff/swiftlet-log","owner":"GavinBirkhoff","description":"Logging utility with different log levels with timestamp options.","archived":false,"fork":false,"pushed_at":"2024-03-10T08:21:42.000Z","size":144,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T05:14:22.188Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/GavinBirkhoff.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}},"created_at":"2024-01-14T15:21:01.000Z","updated_at":"2024-02-14T04:21:49.000Z","dependencies_parsed_at":"2024-02-14T05:26:49.555Z","dependency_job_id":"7a3e6606-2609-41ae-8517-65846faf0aa8","html_url":"https://github.com/GavinBirkhoff/swiftlet-log","commit_stats":null,"previous_names":["gavinbirkhoff/swiftlet-log"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GavinBirkhoff%2Fswiftlet-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GavinBirkhoff%2Fswiftlet-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GavinBirkhoff%2Fswiftlet-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GavinBirkhoff%2Fswiftlet-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GavinBirkhoff","download_url":"https://codeload.github.com/GavinBirkhoff/swiftlet-log/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244538164,"owners_count":20468665,"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":[],"created_at":"2025-01-25T05:14:25.041Z","updated_at":"2025-03-20T02:28:48.167Z","avatar_url":"https://github.com/GavinBirkhoff.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swiftlet-log\n\nLogging utility with different log levels with timestamp options.\n\n## Usage\n\n1. **Installation**\n\n   Install the Logger package using npm:\n\n   ```bash\n   npm install swiftlet-log\n   ```\n\n   Install the Logger package using yarn:\n\n   ```bash\n   yarn add swiftlet-log\n   ```\n\n   Install the Logger package using pnpm:\n\n   ```bash\n   pnpm add swiftlet-log\n   ```\n\n2. **Import and Create Logger Instance**\n\n   Import the Logger class and create an instance:\n\n   ```typescript\n   import { Logger, LogLevel } from 'swiftlet-log'\n\n   const logger = new Logger({ level: LogLevel.DEBUG, timestamp: true })\n   ```\n\n3. **Log Messages**\n\n   Use the different log level methods to log messages:\n\n   ```typescript\n   logger.debug('This is a debug message.')\n   logger.info('This is an info message.')\n   logger.warning('This is a warning message.')\n   logger.error('This is an error message.')\n   logger.trace('This is a trace message.')\n   logger.fatal('This is a fatal message.')\n   ```\n\n4. **Middleware**\n\n   ```typescript\n   import { Logger, LogLevel, LogMiddleware } from 'swiftlet-log'\n\n   const logger = new Logger({ level: LogLevel.DEBUG, timestamp: true })\n\n   const customPrefixMiddleware: LogMiddleware = (ctx, next) =\u003e {\n     ctx.message = `[CUSTOM PREFIX] ${ctx.message}`\n     next(ctx.message, ctx.level)\n   }\n\n   logger.use(customPrefixMiddleware)\n\n   logger.info('This is an info message.') // 输出: [CUSTOM PREFIX] [INFO]: This is an info message.\n   ```\n\n5. **Customization**\n\n- Adjust log level:\n\n  ```typescript\n  logger.setLogLevel(LogLevel.INFO)\n  ```\n\n- Enable or disable timestamp:\n\n  ```typescript\n  logger.enableTimestamp()\n  logger.disableTimestamp()\n  ```\n\n- Add or remove log listeners:\n\n  ```typescript\n  const customListener: LogListener = (level, message) =\u003e {\n    // Your custom log listener logic\n  }\n\n  logger.addLogListener(customListener)\n  logger.removeLogListener(customListener)\n  ```\n\n## Log Levels\n\n- `DEBUG`: Detailed debugging information.\n- `INFO`: General information about system operation.\n- `WARNING`: Indicates a potential problem.\n- `ERROR`: Indicates a more serious problem.\n- `TRACE`: Very detailed tracing information.\n- `FATAL`: A very severe error that may lead to application termination.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinbirkhoff%2Fswiftlet-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavinbirkhoff%2Fswiftlet-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinbirkhoff%2Fswiftlet-log/lists"}