{"id":19761035,"url":"https://github.com/hkust-vislab/v-logger","last_synced_at":"2026-05-17T08:31:39.377Z","repository":{"id":57389746,"uuid":"90590883","full_name":"HKUST-VISLab/v-logger","owner":"HKUST-VISLab","description":"A logger middleware for koa","archived":false,"fork":false,"pushed_at":"2017-05-11T14:35:26.000Z","size":38,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-10T23:27:08.735Z","etag":null,"topics":["koa","logger","logger-middleware","typescript"],"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/HKUST-VISLab.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}},"created_at":"2017-05-08T05:49:21.000Z","updated_at":"2017-05-11T13:54:10.000Z","dependencies_parsed_at":"2022-09-02T09:42:19.936Z","dependency_job_id":null,"html_url":"https://github.com/HKUST-VISLab/v-logger","commit_stats":null,"previous_names":["myaooo/v-logger"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HKUST-VISLab%2Fv-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HKUST-VISLab%2Fv-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HKUST-VISLab%2Fv-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HKUST-VISLab%2Fv-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HKUST-VISLab","download_url":"https://codeload.github.com/HKUST-VISLab/v-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241090718,"owners_count":19908005,"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":["koa","logger","logger-middleware","typescript"],"created_at":"2024-11-12T03:39:24.225Z","updated_at":"2026-05-17T08:31:34.349Z","avatar_url":"https://github.com/HKUST-VISLab.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# v-logger\n\n[![Build Status](https://travis-ci.org/myaooo/v-logger.svg?branch=master)](https://travis-ci.org/myaooo/v-logger.svg?branch=master)\n[![codecov](https://codecov.io/gh/myaooo/v-logger/branch/master/graph/badge.svg)](https://codecov.io/gh/myaooo/v-logger)\n[![Greenkeeper badge](https://badges.greenkeeper.io/HKUST-VISLab/koa-bodyparser-ts.svg)](https://greenkeeper.io/)\n\nA customizable logger module written in Typescript. Extension of the logger is available as a koa logger middleware.\n\n## Basic Usage\n\n```javascript\nconst { logger } = require(\"v-logger\");\n\nlogger.info(\"Hello world\");\n```\n\nCustomizing logging format and logging level:\n\n```javascript\nlogger.format(\"[:date] :name \u003e :level: :msg\");\nlogger.level(\"DEBUG\");\nlogger.info(\"Another hi!\");\n```\n\nor create your own logger with options and write logs to file:\n\n```javascript\nconst fs = require(\"fs\");\n\nconst { Logger } = require(\"v-logger\");\nconst myLogger = new Logger(\"MyLogger\", { \n    format: \"[:date] :name \u003e :level: :msg\",\n    dateFormat: \"iso\",\n    logLevel: \"WARN\",\n    stream: fs.createWriteStream(\"warnings.log\");\n});\nmyLogger.info(\"This message will not be logged.\");\nmyLogger.warn(\"This message will be logged.\");\n```\n\n## Log Levels\n\nThere are 6 pre-defined `LogLevel`s, each associate with an integer value:\n\n```typescript\nVERBOSE: 0;\nDEBUG: 10;\nINFO: 20;\nWARN: 30;\nERROR: 40;\nCRITICAL: 50;\n```\n\nYou can customize your own LogLevel using:\n\n```typescript\nLogLevel.addLevel(\"MY-LEVEL\", 25);\nlogger.log(\"MY-LEVEL\", \"This is a log with custom log level.\");\n```\n\n## Options\n\nAvailable options for customizing a logger instance:\n\n* logLevel: the threshold LogLevel of the logger, all logs with lower level than this one would be emitted.\n    Default to `\"INFO\"`.\n\n* format: a format template for logging, all tokens should start with a `:`.\n    \n    Available tokens for the basic logger are: `date` (the created date of a log record), \n    `name` (the name of the logger), `level` (the level of a log record), `msg` (the message or content of the log).\n\n* stream: a `WritableStream` to write the log to. Default to `process.stdout`.\n\n* dateFormat: a format template for date. Pre-set formats are `\"iso\"` and `\"utc\"`. \n    To customize your own date format, please reference the following available tokens.\n\n`%%`: A literal `%` character.\n\n`%a`: Locale’s abbreviated weekday name.\n\n`%A`: Locale’s full weekday name.\n\n`%b`: Locale’s abbreviated month name.\n\n`%B`: Locale’s full month name.\n\n`%c`: Locale’s appropriate date and time representation.\n\n`%d`: Day of the month as a decimal number [01,31].\n\n`%H`: Hour (24-hour clock) as a decimal number [00,23].\n\n`%I`: Hour (12-hour clock) as a decimal number [01,12].\n\n`%m`: Month as a decimal number [01,12].\n\n`%M`: Minute as a decimal number [00,59].\n\n`%P`: Locale’s equivalent of either AM or PM.\n\n`%S`: Second as a decimal number [00,59].\n\n`%w`: Weekday as a decimal number [0(Sunday),6].\n\n`%x`: Locale’s appropriate date representation.\n\n`%X`: Locale’s appropriate time representation.\n\n`%y`: Year without century as a decimal number [00,99].\n\n`%Y`: Year with century as a decimal number.\n\n`%z`: Time zone offset indicating time difference from UTC/GMT of the form +HHMM or -HHMM,\nwhere H represents decimal hour digits and M represents decimal minute digits [-23:59, +23:59].\n\n## Koa Logger Middleware\n\nCreate a koa logger middleware by:\n\n```typescript\nimport { koaLogger } from \"v-logger\";\nimport * as Koa from \"koa\";\n\nconst app = new Koa();\napp.use(koaLogger(\"MyLogger\"));\n...\n```\n\n### Customizing Logger Middleware\n\n```typescript\nconst options = {\n    format: ':remote-addr [:date] \":method :url HTTP/:http-version\" :status :length - :response-time ms',\n    logLevel: \"INFO\",\n    dateFormat: \"utc\",\n};\napp.use(koaLogger(\"MyLogger\", options));\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhkust-vislab%2Fv-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhkust-vislab%2Fv-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhkust-vislab%2Fv-logger/lists"}