@remix-run/logger-middleware 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,37 +1,47 @@
1
1
  import type { Middleware } from '@remix-run/fetch-router';
2
+ /**
3
+ * Options for the `logger` middleware.
4
+ */
2
5
  export interface LoggerOptions {
3
6
  /**
4
- * The format to use for log messages. Defaults to `[%date] %method %path %status %contentLength`.
7
+ * The format to use for log messages.
5
8
  *
6
9
  * The following tokens are available:
7
10
  *
8
- * - `%date` - The date and time of the request in Apache/nginx log format (dd/Mon/yyyy:HH:mm:ss ±zzzz).
9
- * - `%dateISO` - The date and time of the request in ISO format.
10
- * - `%duration` - The duration of the request in milliseconds.
11
- * - `%contentLength` - The `Content-Length` header of the response.
12
- * - `%contentType` - The `Content-Type` header of the response.
13
- * - `%host` - The host of the request URL.
14
- * - `%hostname` - The hostname of the request URL.
15
- * - `%method` - The method of the request.
16
- * - `%path` - The pathname + search of the request URL.
17
- * - `%pathname` - The pathname of the request URL.
18
- * - `%port` - The port of the request.
19
- * - `%query` - The query (search) string of the request URL.
20
- * - `%referer` - The `Referer` header of the request.
21
- * - `%search` - The search string of the request URL.
22
- * - `%status` - The status code of the response.
23
- * - `%statusText` - The status text of the response.
24
- * - `%url` - The full URL of the request.
25
- * - `%userAgent` - The `User-Agent` header of the request.
11
+ * - `%date` - The date and time of the request in Apache/nginx log format (dd/Mon/yyyy:HH:mm:ss ±zzzz)
12
+ * - `%dateISO` - The date and time of the request in ISO format
13
+ * - `%duration` - The duration of the request in milliseconds
14
+ * - `%contentLength` - The `Content-Length` header of the response
15
+ * - `%contentType` - The `Content-Type` header of the response
16
+ * - `%host` - The host of the request URL
17
+ * - `%hostname` - The hostname of the request URL
18
+ * - `%method` - The method of the request
19
+ * - `%path` - The pathname + search of the request URL
20
+ * - `%pathname` - The pathname of the request URL
21
+ * - `%port` - The port of the request
22
+ * - `%query` - The query (search) string of the request URL
23
+ * - `%referer` - The `Referer` header of the request
24
+ * - `%search` - The search string of the request URL
25
+ * - `%status` - The status code of the response
26
+ * - `%statusText` - The status text of the response
27
+ * - `%url` - The full URL of the request
28
+ * - `%userAgent` - The `User-Agent` header of the request
29
+ *
30
+ * @default '[%date] %method %path %status %contentLength'
26
31
  */
27
32
  format?: string;
28
33
  /**
29
- * The function to use to log messages. Defaults to `console.log`.
34
+ * The function to use to log messages.
35
+ *
36
+ * @default console.log
30
37
  */
31
38
  log?: (message: string) => void;
32
39
  }
33
40
  /**
34
41
  * Creates a middleware handler that logs various request/response info.
42
+ *
43
+ * @param options Options for the logger
44
+ * @returns The logger middleware
35
45
  */
36
46
  export declare function logger(options?: LoggerOptions): Middleware;
37
47
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEzD,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAChC;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,UAAU,CAoC9D"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEzD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,UAAU,CAoC9D"}
@@ -1,5 +1,8 @@
1
1
  /**
2
2
  * Creates a middleware handler that logs various request/response info.
3
+ *
4
+ * @param options Options for the logger
5
+ * @returns The logger middleware
3
6
  */
4
7
  export function logger(options = {}) {
5
8
  let { format = '[%date] %method %path %status %contentLength', log = console.log } = options;
@@ -37,6 +40,9 @@ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', '
37
40
  /**
38
41
  * Formats a date in Apache/nginx log format: "dd/Mon/yyyy:HH:mm:ss ±zzzz"
39
42
  * Example: "23/Sep/2025:11:34:12 -0700"
43
+ *
44
+ * @param date The date to format
45
+ * @returns The formatted date string
40
46
  */
41
47
  function formatApacheDate(date) {
42
48
  let day = String(date.getDate()).padStart(2, '0');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/logger-middleware",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Middleware for logging HTTP requests and responses",
5
5
  "author": "Michael Jackson <mjijackson@gmail.com>",
6
6
  "license": "MIT",
@@ -27,11 +27,11 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^24.6.0",
30
- "typescript": "^5.9.3",
31
- "@remix-run/fetch-router": "0.9.0"
30
+ "@typescript/native-preview": "7.0.0-dev.20251125.1",
31
+ "@remix-run/fetch-router": "0.15.1"
32
32
  },
33
- "peerDependencies": {
34
- "@remix-run/fetch-router": "^0.9.0"
33
+ "dependencies": {
34
+ "@remix-run/fetch-router": "^0.15.1"
35
35
  },
36
36
  "keywords": [
37
37
  "fetch",
@@ -42,9 +42,9 @@
42
42
  "http-logger"
43
43
  ],
44
44
  "scripts": {
45
- "build": "tsc -p tsconfig.build.json",
45
+ "build": "tsgo -p tsconfig.build.json",
46
46
  "clean": "git clean -fdX",
47
- "test": "node --disable-warning=ExperimentalWarning --test './src/**/*.test.ts'",
48
- "typecheck": "tsc --noEmit"
47
+ "test": "node --disable-warning=ExperimentalWarning --test",
48
+ "typecheck": "tsgo --noEmit"
49
49
  }
50
50
  }
package/src/index.ts CHANGED
@@ -1,2 +1 @@
1
1
  export { type LoggerOptions, logger } from './lib/logger.ts'
2
-
package/src/lib/logger.ts CHANGED
@@ -1,39 +1,49 @@
1
1
  import type { Middleware } from '@remix-run/fetch-router'
2
2
 
3
+ /**
4
+ * Options for the `logger` middleware.
5
+ */
3
6
  export interface LoggerOptions {
4
7
  /**
5
- * The format to use for log messages. Defaults to `[%date] %method %path %status %contentLength`.
8
+ * The format to use for log messages.
6
9
  *
7
10
  * The following tokens are available:
8
11
  *
9
- * - `%date` - The date and time of the request in Apache/nginx log format (dd/Mon/yyyy:HH:mm:ss ±zzzz).
10
- * - `%dateISO` - The date and time of the request in ISO format.
11
- * - `%duration` - The duration of the request in milliseconds.
12
- * - `%contentLength` - The `Content-Length` header of the response.
13
- * - `%contentType` - The `Content-Type` header of the response.
14
- * - `%host` - The host of the request URL.
15
- * - `%hostname` - The hostname of the request URL.
16
- * - `%method` - The method of the request.
17
- * - `%path` - The pathname + search of the request URL.
18
- * - `%pathname` - The pathname of the request URL.
19
- * - `%port` - The port of the request.
20
- * - `%query` - The query (search) string of the request URL.
21
- * - `%referer` - The `Referer` header of the request.
22
- * - `%search` - The search string of the request URL.
23
- * - `%status` - The status code of the response.
24
- * - `%statusText` - The status text of the response.
25
- * - `%url` - The full URL of the request.
26
- * - `%userAgent` - The `User-Agent` header of the request.
12
+ * - `%date` - The date and time of the request in Apache/nginx log format (dd/Mon/yyyy:HH:mm:ss ±zzzz)
13
+ * - `%dateISO` - The date and time of the request in ISO format
14
+ * - `%duration` - The duration of the request in milliseconds
15
+ * - `%contentLength` - The `Content-Length` header of the response
16
+ * - `%contentType` - The `Content-Type` header of the response
17
+ * - `%host` - The host of the request URL
18
+ * - `%hostname` - The hostname of the request URL
19
+ * - `%method` - The method of the request
20
+ * - `%path` - The pathname + search of the request URL
21
+ * - `%pathname` - The pathname of the request URL
22
+ * - `%port` - The port of the request
23
+ * - `%query` - The query (search) string of the request URL
24
+ * - `%referer` - The `Referer` header of the request
25
+ * - `%search` - The search string of the request URL
26
+ * - `%status` - The status code of the response
27
+ * - `%statusText` - The status text of the response
28
+ * - `%url` - The full URL of the request
29
+ * - `%userAgent` - The `User-Agent` header of the request
30
+ *
31
+ * @default '[%date] %method %path %status %contentLength'
27
32
  */
28
33
  format?: string
29
34
  /**
30
- * The function to use to log messages. Defaults to `console.log`.
35
+ * The function to use to log messages.
36
+ *
37
+ * @default console.log
31
38
  */
32
39
  log?: (message: string) => void
33
40
  }
34
41
 
35
42
  /**
36
43
  * Creates a middleware handler that logs various request/response info.
44
+ *
45
+ * @param options Options for the logger
46
+ * @returns The logger middleware
37
47
  */
38
48
  export function logger(options: LoggerOptions = {}): Middleware {
39
49
  let { format = '[%date] %method %path %status %contentLength', log = console.log } = options
@@ -78,6 +88,9 @@ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', '
78
88
  /**
79
89
  * Formats a date in Apache/nginx log format: "dd/Mon/yyyy:HH:mm:ss ±zzzz"
80
90
  * Example: "23/Sep/2025:11:34:12 -0700"
91
+ *
92
+ * @param date The date to format
93
+ * @returns The formatted date string
81
94
  */
82
95
  function formatApacheDate(date: Date): string {
83
96
  let day = String(date.getDate()).padStart(2, '0')