Gathering detailed insights and metrics for @ts-koa/koa-morgan
Gathering detailed insights and metrics for @ts-koa/koa-morgan
Gathering detailed insights and metrics for @ts-koa/koa-morgan
Gathering detailed insights and metrics for @ts-koa/koa-morgan
npm install @ts-koa/koa-morgan
Typescript
Module System
Min. Node Version
Node Version
NPM Version
71.4
Supply Chain
98.9
Quality
75.6
Maintenance
100
Vulnerability
100
License
TypeScript (73.08%)
JavaScript (26.92%)
Total Downloads
1,203
Last Day
1
Last Week
1
Last Month
4
Last Year
146
2 Stars
14 Commits
1 Watching
1 Branches
1 Contributors
Latest Version
0.0.9
Package Id
@ts-koa/koa-morgan@0.0.9
Unpacked Size
26.67 kB
Size
7.06 kB
File Count
8
NPM Version
8.11.0
Node Version
16.15.1
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-66.7%
1
Compared to previous week
Last month
-20%
4
Compared to previous month
Last year
-65.9%
146
Compared to previous year
HTTP request logger middleware for Koa.js.
A TypeScript version for Koa.js, stripped down from: https://github.com/expressjs/morgan
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm i @ts-koa/koa-morgan
1import { morgan } from "@ts-koa/koa-morgan" 2 3const app = new Koa() 4app.use(morgan())
Recommended that you .use()
this middleware near the top
to "wrap" all subsequent middleware.
Create a new morgan logger middleware function using the given format
and options
.
The format
argument may be a string of a predefined name (see below for the names) or a string of a format string.
1morgan("dev")
1morgan(":method :url :status :res[content-length] - :response-time ms")
Morgan accepts these properties in the options object.
Output logger for writing log lines, defaults to console.log
.
Argument type: MorganLogger
1type MorganLogger = (message: any) => void
A boolean that indicates whether to print out status code with colors or not. Defaults to false
.
If set to true, The :status
token will be colored green for success codes, red for server error codes, yellow for client error codes, cyan for redirection codes, and uncolored for information codes.
Function to determine if logging is skipped, defaults to false
. This function
will be called as skip(req, res)
.
1// EXAMPLE: only log error responses 2morgan("combined", { 3 skip: (ctx: Context) => { 4 return ctx.status < 400 5 }, 6})
There are various pre-defined formats provided:
Standard Apache combined log output.
:remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"
Standard Apache common log output.
:remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length]
Concise output colored by response status for development use.
:method :url :status :response-time ms - :res[content-length]
Shorter than default, also including response time.
:remote-addr :remote-user :method :url HTTP/:http-version :status :res[content-length] - :response-time ms
The minimal output.
:method :url :status :res[content-length] - :response-time ms
The current date and time in UTC. The available formats are:
clf
for the common log format ("10/Oct/2000:13:55:36 +0000"
)iso
for the common ISO 8601 date time format (2000-10-10T13:55:36.000Z
)web
for the common RFC 1123 date time format (Tue, 10 Oct 2000 13:55:36 GMT
)If no format is given, then the default is web
.
The HTTP version of the request.
The HTTP method of the request.
The Referrer header of the request. This will use the standard mis-spelled Referer header if exists, otherwise Referrer.
The remote address of the request. This will use ctx.request.ip
, otherwise the standard req.socket.remoteAddress
value.
The user authenticated as part of Basic auth for the request.
The given header
of the request. If the header is not present, the
value will be displayed as "-"
in the log.
The given header
of the response. If the header is not present, the
value will be displayed as "-"
in the log.
The time between the request coming into morgan
and when the response headers are written, in milliseconds.
The status code of the response.
The URL of the request. Uses ctx.url
.
The contents of the User-Agent header of the request.
Special thanks to the authors of Express.js/Morgan, as I have learned much from this simple project.
I am glad that I started watching the whole series after it's completed. :)
MIT
No vulnerabilities found.
No security vulnerabilities found.