{"id":26942163,"url":"https://github.com/juanbautista0/loggerfy","last_synced_at":"2026-02-14T22:34:18.820Z","repository":{"id":284768977,"uuid":"956027708","full_name":"juanbautista0/loggerfy","owner":"juanbautista0","description":"Loggerfy is a lightweight and customizable logging library designed to provide structured logs with rich metadata. It simplifies the process of logging errors, warnings, and information while ensuring consistency across your application.","archived":false,"fork":false,"pushed_at":"2025-05-28T16:29:46.000Z","size":65,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-11T09:45:37.862Z","etag":null,"topics":["aws","gcp","log","logger","logging","logging-library"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/loggerfy","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/juanbautista0.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,"zenodo":null}},"created_at":"2025-03-27T15:25:11.000Z","updated_at":"2025-05-28T18:46:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"a72c8f41-acf3-4dc6-b182-59460c474d14","html_url":"https://github.com/juanbautista0/loggerfy","commit_stats":null,"previous_names":["juanbautista0/loggerfy"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/juanbautista0/loggerfy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanbautista0%2Floggerfy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanbautista0%2Floggerfy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanbautista0%2Floggerfy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanbautista0%2Floggerfy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juanbautista0","download_url":"https://codeload.github.com/juanbautista0/loggerfy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanbautista0%2Floggerfy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29458872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T21:29:27.764Z","status":"ssl_error","status_checked_at":"2026-02-14T21:28:11.111Z","response_time":53,"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":["aws","gcp","log","logger","logging","logging-library"],"created_at":"2025-04-02T16:40:21.103Z","updated_at":"2026-02-14T22:34:18.815Z","avatar_url":"https://github.com/juanbautista0.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Loggerfy\n\n\u003e A simple and structured logging library for Node.js applications\n\n## What is Loggerfy?\n\nLoggerfy is a lightweight library that helps you create structured logs with a consistent format. Perfect for applications that need an organized and easy-to-implement logging system.\n\n## Quick Installation\n\n```bash\nnpm install loggerfy\n```\n\n## Quick Start Guide\n\n### 1. Import the library\n\n```js\n// CommonJS\nconst { Loggerfy } = require('loggerfy');\n\n// ES Modules\nimport { Loggerfy } from 'loggerfy';\n```\n\n### 2. Create a logger and use it\n\n```js\n// Create an instance\nconst logger = new Loggerfy();\n\n// Log an error\nlogger.error()\n  .setCode('AUTH_001')\n  .setMessage('User authentication failed')\n  .setDetail('Invalid credentials provided')\n  .setMetadata({ userId: 123 })\n  .write();\n```\n\n## Log Levels\n\nLoggerfy offers three logging levels:\n\n```js\n// Information\nlogger.info()\n  .setCode('APP_001')\n  .setMessage('Application started')\n  .setDetail('Server listening on port 3000')\n  .write();\n\n// Warning\nlogger.warn()\n  .setCode('CONFIG_001')\n  .setMessage('Using default configuration')\n  .setDetail('Configuration file not found')\n  .write();\n\n// Error\nlogger.error()\n  .setCode('DB_001')\n  .setMessage('Database connection error')\n  .setDetail('Timeout after 30 seconds')\n  .write();\n```\n\n## Available Methods\n\n| Method | Description | Required? |\n|--------|-------------|-----------|\n| `setCode(code)` | Sets a unique code for the log entry | Yes |\n| `setMessage(message)` | Sets the main message | Yes |\n| `setDetail(detail)` | Adds additional details | Yes |\n| `setMetadata(object)` | Adds contextual data | No |\n| `write()` | Writes the log to the console | Yes* |\n| `getLog()` | Returns the log as a JSON string without printing | Yes* |\n\n*Either `write()` or `getLog()` must be called to complete the logging operation.\n\n## Getting Log as String\n\nIf you need the log as a string instead of printing it to the console:\n\n```js\n// Get log as JSON string\nconst logString = logger.error()\n  .setCode('AUTH_001')\n  .setMessage('User authentication failed')\n  .setDetail('Invalid credentials provided')\n  .setMetadata({ userId: 123 })\n  .getLog();\n\n// Now you can use the string however you want\nsendToExternalService(logString);\n```\n\n## Output Format\n\nAll logs are generated in JSON format:\n\n```json\n{\n  \"timestamp\": \"2023-11-15T14:30:45.123Z\",\n  \"id\": \"550e8400-e29b-41d4-a716-446655440000\",\n  \"code\": \"AUTH_001\",\n  \"message\": \"User authentication failed\",\n  \"detail\": \"Invalid credentials provided\",\n  \"payload\": { \"userId\": 123 },\n  \"level\": \"ERROR\",\n  \"severity\": \"ERROR\",\n  \"service\": \"my-service\",\n  \"environment\": \"development\"\n}\n```\n\n## Environment Customization\n\nLoggerfy automatically detects the environment and service name:\n\n```js\n// Configure environment variables\nprocess.env.SERVICE_NAME = \"user-api\";\nprocess.env.NODE_ENV = \"production\";\n\n// Logs will include these values\n```\n\n## Implementation with Custom Repository\n\nYou can save logs to a custom repository:\n\n```js\nimport { Loggerfy, LoggerfyRepository, LogEntry } from 'loggerfy';\n\n// Implement your repository\nclass MyRepository implements LoggerfyRepository {\n  async save(log: LogEntry): Promise\u003cvoid\u003e {\n    // Save the log to your database\n    await db.logs.insert(log);\n  }\n}\n\n// Create the logger with your repository\nconst logger = new Loggerfy(new MyRepository());\n\n// Use it normally\nlogger.info()\n  .setCode('USER_001')\n  .setMessage('User created')\n  .setDetail('New record in database')\n  .write();\n```\n\n## Complete Example\n\n```js\nimport { Loggerfy } from 'loggerfy';\n\n// Environment configuration\nprocess.env.SERVICE_NAME = \"payment-service\";\n\nconst logger = new Loggerfy();\n\nfunction processPayment(userId, amount) {\n  try {\n    // Payment processing logic\n    \n    // Success log\n    logger.info()\n      .setCode('PAYMENT_001')\n      .setMessage('Payment processed successfully')\n      .setDetail(`Payment of $${amount} processed`)\n      .setMetadata({ userId, amount, timestamp: new Date() })\n      .write();\n      \n    return true;\n  } catch (error) {\n    // Error log\n    logger.error()\n      .setCode('PAYMENT_ERR_001')\n      .setMessage('Payment processing failed')\n      .setDetail(error.message)\n      .setMetadata({ userId, amount, errorStack: error.stack })\n      .write();\n      \n    return false;\n  }\n}\n```\n\n## Tips for Effective Use\n\n1. **Use consistent codes** - Create a coding system for your logs (e.g., AUTH_001, DB_001)\n2. **Include context** - Use setMetadata to add relevant information for debugging\n3. **Use the appropriate level** - Don't log everything as an error, use info and warn appropriately\n4. **Choose the right output method** - Use `write()` for console output or `getLog()` when you need the log as a string\n\n## Need Help?\n\nVisit our [GitHub repository](https://github.com/juanbautista0/loggerfy) for more information or to report issues.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanbautista0%2Floggerfy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuanbautista0%2Floggerfy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanbautista0%2Floggerfy/lists"}