logixlysia 3.0.1 → 3.0.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.0.2](https://github.com/PunGrumpy/logixlysia/compare/v3.0.1...v3.0.2) (2024-04-08)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **logger:** add `config` property for logging configuration ([27d80eb](https://github.com/PunGrumpy/logixlysia/commit/27d80eb6b0c3a4a40a96738b235d9bc6b117c804))
9
+
3
10
  ## [3.0.1](https://github.com/PunGrumpy/logixlysia/compare/v3.0.0...v3.0.1) (2024-04-08)
4
11
 
5
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logixlysia",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "🦊 Logixlysia is a logger for Elysia",
5
5
  "type": "module",
6
6
  "module": "src/index.ts",
package/src/logger.ts CHANGED
@@ -4,8 +4,15 @@ import methodString from './utils/method'
4
4
  import logString from './utils/log'
5
5
  import pathString from './utils/path'
6
6
  import statusString from './utils/status'
7
- import { HttpError, RequestInfo } from './types'
8
- import { LogLevel, LogData, Logger, StoreData, Options } from './types'
7
+ import {
8
+ LogLevel,
9
+ LogData,
10
+ Logger,
11
+ StoreData,
12
+ Options,
13
+ RequestInfo,
14
+ HttpError
15
+ } from './types'
9
16
 
10
17
  /**
11
18
  * Logs a message.
@@ -52,12 +59,12 @@ function buildLogMessage(
52
59
  const statusStr = statusString(data.status || 200)
53
60
  const messageStr = data.message || ''
54
61
  const ipStr =
55
- options?.ip && request.headers.get('x-forwarded-for')
62
+ options?.config?.ip && request.headers.get('x-forwarded-for')
56
63
  ? `IP: ${request.headers.get('x-forwarded-for')}`
57
64
  : ''
58
65
 
59
66
  const logFormat =
60
- options?.customLogFormat ||
67
+ options?.config?.customLogFormat ||
61
68
  '🦊 {now} {level} {duration} {method} {pathname} {status} {message} {ip}'
62
69
  const logMessage = logFormat
63
70
  .replace('{now}', nowStr)
@@ -81,7 +88,7 @@ function buildLogMessage(
81
88
  export const createLogger = (options?: Options): Logger => ({
82
89
  log: (level, request, data, store) =>
83
90
  log(level, request, data, store, options),
84
- customLogFormat: options?.customLogFormat
91
+ customLogFormat: options?.config?.customLogFormat
85
92
  })
86
93
 
87
94
  /**
package/src/types.ts CHANGED
@@ -45,8 +45,10 @@ class HttpError extends Error {
45
45
  }
46
46
 
47
47
  interface Options {
48
- ip?: boolean
49
- customLogFormat?: string
48
+ config?: {
49
+ ip?: boolean
50
+ customLogFormat?: string
51
+ }
50
52
  }
51
53
 
52
54
  export {
@@ -12,9 +12,11 @@ describe('Logixlysia with IP logging enabled', () => {
12
12
  server = new Elysia()
13
13
  .use(
14
14
  logger({
15
- ip: true,
16
- customLogFormat:
17
- '🦊 {now} {duration} {level} {method} {pathname} {status} {message} {ip}'
15
+ config: {
16
+ ip: true,
17
+ customLogFormat:
18
+ '🦊 {now} {duration} {level} {method} {pathname} {status} {message} {ip}'
19
+ }
18
20
  })
19
21
  )
20
22
  .get('/', ctx => {
@@ -69,9 +71,11 @@ describe('Logixlysia with IP logging disabled', () => {
69
71
  server = new Elysia()
70
72
  .use(
71
73
  logger({
72
- ip: false,
73
- customLogFormat:
74
- '🦊 {now} {duration} {level} {method} {pathname} {status} {message} {ip}'
74
+ config: {
75
+ ip: false,
76
+ customLogFormat:
77
+ '🦊 {now} {duration} {level} {method} {pathname} {status} {message} {ip}'
78
+ }
75
79
  })
76
80
  )
77
81
  .get('/', () => '🦊 Logixlysia Getting')