{"id":16907677,"url":"https://github.com/james-pre/logzen","last_synced_at":"2025-04-11T15:41:26.816Z","repository":{"id":184046998,"uuid":"671222518","full_name":"james-pre/logzen","owner":"james-pre","description":"LogZen is a simple and flexible logging library for JS.","archived":false,"fork":false,"pushed_at":"2024-10-06T06:19:34.000Z","size":330,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T12:14:23.362Z","etag":null,"topics":["log","logging"],"latest_commit_sha":null,"homepage":"https://dr-vortex.github.io/logzen/","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/james-pre.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":"2023-07-26T20:32:01.000Z","updated_at":"2024-10-06T06:19:11.000Z","dependencies_parsed_at":"2024-02-15T00:23:15.332Z","dependency_job_id":"885a2869-bc47-48ae-a984-c6f9fb9061f9","html_url":"https://github.com/james-pre/logzen","commit_stats":null,"previous_names":["dr-vortex/logzen","james-pre/logzen"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james-pre%2Flogzen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james-pre%2Flogzen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james-pre%2Flogzen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james-pre%2Flogzen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/james-pre","download_url":"https://codeload.github.com/james-pre/logzen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248433003,"owners_count":21102489,"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":["log","logging"],"created_at":"2024-10-13T18:48:28.534Z","updated_at":"2025-04-11T15:41:26.794Z","avatar_url":"https://github.com/james-pre.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LogZen\n\nLogzen is a simple and flexible logging library for Javascript that provides easy-to-use logging functionality with customizable log levels and the ability to output logs to different streams and consoles.\n\n[Documentation](https://james-pre.github.io/logzen)\n\n## Installation\n\nYou can install Logzen using npm:\n\n```bash\nnpm install logzen\n```\n\n## Usage\n\nTo use Logzen in your project, you need to import the `Logger` class from the Logzen package:\n\n```javascript\nimport { Logger } from 'logzen';\n```\n\n### Basic Logging\n\nCreate a new `Logger` instance to start logging:\n\n```javascript\nconst logger = new Logger();\n\nlogger.log('This is a log message.');\nlogger.warn('This is a warning message.');\nlogger.error('This is an error message.');\nlogger.debug('This is a debug message.');\n```\n\n### Customizing Log Levels\n\nYou can customize the log levels by setting the `attachGlobalConsole` option to `false` and manually attaching the console with custom log levels:\n\n```javascript\nimport { Logger, LogLevel } from 'logzen';\nconst logger = new Logger({ attachGlobalConsole: false });\n\n// Attach console with custom log levels\nlogger.attach(console, LogLevel.WARN, LogLevel.ERROR);\n\nlogger.error('This message will be sent to the console.');\nlogger.log('This message will not be sent to the console!');\n```\n\n### Logging to Files\n\nLogzen supports logging to files by attaching file streams to the `Logger` instance. This allows you to send log entries with specific log levels to separate log files.\n\n```javascript\nimport { Logger, LogLevel } from 'logzen';\nimport fs from 'fs';\n\n// Create a writable stream to a log file\nconst logFileStream = fs.createWriteStream('app.log', { flags: 'a' });\nconst errorFileStream = fs.createWriteStream('error.log', { flags: 'a' });\n\n// Create the Logger instance\nconst logger = new Logger({ attachGlobalConsole: false });\n\n// Attach the file stream with specific log levels\nlogger.attach(logFileStream, LogLevel.LOG, LogLevel.INFO);\nlogger.attach(errorFileStream, LogLevel.WARN, LogLevel.ERROR);\n\nlogger.log('This log message will be written to the app.log file.');\nlogger.error('This error message will also be written to the error.log file.');\n```\n\n### Detaching Streams and Consoles\n\nYou can detach streams and consoles from the `Logger` using the `detachStream` and `detachConsole` methods:\n\n```javascript\nconst logger = new Logger();\n\n// Detach streams and Console objects\nlogger.detach(stream, LogLevel.LOG, LogLevel.WARN);\nlogger.detach(console);\n```\n\n### Attaching Consoles\n\nYou can also attach Console objects to the Logger instance to output logs to the console. This is useful if you have multiple consoles and want to output to all of them.\n\n```javascript\nconst logger = new Logger({ attachGlobalConsole: false });\n\nlogger.attach(console, LogLevel.WARN, LogLevel.ERROR);\n\nlogger.log('This log message will be not sent to the console.');\nlogger.error('This error will be sent to the console!');\n```\n\n### Retaining Logs\n\nBy default, logs are retained in memory. You can disable log retention by setting the retainLogs option to false. Note that if you disable log retention, calling a `Logger`'s `toString` method will return an empty string.\n\n```javascript\nconst logger = new Logger({ retainLogs: false });\n\nlogger.log('This log message will not be retained in memory.');\nlogger.warn('This warning message will also not be retained.');\n```\n\n### Default log levels for attaching and detaching\n\nWhen attaching a stream or console without specifying log levels, all will be attached. Likewise, when detaching, the stream or console will be completly removed.\n\n## FAQs\n\nNone yet!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames-pre%2Flogzen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjames-pre%2Flogzen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames-pre%2Flogzen/lists"}