{"id":19281726,"url":"https://github.com/scality/werelogs","last_synced_at":"2025-11-04T09:07:35.455Z","repository":{"id":46694509,"uuid":"45952329","full_name":"scality/werelogs","owner":"scality","description":"A logging library providing efficient raw logging in the form of JSON data.","archived":false,"fork":false,"pushed_at":"2025-03-19T14:47:10.000Z","size":565,"stargazers_count":16,"open_issues_count":6,"forks_count":2,"subscribers_count":55,"default_branch":"development/8.2","last_synced_at":"2025-04-01T17:53:34.875Z","etag":null,"topics":["artesca","bunyan","javascript","logging","nodejs","performance","requestlogger","ring","zenko"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scality.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2015-11-11T01:31:53.000Z","updated_at":"2025-02-21T16:17:51.000Z","dependencies_parsed_at":"2024-02-27T00:29:36.430Z","dependency_job_id":"7f5af034-18c2-4395-b8bf-6c6b5f4ace53","html_url":"https://github.com/scality/werelogs","commit_stats":null,"previous_names":[],"tags_count":455,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scality%2Fwerelogs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scality%2Fwerelogs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scality%2Fwerelogs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scality%2Fwerelogs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scality","download_url":"https://codeload.github.com/scality/werelogs/tar.gz/refs/heads/development/8.2","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250161969,"owners_count":21385014,"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":["artesca","bunyan","javascript","logging","nodejs","performance","requestlogger","ring","zenko"],"created_at":"2024-11-09T21:23:56.609Z","updated_at":"2025-11-04T09:07:35.416Z","avatar_url":"https://github.com/scality.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WereLogs\n\nThis repository provides a NodeJS Library that aims to be an efficient logging\nlibrary, reducing as much as possible the need to compute anything in NodeJS,\nand focusing on a simple I/O scheme. The goal here is to make the most of\nNodeJS's strengths, but relying on its I/O capacities, and avoiding any form of\ncomputation that is known to not be advantageous in Node.\n\n## Contributing\n\nIn order to contribute, please follow the\n[Contributing Guidelines](\nhttps://github.com/scality/Guidelines/blob/master/CONTRIBUTING.md).\n\n## Installing the Library\n\nIn order to install WereLogs, you can use NPM with github's HTTP url, and save\nit in your own package.json:\n\n```sh\n$\u003e npm i --save scality/werelogs\n```\n\nAs the repository is currently private, you will need to provide your username\nand your password, or use the git+ssh protocol with a properly configured\nenvironment, or use the git+https protocol with your username and cleartext\npassword in the URL (which I absolutely don't recommend for security reasons).\n\n## Using the Library\n\nWerelogs is a logging library that provides both per-request and per-module\nlogging facilities, through the intermediary of the per-module Logger that\nis the default export.\n\nWerelogs may be configured only once throughout your application's lifetime,\nthrough the configuration options available in the per-module logger\nconstructor.\n\nThe per-module Logger object is used to log relevant events for a given module.\n\nThe RequestLogger object is the one you want to use for any logging operation\nrelated to an ongoing request, so you will have to pass it to any function that\nrequires it.\n\nAll logging methods (trace, debug, info, warn, error and fatal) follow the same\nprototype and usage pattern. They can take up to two parameters, the first one,\nmandatory, being a string message, and the second one, optional, being an\nobject used to provide additional information to be included in the log entry.\n\nThe RequestLogger also provides a way to include some attributes in the JSON by\ndefault for all subsequent logging calls, by explicitly inputting them only\nonce for the whole request's lifetime through the method\n`addDefaultFields`.\n\nAs the RequestLogger is a logger strongly associated to a request's processing\noperations, it provides a builtin facility to log the elapsed time in ms of the\nsaid processing of the request. This is done through a specific logging method,\n`end` that returns a prepared logging object. Using this returned object with\nthe usual logging methods will automatically compute the elapsed time from the\ninstantiation of the RequestLogger to the moment it is called, by using an\ninternal hi-res time generated at the instantiation of the logger.\n\n```javascript\nimport Logger from 'werelogs';\n\n/*\n * Here, configure your WereLogs Logger at a global level\n * It can be instantiated with a Name (for the module), and a config options\n * Object.\n *\n * This config options object contains a log level called 'level', a log\n * dumping threshold called 'dump'. The only unnecessary\n * field is the 'level' of each individual stream, as werelogs is managing\n * that on its own.\n *\n * All request loggers instantiated through this Logger will inherit its\n * configuration.\n */\nconst log = new Logger(\n    'SampleModule',\n    {\n        level: 'debug',\n        dump: 'error',\n    }\n);\n\n/*\n * First, you can use the Logger as a module-level logger, logging events\n * that happen at the module's level.\n *\n * The API of the module-level logger is the same as the API of the request\n * Logger.\n */\nlog.info('Application started.');\nlog.warn('Starting RequestLogging...', {'metadata': new Date()});\n\ndoSomething(reqLogger) {\n    /*\n     * Let's add some kind of client-related data as default attributes first\n     */\n    reqLogger.addDefaultFields({ clientIP: '127.0.0.1',\n                                 clientPort: '65535',\n                                 clientName: 'Todd'});\n\n    /*\n     * Then, you can log some data, either a string or an object, using one of\n     * the logging methods: 'trace', 'debug', 'info', 'warn', 'error', or\n     * 'fatal'.\n     */\n    reqLogger.info('This is a string log entry');\n    // This example provides additional information to include into the JSON\n    reqLogger.info('Placing bet...',\n                   { date: new Date().toISOString(),\n                     odds: [1, 1000],\n                     amount: 20000,\n    });\n}\n\nfunction processRequest() {\n    /*\n     * Now, for one specific request, we need to get a request-specific logger\n     * instance. It can be called without a request ID, and will then generate\n     * one for you. Otherwise you can give it a string id (no specific format\n     * required) or a list of string ids (that can allow request-scoping on a\n     * distributed system)\n     */\n    const reqLogger = log.newRequestLogger();\n\n    /* you need to provide your logger instance to the code that requires it,\n     * as it is not a module-wide object instance */\n    doSomething(reqLogger, ...);\n\n    ...\n\n    /*\n     * Planning for some specific data to be included in the last logging\n     * request, you could use the addDefaultFields of the end()'s object:\n     */\n    reqLogger.end().addDefaultFields({method: 'GET', client: client.getIP()})\n\n    /*\n     * This call will generate a log entry with an added elapsed_ms\n     * field. This object can only be used once, as it should only be used for\n     * the last log entry associated to this specific RequestLogger.\n     * This call will be reusing potential data fields previously added through\n     * end().addDefaultFields().\n     */\n    reqLogger.end().info('End of request.', { status: 200 });\n}\n```\n\n## Known Issues\n\nIn order to find out the known issues, it is advised to take a look at the\n[project's github page](http://github.com/scality/werelogs). There, you should\nbe able to find the issues, tagged with the releases they are impacting,\nwhether they're open or closed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscality%2Fwerelogs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscality%2Fwerelogs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscality%2Fwerelogs/lists"}