logixlysia 4.2.2 → 4.2.3

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 DELETED
@@ -1,291 +0,0 @@
1
- # Changelog
2
-
3
- ## [4.2.2](https://github.com/PunGrumpy/logixlysia/compare/v4.2.1...v4.2.2) (2025-04-14)
4
-
5
-
6
- ### Bug Fixes
7
-
8
- * **package:** remove unused devDependencies for cleaner setup ([7dab60f](https://github.com/PunGrumpy/logixlysia/commit/7dab60fcbccac59f8ac092ab4024c6ca249d00c2))
9
-
10
- ## [4.2.1](https://github.com/PunGrumpy/logixlysia/compare/v4.2.0...v4.2.1) (2025-04-13)
11
-
12
-
13
- ### Bug Fixes
14
-
15
- * **ci:** replace lint step with Reviewdog integration for enhanced linting feedback ([81cd883](https://github.com/PunGrumpy/logixlysia/commit/81cd883b29723ffe640cc99dff9716a1613989ef))
16
-
17
- ## [4.2.0](https://github.com/PunGrumpy/logixlysia/compare/v4.1.2...v4.2.0) (2025-04-13)
18
-
19
-
20
- ### Features
21
-
22
- * **docs:** add screenshot to documentation introduction ([800bb17](https://github.com/PunGrumpy/logixlysia/commit/800bb17dcfda88699cd7a0a2dc2e199e5704ce61))
23
- * **website:** add new components and integrate react-fast-marquee ([6332f62](https://github.com/PunGrumpy/logixlysia/commit/6332f622c22fccf4cbadfb2a0099b9fac723f61a))
24
- * **website:** add Open Graph image for enhanced social sharing ([de35d41](https://github.com/PunGrumpy/logixlysia/commit/de35d413bf6a10b06933eb2619d3cb6459618c3e))
25
- * **website:** add transparent mode to navigation title ([9c01757](https://github.com/PunGrumpy/logixlysia/commit/9c01757f8808b5792b792fc1ed56e5b6e26603d2))
26
- * **website:** add website documentation ([82e281c](https://github.com/PunGrumpy/logixlysia/commit/82e281cd5c08fa948ecf103eb70f218e61029142))
27
- * **website:** enhance logging features and update documentation ([fa7ea45](https://github.com/PunGrumpy/logixlysia/commit/fa7ea45ae8c535a22b52e94a46df5931009e013f))
28
- * **website:** initialize new documentation website with Fumadocs ([c864d9f](https://github.com/PunGrumpy/logixlysia/commit/c864d9f00ea6d0250f2db8b20a994975da18185e))
29
- * **website:** integrate GitHub info component into layout ([5cd282c](https://github.com/PunGrumpy/logixlysia/commit/5cd282c072e56d90a7554a78dad1f27e8eb13400))
30
-
31
-
32
- ### Bug Fixes
33
-
34
- * **docs:** correct license information in documentation ([e64f156](https://github.com/PunGrumpy/logixlysia/commit/e64f1565a2100a08ee324ddf68769726dcc6d9ff))
35
- * **docs:** update file logging examples for clarity and consistency ([1d8653f](https://github.com/PunGrumpy/logixlysia/commit/1d8653f5aa97f8b6d829a10c0a510fc5a5b7dcae))
36
- * **docs:** update help section for user support ([84e5052](https://github.com/PunGrumpy/logixlysia/commit/84e5052ddf4ef8e636d68be113d866df2d13fd09))
37
- * **playground:** correct class name syntax for overflow visibility ([25ed919](https://github.com/PunGrumpy/logixlysia/commit/25ed919c1592129d8495afbc2927befb0c431fa0))
38
- * **website:** adjust z-index for background image and hero component ([af593a7](https://github.com/PunGrumpy/logixlysia/commit/af593a709d625df06f2f0e7ecff55764be46cdd5))
39
- * **website:** adjust z-index for hero component to improve visibility ([4cc144e](https://github.com/PunGrumpy/logixlysia/commit/4cc144e50c5e0e869e62c3821edd2216acf4cacd))
40
- * **website:** simplify sidebar configuration in layout component ([dc7e479](https://github.com/PunGrumpy/logixlysia/commit/dc7e47962085c4922dcfaad83e1ce0e38dcfeff0))
41
- * **website:** update logo assets and adjust class names ([18c8c57](https://github.com/PunGrumpy/logixlysia/commit/18c8c57a2337f3242e77eb0234afee487039f554))
42
- * **website:** update sidebar configuration to include collapsible property ([2d27ee3](https://github.com/PunGrumpy/logixlysia/commit/2d27ee31b3eeb79505a70dee2fef214a45fb1a9e))
43
-
44
- ## [4.1.2](https://github.com/PunGrumpy/logixlysia/compare/v4.1.1...v4.1.2) (2025-02-24)
45
-
46
-
47
- ### Bug Fixes
48
-
49
- * **logixlysia:** ensure message is a string in response headers ([2f9eeee](https://github.com/PunGrumpy/logixlysia/commit/2f9eeeeb1ec1ab7454e6633c28aa112963f54ed6)), closes [#74](https://github.com/PunGrumpy/logixlysia/issues/74)
50
-
51
- ## [4.1.1](https://github.com/PunGrumpy/logixlysia/compare/v4.1.0...v4.1.1) (2025-01-31)
52
-
53
-
54
- ### Bug Fixes
55
-
56
- * **package:** wrong place @elysiajs/swagger and move to devDependencies ([a5e1a96](https://github.com/PunGrumpy/logixlysia/commit/a5e1a96606f53883a50331a94c1ba844dff67dc3))
57
-
58
- ## [4.1.0](https://github.com/PunGrumpy/logixlysia/compare/v4.0.0...v4.1.0) (2025-01-31)
59
-
60
-
61
- ### Features
62
-
63
- * **logging:** add status string parsing and error handling ([32800ac](https://github.com/PunGrumpy/logixlysia/commit/32800acb0fbfdf957e2975b5773b0a350e3af0d8)), closes [#71](https://github.com/PunGrumpy/logixlysia/issues/71)
64
-
65
- ## [4.0.0](https://github.com/PunGrumpy/logixlysia/compare/v3.7.0...v4.0.0) (2024-10-28)
66
-
67
-
68
- ### ⚠ BREAKING CHANGES
69
-
70
- * **timestamp:** The timestamp format in logs will now respect the new timestamp configuration options when provided
71
-
72
- ### Features
73
-
74
- * **timestamp:** add customize timestamp formatting ([5a4e2a5](https://github.com/PunGrumpy/logixlysia/commit/5a4e2a5230443761d8c2ca99d9ebc586ff26a8c0)), closes [#69](https://github.com/PunGrumpy/logixlysia/issues/69)
75
-
76
- ## [3.7.0](https://github.com/PunGrumpy/logixlysia/compare/v3.6.2...v3.7.0) (2024-09-26)
77
-
78
-
79
- ### Features
80
-
81
- * **optional:** add startup message config ([#66](https://github.com/PunGrumpy/logixlysia/pull/66)) ([c7a76db](https://github.com/PunGrumpy/logixlysia/commit/c7a76dbc0f30f4c9c607b52dedc49979e26b67ec)) by [@n0ky4](https://github.com/n0ky4)
82
-
83
- ## [3.6.2](https://github.com/PunGrumpy/logixlysia/compare/v3.6.1...v3.6.2) (2024-09-18)
84
-
85
-
86
- ### Bug Fixes
87
-
88
- * **logtofile:** store error to log file ([1bb2d07](https://github.com/PunGrumpy/logixlysia/commit/1bb2d07ae0c815742a9eb7c930ac8487ac287b2c)), closes [#63](https://github.com/PunGrumpy/logixlysia/issues/63)
89
-
90
- ## [3.6.1](https://github.com/PunGrumpy/logixlysia/compare/v3.6.0...v3.6.1) (2024-08-21)
91
-
92
-
93
- ### Performance Improvements
94
-
95
- * **logger:** improve performance and fix TypeScript errors ([d3ed751](https://github.com/PunGrumpy/logixlysia/commit/d3ed751041443b9bd2ce53350994e1443df40971))
96
-
97
- ## [3.6.0](https://github.com/PunGrumpy/logixlysia/compare/v3.5.0...v3.6.0) (2024-07-24)
98
-
99
-
100
- ### Features
101
-
102
- * **custom-log:** add unix epoch timestamp option on `customLogFormat` configuration ([58d3e5b](https://github.com/PunGrumpy/logixlysia/commit/58d3e5b89bfef86aed1f5daa70d9a39982750073)), closes [#56](https://github.com/PunGrumpy/logixlysia/issues/56)
103
- * **transports:** add custom tranporter support for flexible logging ([69e1b89](https://github.com/PunGrumpy/logixlysia/commit/69e1b8991d323d8463fb81cf5bf1b441f678318b)), closes [#51](https://github.com/PunGrumpy/logixlysia/issues/51)
104
-
105
- ## [3.5.0](https://github.com/PunGrumpy/logixlysia/compare/v3.4.0...v3.5.0) (2024-07-11)
106
-
107
-
108
- ### Features
109
-
110
- * **config:** add option to toggle server start banner display ([c975cd6](https://github.com/PunGrumpy/logixlysia/commit/c975cd6da94e39d055cdf7bc43cc1ed1eec4971e)), closes [#52](https://github.com/PunGrumpy/logixlysia/issues/52)
111
-
112
- ## [3.4.0](https://github.com/PunGrumpy/logixlysia/compare/v3.3.2...v3.4.0) (2024-06-17)
113
-
114
-
115
- ### Features
116
-
117
- * **logger:** add file logging capability ([6d913a3](https://github.com/PunGrumpy/logixlysia/commit/6d913a3dcc6cbba40bcaa4b6c4c4a4b474a90969))
118
-
119
-
120
- ### Bug Fixes
121
-
122
- * **logger:** remove ANSI color codes from log files ([df42315](https://github.com/PunGrumpy/logixlysia/commit/df423151399f9436121b0d5d4a9b0424befdc835))
123
-
124
- ## [3.3.2](https://github.com/PunGrumpy/logixlysia/compare/v3.3.1...v3.3.2) (2024-06-06)
125
-
126
-
127
- ### Bug Fixes
128
-
129
- * **npm-ignore:** accidentally ignore `tsconfig.json` ([85997f7](https://github.com/PunGrumpy/logixlysia/commit/85997f7dd8bb22b4811a7555e0a56e0cfb3ee269))
130
-
131
- ## [3.3.1](https://github.com/PunGrumpy/logixlysia/compare/v3.3.0...v3.3.1) (2024-06-01)
132
-
133
-
134
- ### Bug Fixes
135
-
136
- * **deps:** move `ESLint` and related packages to dev dependencies ([98de50c](https://github.com/PunGrumpy/logixlysia/commit/98de50c6c3bffc5939963ebd04563204c7c70793)), closes [#46](https://github.com/PunGrumpy/logixlysia/issues/46)
137
-
138
- ## [3.3.0](https://github.com/PunGrumpy/logixlysia/compare/v3.2.0...v3.3.0) (2024-05-22)
139
-
140
-
141
- ### Features
142
-
143
- * **color:** new color for methods (matching Postman color) ([0528886](https://github.com/PunGrumpy/logixlysia/commit/0528886ef9fdaa466e4b78b46fb09d31731b0520))
144
-
145
- ## [3.2.0](https://github.com/PunGrumpy/logixlysia/compare/v3.1.0...v3.2.0) (2024-05-07)
146
-
147
-
148
- ### Features
149
-
150
- * update logger function name for clarity ([9badffc](https://github.com/PunGrumpy/logixlysia/commit/9badffc286fc13feda9eeffd28881990ae437c9f))
151
-
152
- ## [3.1.0](https://github.com/PunGrumpy/logixlysia/compare/v3.0.2...v3.1.0) (2024-04-09)
153
-
154
-
155
- ### Features
156
-
157
- * **logger:** add log filtering functional ([af7d9ec](https://github.com/PunGrumpy/logixlysia/commit/af7d9ec5b2bb5ff5942d1a586be23a9d23a2c1cf)), closes [#38](https://github.com/PunGrumpy/logixlysia/issues/38)
158
-
159
-
160
- ### Bug Fixes
161
-
162
- * CI/CD GitHub Actions ([3c40092](https://github.com/PunGrumpy/logixlysia/commit/3c40092bd0ac7bf8bd601a299453cf5080224234))
163
-
164
- ## [3.0.2](https://github.com/PunGrumpy/logixlysia/compare/v3.0.1...v3.0.2) (2024-04-08)
165
-
166
-
167
- ### Bug Fixes
168
-
169
- * **logger:** add `config` property for logging configuration ([27d80eb](https://github.com/PunGrumpy/logixlysia/commit/27d80eb6b0c3a4a40a96738b235d9bc6b117c804))
170
-
171
- ## [3.0.1](https://github.com/PunGrumpy/logixlysia/compare/v3.0.0...v3.0.1) (2024-04-08)
172
-
173
-
174
- ### Bug Fixes
175
-
176
- * **logger:** use correct status code in error log message ([a3ec49c](https://github.com/PunGrumpy/logixlysia/commit/a3ec49cd3fc1dc7f01a29b21e4de9cf543329c43)), closes [#33](https://github.com/PunGrumpy/logixlysia/issues/33)
177
-
178
- ## [3.0.0](https://github.com/PunGrumpy/logixlysia/compare/v2.3.1...v3.0.0) (2024-04-08)
179
-
180
-
181
- ### ⚠ BREAKING CHANGES
182
-
183
- * Added support for custom log format in the logger
184
- * Enhanced flexibility for define thier preferred log message structure
185
-
186
- ### Features
187
-
188
- * **options:** add support for custom log format ([acc9380](https://github.com/PunGrumpy/logixlysia/commit/acc9380ea25691e7d7fec175094cb6a9878b6c69))
189
-
190
- ## [2.3.1](https://github.com/PunGrumpy/logixlysia/compare/v2.3.0...v2.3.1) (2024-04-07)
191
-
192
-
193
- ### Bug Fixes
194
-
195
- * **index:** remove duplicate logging when options IP enabled ([2e99bd6](https://github.com/PunGrumpy/logixlysia/commit/2e99bd628b7160fb43161ca08e49f711b74e8666))
196
-
197
- ## [2.3.0](https://github.com/PunGrumpy/logixlysia/compare/v2.2.3...v2.3.0) (2024-04-06)
198
-
199
-
200
- ### Features
201
-
202
- * **logger:** handle HTTP errors and log with appropriate status code ([276b3c4](https://github.com/PunGrumpy/logixlysia/commit/276b3c41334bcf1cefd032ae11f71fb8cda2bc9a)), closes [#24](https://github.com/PunGrumpy/logixlysia/issues/24)
203
-
204
- ## [2.2.3](https://github.com/PunGrumpy/logixlysia/compare/v2.2.2...v2.2.3) (2024-04-06)
205
-
206
-
207
- ### Bug Fixes
208
-
209
- * **error-log:** add global to `onError` ([e217baa](https://github.com/PunGrumpy/logixlysia/commit/e217baad9f72fa3e866f959f371768ed2ed22e33))
210
- * **ts2488:** that method return an iterator ([35da93f](https://github.com/PunGrumpy/logixlysia/commit/35da93f75e34ff212ddd31ff951425551f31c764))
211
-
212
- ## [2.2.2](https://github.com/PunGrumpy/logixlysia/compare/v2.2.1...v2.2.2) (2024-04-06)
213
-
214
-
215
- ### Bug Fixes
216
-
217
- * **eslint:** change to use `eslint.config.cjs` instead `.eslintrc.cjs` ([506a33b](https://github.com/PunGrumpy/logixlysia/commit/506a33bc6540614a0b912ddedec109b2215affa3))
218
- * package.json to reduce vulnerabilities ([f768e88](https://github.com/PunGrumpy/logixlysia/commit/f768e88acd7d7c1faf32dab06a467c2cd6ba8f9c))
219
-
220
- ## [2.2.1](https://github.com/PunGrumpy/logixlysia/compare/v2.2.0...v2.2.1) (2024-03-19)
221
-
222
-
223
- ### Bug Fixes
224
-
225
- * **index:** remove `onBeforeHandle` for avoid repeat logging ([4c6f0b9](https://github.com/PunGrumpy/logixlysia/commit/4c6f0b9912a4319ada15ad2a5110a9ed34f08a11))
226
-
227
-
228
- ### Reverts
229
-
230
- * **deps:** new come back to old version ([361ac6b](https://github.com/PunGrumpy/logixlysia/commit/361ac6b2821ac897c1a4658cbfa1b5eb1a190804))
231
-
232
- ## [2.2.0](https://github.com/PunGrumpy/logixlysia/compare/v2.1.0...v2.2.0) (2024-03-19)
233
-
234
-
235
- ### Features
236
-
237
- * **options:** add show ip ([4e997c5](https://github.com/PunGrumpy/logixlysia/commit/4e997c557e9aef6046a93e0cab9fe11a87df3430))
238
-
239
-
240
- ### Bug Fixes
241
-
242
- * **logger:** change to use array and push them ([3feefb7](https://github.com/PunGrumpy/logixlysia/commit/3feefb7a8dddc42c4eec54de40ab9dd8d5c70e70))
243
-
244
- ## [2.1.0](https://github.com/PunGrumpy/logixlysia/compare/v2.0.2...v2.1.0) (2024-01-25)
245
-
246
-
247
- ### Features
248
-
249
- * **logger:** implement asynchronous logging functionality ([1017af0](https://github.com/PunGrumpy/logixlysia/commit/1017af0a28bd6121a85ec814a9177fd303c2572c))
250
-
251
- ## [2.0.2](https://github.com/PunGrumpy/logixlysia/compare/v2.0.1...v2.0.2) (2024-01-07)
252
-
253
-
254
- ### Bug Fixes
255
-
256
- * **logger:** change time from `iso` to `local` ([33ff28a](https://github.com/PunGrumpy/logixlysia/commit/33ff28a4a41db1dda7ca224e4807bd2451b95985))
257
-
258
- ## [2.0.1](https://github.com/PunGrumpy/logixlysia/compare/v2.0.0...v2.0.1) (2024-01-03)
259
-
260
-
261
- ### Bug Fixes
262
-
263
- * **index:** elysia `0.8.8` doesn't contain `app` variable ([72f2314](https://github.com/PunGrumpy/logixlysia/commit/72f2314adf392b2e5387bb731f1417bf689e2dd9))
264
-
265
- ## [2.0.0](https://github.com/PunGrumpy/logixlysia/compare/v1.0.0...v2.0.0) (2023-11-19)
266
-
267
-
268
- ### Features
269
-
270
- * **ci/cd:** separate deploy workflows from ci workflows ([e0344ae](https://github.com/PunGrumpy/logixlysia/commit/e0344ae32f711d140b1c914164e8eb7a57181558))
271
-
272
- ## 1.0.0 (2023-11-18)
273
-
274
-
275
- ### Features
276
-
277
- * add example for test ([8f0f1ee](https://github.com/PunGrumpy/logixlysia/commit/8f0f1ee01de5e5c639687bf0971f0347c3516ed0))
278
- * add log on start ([f1adeb9](https://github.com/PunGrumpy/logixlysia/commit/f1adeb9c620b42a2639ea6f01fa3e0ebd583ee8f))
279
- * add logger format and enhance logging functionality ([c0887e8](https://github.com/PunGrumpy/logixlysia/commit/c0887e8eed6142a476d2fd7eb343ef6933e26d31))
280
- * add new style on logging ([f1d9583](https://github.com/PunGrumpy/logixlysia/commit/f1d95832eacd6528c23454b914c61e09b4c1b83a))
281
- * **ci:** add google automated workflows ([526e069](https://github.com/PunGrumpy/logixlysia/commit/526e0695029b0235a268445fd1c72b267c030c13))
282
- * setting environment ([6f5e553](https://github.com/PunGrumpy/logixlysia/commit/6f5e553744999c70de1d8fb1b42a5eb7b75d8798))
283
-
284
-
285
- ### Bug Fixes
286
-
287
- * change name ([ee0c164](https://github.com/PunGrumpy/logixlysia/commit/ee0c1645be16a582c4df03874fdf0712e27a9e6a))
288
- * change to use chalk instead piccolors ([b2fe4f5](https://github.com/PunGrumpy/logixlysia/commit/b2fe4f5a8dce51731e1729b9b0f2c7a15d280978))
289
- * **types:** add types ([38e1f63](https://github.com/PunGrumpy/logixlysia/commit/38e1f63b4b92f4829772d638d45d7bad8182dbdc))
290
- * update jsdocs and add new banner ([226c7eb](https://github.com/PunGrumpy/logixlysia/commit/226c7ebac504f661e58a9581c54e1937dfbea4a8))
291
- * **utils:** update jsdocs ([8cab996](https://github.com/PunGrumpy/logixlysia/commit/8cab996e757d997d3a05183e85d4bfe684fdb11d))
@@ -1 +0,0 @@
1
- export { default as startServer } from './start-server'
@@ -1,33 +0,0 @@
1
- import type { Options, Server } from '../interfaces'
2
-
3
- const createBoxText = (text: string, width: number): string => {
4
- const paddingLength = Math.max(0, (width - text.length) / 2)
5
- const padding = ' '.repeat(paddingLength)
6
- return `${padding}${text}${padding}`.padEnd(width)
7
- }
8
-
9
- export default function startServer(config: Server, options?: Options): void {
10
- const { hostname, port, protocol } = config
11
- const showBanner = options?.config?.startupMessageFormat !== 'simple'
12
-
13
- if (showBanner) {
14
- const ELYSIA_VERSION = import.meta.require('elysia/package.json').version
15
- const title = `Elysia v${ELYSIA_VERSION}`
16
- const message = `🦊 Elysia is running at ${protocol}://${hostname}:${port}`
17
- const boxWidth = Math.max(title.length, message.length) + 4
18
- const border = '─'.repeat(boxWidth)
19
- const emptyLine = createBoxText('', boxWidth)
20
-
21
- console.log(`
22
- ┌${border}┐
23
- │${emptyLine}│
24
- │${createBoxText(title, boxWidth)}│
25
- │${emptyLine}│
26
- │${createBoxText(message, boxWidth)}│
27
- │${emptyLine}│
28
- └${border}┘
29
- `)
30
- } else {
31
- console.log(`🦊 Elysia is running at ${protocol}://${hostname}:${port}`)
32
- }
33
- }
@@ -1,19 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- import type { ColorMap } from '../interfaces'
4
-
5
- export const LogLevelColorMap: ColorMap = {
6
- INFO: chalk.bgGreen.black,
7
- WARNING: chalk.bgYellow.black,
8
- ERROR: chalk.bgRed.black
9
- }
10
-
11
- export const HttpMethodColorMap: ColorMap = {
12
- GET: chalk.green,
13
- POST: chalk.yellow,
14
- PUT: chalk.blue,
15
- PATCH: chalk.magentaBright,
16
- DELETE: chalk.red,
17
- HEAD: chalk.cyan,
18
- OPTIONS: chalk.magenta
19
- }
@@ -1,27 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- const timeUnits = [
4
- { unit: 's', threshold: 1e9, decimalPlaces: 2 },
5
- { unit: 'ms', threshold: 1e6, decimalPlaces: 0 },
6
- { unit: 'µs', threshold: 1e3, decimalPlaces: 0 },
7
- { unit: 'ns', threshold: 1, decimalPlaces: 0 }
8
- ]
9
-
10
- export default function durationString(
11
- beforeTime: bigint,
12
- useColors: boolean
13
- ): string {
14
- const nanoseconds = Number(process.hrtime.bigint() - beforeTime)
15
-
16
- for (const { unit, threshold, decimalPlaces } of timeUnits) {
17
- if (nanoseconds >= threshold) {
18
- const value = (nanoseconds / threshold).toFixed(decimalPlaces)
19
- const timeStr = `${value}${unit}`.padStart(8).padEnd(16)
20
- return useColors ? chalk.gray(timeStr) : timeStr
21
- }
22
- }
23
-
24
- return useColors
25
- ? chalk.gray('0ns'.padStart(8).padEnd(16))
26
- : '0ns'.padStart(8).padEnd(16)
27
- }
@@ -1,7 +0,0 @@
1
- export { HttpMethodColorMap, LogLevelColorMap } from './color-mapping'
2
- export { default as durationString } from './duration'
3
- export { default as logString } from './log'
4
- export { default as methodString } from './method'
5
- export { default as pathString } from './path'
6
- export { default as statusString } from './status'
7
- export { formatTimestamp } from './timestamp'
@@ -1,9 +0,0 @@
1
- import type { LogLevel } from '../interfaces'
2
- import { LogLevelColorMap } from './color-mapping'
3
-
4
- export default function logString(level: LogLevel, useColors: boolean): string {
5
- const levelStr = level.toUpperCase()
6
- return useColors
7
- ? LogLevelColorMap[levelStr]?.(levelStr.padEnd(7)) || levelStr
8
- : levelStr.padEnd(7)
9
- }
@@ -1,11 +0,0 @@
1
- import { HttpMethodColorMap } from './color-mapping'
2
-
3
- export default function methodString(
4
- method: string,
5
- useColors: boolean
6
- ): string {
7
- const colorFunction = HttpMethodColorMap[method]
8
- return useColors && colorFunction
9
- ? colorFunction(method.padEnd(7))
10
- : method.padEnd(7)
11
- }
@@ -1,11 +0,0 @@
1
- import type { RequestInfo } from '../interfaces'
2
-
3
- export default function pathString(
4
- requestInfo: RequestInfo
5
- ): string | undefined {
6
- try {
7
- return new URL(requestInfo.url).pathname
8
- } catch {
9
- return undefined
10
- }
11
- }
@@ -1,33 +0,0 @@
1
- import chalk from 'chalk'
2
- import { StatusMap } from 'elysia'
3
-
4
- export function getStatusCode(status: string | number): number {
5
- if (typeof status === 'number') {
6
- return status
7
- }
8
- return (StatusMap as Record<string, number>)[status] || 500
9
- }
10
-
11
- export default function statusString(
12
- status: number,
13
- useColors: boolean
14
- ): string {
15
- const statusStr = status.toString()
16
- if (!useColors) {
17
- return statusStr
18
- }
19
-
20
- if (status >= 500) {
21
- return chalk.red(statusStr)
22
- }
23
- if (status >= 400) {
24
- return chalk.yellow(statusStr)
25
- }
26
- if (status >= 300) {
27
- return chalk.cyan(statusStr)
28
- }
29
- if (status >= 200) {
30
- return chalk.green(statusStr)
31
- }
32
- return chalk.white(statusStr)
33
- }
@@ -1,48 +0,0 @@
1
- import type { TimestampConfig } from '../interfaces'
2
-
3
- // const DEFAULT_TIMESTAMP_FORMAT = 'yyyy-mm-dd HH:MM:ss'
4
- const SYS_TIME = 'SYS:STANDARD'
5
-
6
- const pad = (n: number): string => n.toString().padStart(2, '0')
7
-
8
- function formatSystemTime(date: Date): string {
9
- const year = date.getFullYear()
10
- const month = pad(date.getMonth() + 1)
11
- const day = pad(date.getDate())
12
- const hours = pad(date.getHours())
13
- const minutes = pad(date.getMinutes())
14
- const seconds = pad(date.getSeconds())
15
- const ms = date.getMilliseconds().toString().padStart(3, '0')
16
-
17
- return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${ms}`
18
- }
19
-
20
- function formatCustomTime(date: Date, format: string): string {
21
- const tokens: { [key: string]: string | number } = {
22
- yyyy: date.getFullYear(),
23
- yy: date.getFullYear().toString().slice(-2),
24
- mm: pad(date.getMonth() + 1),
25
- dd: pad(date.getDate()),
26
- HH: pad(date.getHours()),
27
- MM: pad(date.getMinutes()),
28
- ss: pad(date.getSeconds()),
29
- SSS: pad(date.getMilliseconds()),
30
- Z: -date.getTimezoneOffset() / 60
31
- }
32
-
33
- return format.replace(/yyyy|yy|mm|dd|HH|MM|ss|SSS|Z/g, match =>
34
- (tokens[match] ?? '').toString()
35
- )
36
- }
37
-
38
- export function formatTimestamp(date: Date, config?: TimestampConfig): string {
39
- if (!config || !config.translateTime) {
40
- return date.toISOString()
41
- }
42
-
43
- if (config.translateTime === true || config.translateTime === SYS_TIME) {
44
- return formatSystemTime(date)
45
- }
46
-
47
- return formatCustomTime(date, config.translateTime)
48
- }
package/src/index.ts DELETED
@@ -1,46 +0,0 @@
1
- import { Elysia } from 'elysia'
2
-
3
- import { startServer } from './extensions'
4
- import { getStatusCode } from './helpers/status'
5
- import type { HttpError, Options, Server } from './interfaces'
6
- import { createLogger } from './logger'
7
-
8
- export default function logixlysia(options?: Options): Elysia {
9
- const log = createLogger(options)
10
-
11
- return new Elysia({
12
- name: 'Logixlysia'
13
- })
14
- .onStart(ctx => {
15
- const showStartupMessage = options?.config?.showStartupMessage ?? true
16
- if (showStartupMessage) {
17
- startServer(ctx.server as Server, options)
18
- }
19
- })
20
- .onRequest(ctx => {
21
- ctx.store = { beforeTime: process.hrtime.bigint() }
22
- })
23
- .onAfterHandle({ as: 'global' }, ({ request, set, store }) => {
24
- const status = getStatusCode(set.status || 200)
25
- log.log(
26
- 'INFO',
27
- request,
28
- {
29
- status,
30
- message: String(set.headers?.['x-message'] || '')
31
- },
32
- store as { beforeTime: bigint }
33
- )
34
- })
35
- .onError({ as: 'global' }, ({ request, error, set, store }) => {
36
- const status = getStatusCode(set.status || 500)
37
- log.handleHttpError(
38
- request,
39
- { ...error, status } as HttpError,
40
- store as { beforeTime: bigint }
41
- )
42
- })
43
- }
44
-
45
- export { createLogger, handleHttpError } from './logger'
46
- export { logToTransports } from './output'
@@ -1,98 +0,0 @@
1
- export interface RequestInfo {
2
- headers: { get: (key: string) => string | null }
3
- method: string
4
- url: string
5
- }
6
-
7
- export interface Server {
8
- hostname?: string
9
- port?: number
10
- protocol?: string
11
- }
12
-
13
- export interface ColorMap {
14
- [key: string]: (str: string) => string
15
- }
16
-
17
- export type LogLevel = 'INFO' | 'WARNING' | 'ERROR' | string
18
-
19
- export interface LogData {
20
- status?: number
21
- message?: string
22
- }
23
-
24
- export interface Logger {
25
- log(
26
- level: LogLevel,
27
- request: RequestInfo,
28
- data: LogData,
29
- store: StoreData
30
- ): void
31
- handleHttpError(
32
- request: RequestInfo,
33
- error: HttpError,
34
- store: StoreData
35
- ): void
36
- customLogFormat?: string
37
- }
38
-
39
- export interface LogComponents {
40
- now: string
41
- epoch: string
42
- level: string
43
- duration: string
44
- method: string
45
- pathname: string | undefined
46
- status: string
47
- message: string
48
- ip: string
49
- }
50
-
51
- export interface StoreData {
52
- beforeTime: bigint
53
- }
54
-
55
- export class HttpError extends Error {
56
- status: number
57
-
58
- constructor(status: number, message: string) {
59
- super(message)
60
- this.status = status
61
- }
62
- }
63
-
64
- export type TransportFunction = (
65
- level: LogLevel,
66
- message: string,
67
- meta: {
68
- request: RequestInfo
69
- data: LogData
70
- store: StoreData
71
- }
72
- ) => Promise<void> | void
73
-
74
- export interface Transport {
75
- log: TransportFunction
76
- }
77
-
78
- export interface TimestampConfig {
79
- translateTime?: boolean | string
80
- }
81
-
82
- export interface Options {
83
- config?: {
84
- customLogFormat?: string
85
- logFilePath?: string
86
- logFilter?: {
87
- level?: LogLevel | LogLevel[]
88
- method?: string | string[]
89
- status?: number | number[]
90
- } | null
91
- ip?: boolean
92
- useColors?: boolean
93
- showStartupMessage?: boolean
94
- startupMessageFormat?: 'banner' | 'simple'
95
- transports?: Transport[]
96
- timestamp?: TimestampConfig // Add this new option
97
- }
98
- }