{"id":18545320,"url":"https://github.com/xeinebiu/typescript_logger","last_synced_at":"2026-05-18T15:33:43.153Z","repository":{"id":47284924,"uuid":"259121879","full_name":"xeinebiu/typescript_logger","owner":"xeinebiu","description":"Enable logging on your TS Project using decorators|annotations.","archived":false,"fork":false,"pushed_at":"2021-09-12T16:12:19.000Z","size":120,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-30T01:50:31.791Z","etag":null,"topics":["console","decorators","filter","javascript","logger","logging","logs","typescript"],"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/xeinebiu.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}},"created_at":"2020-04-26T20:02:22.000Z","updated_at":"2024-10-04T11:53:15.000Z","dependencies_parsed_at":"2022-09-23T03:31:36.699Z","dependency_job_id":null,"html_url":"https://github.com/xeinebiu/typescript_logger","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/xeinebiu/typescript_logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Ftypescript_logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Ftypescript_logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Ftypescript_logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Ftypescript_logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xeinebiu","download_url":"https://codeload.github.com/xeinebiu/typescript_logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Ftypescript_logger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33182866,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"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":["console","decorators","filter","javascript","logger","logging","logs","typescript"],"created_at":"2024-11-06T20:19:43.578Z","updated_at":"2026-05-18T15:33:43.136Z","avatar_url":"https://github.com/xeinebiu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Logger for Typescript\n\nEnable logging on your TS Project using decorators|annotations.\n\n---\n\n### Installation\n\n````bash\nnpm i @xeinebiu/ts-logger@1.1.2\n````\n\n---\n\n### Change Logs\n    1.1.1\n        - Export LogClass\n    1.1.0\n        - Add LogClass Decorator\n    1.0.1\n        - Fix module exports\n    1.0.0\n        - Initial Version\n\n### Usage\n\n---\n\n#### Logger\n\nSetting the ``listner`` is necessary to enable the logging.\n\n````javascript\nLogger.listener = {\n    // Return True to output the given [log], false otherwise\n    beforeLog: (log: Log, outputType: OutputType) =\u003e {\n        return true;\n    },\n\n    // The given [log] is printed\n    afterLog: (log: Log, outputType: OutputType) =\u003e {\n\n    },\n\n    // Apply different styles of [Log] and [outputType]\n    applyStyle: (log: Log, outputType: OutputType) =\u003e {\n        if (outputType === OutputType.log) {\n            return 'background: #8c7ae6; color: #2f3640; padding: 3px';\n        }\n        return true;\n    }\n};\n````\n\n---\n\n#### Method Logger\n\nTo log any method, use ``@Method.Log()`` decorator and `@Method.asyncLong()` for Asynchronous Methods.\n\nAssume we have a class called ``Demo`` and we want to log some methods on it.\n\n````javascript\nclass Demo {\n    @Method.log()\n    public add(...args: number[]): number {\n        let sum = 0;\n        args.forEach(x =\u003e sum += x);\n        return sum;\n    }\n}\n````\n\nNow, every time the method ``add(..args)`` is invoked, an output will result in console like the below\n![](docs/1.PNG)\n\n##### MethodLoggerOptions\n\nThe decorator ``@Method.log()`` accepts an `MethodLoggerOptions` as single argument where we can configure the Logger\nfor each Method.\n\n````javascript\n@Method.log({tag: 'Sum collection of numbers', args: true, importance: 1, printResult: true})\npublic add(...args : number[]) : number {\n    let sum = 0;\n    args.forEach(x =\u003e sum += x);\n    return sum;\n}\n````\n\nWith the above configuration, we are about to see 2 logs for the same method call. First Log when the method is invoked,\nand the second when Return.\n![](docs/2.PNG)\n\nArguments can be printed partially also.\n\n````javascript\n@Method.asyncLog({tag: 'Login', printResult: true, args: [0]})\npublic login(username : string, password : string ): Promise \u003c boolean \u003e {\n    return new Promise \u003c boolean \u003e ((resolve) =\u003e {\n        setTimeout(() =\u003e resolve(true), 1000);\n    });\n}\n````\n\n![](docs/3.PNG)\n\n---\n\n##### Injector\n\nInjector can be used when Logging from inside of method is needed. Inject as last argument, the ``Logger`` and set it\nto `optional`.\n\n````javascript\n@Method.log({inject: true})\npublic add(args : number[], logger? : Logger) : number {\n    logger.debug('Add method is called');\n    let sum = 0;\n    args.forEach(x =\u003e sum += x);\n    logger.params.data.result = sum;\n    logger.debug(`Total: ${sum}`);\n    return sum;\n}\n````\n\n![](docs/4.PNG)\n\n#### Filter\n\nFilter of logs can be done from the Listener ``beforeLog()`` callback.\n\n````javascript\nbeforeLog: (log: Log, outputType: OutputType) =\u003e {\n    return log.data.importance ! \u003e 2 \u0026\u0026 outputType === OutputType.debug;\n},\n...\n````\n\n\u003e Outputs only the Logs with importance greater than ``2`` and of type `debug`\n\n````javascript\nbeforeLog: (log: Log, outputType: OutputType) =\u003e {\n    return log.data.tag === 'login';\n},\n...\n````\n\n\u003e Outputs only the logs with the Tag `login`\n\nDepending on your needs, filter can be done on many ways as it needed.\n\n### Author\n\n\u003e xeinebiu\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeinebiu%2Ftypescript_logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxeinebiu%2Ftypescript_logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeinebiu%2Ftypescript_logger/lists"}