@pori15/logixlysia 0.0.1 → 6.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <div align="center">
2
2
  <h1><code>🦊</code> Logixlysia</h1>
3
3
  <strong>Logixlysia is a logging library for ElysiaJS</strong>
4
- <img src="../../apps/docs/app/opengraph-image.png" alt="Logixlysia" width="100%" height="auto" />
4
+ <img src="https://github.com/PunGrumpy/logixlysia/blob/main/apps/docs/app/opengraph-image.png?raw=true" alt="Logixlysia" width="100%" height="auto" />
5
5
  </div>
6
6
 
7
7
  ## `📩` Installation
package/dist/index.d.ts CHANGED
@@ -36,9 +36,34 @@ declare class ProblemError extends Error {
36
36
  constructor(type: string | undefined, title: string, status: number, detail?: string, instance?: string, extensions?: Record<string, unknown>);
37
37
  toJSON(): ProblemDocument;
38
38
  }
39
+ declare const HttpError: {};
39
40
  type Code = number | "PROBLEM_ERROR" | "UNKNOWN" | "VALIDATION" | "NOT_FOUND" | "PARSE" | "INTERNAL_SERVER_ERROR" | "INVALID_COOKIE_SIGNATURE" | "INVALID_FILE_TYPE";
41
+ type HttpErrorType = keyof typeof HttpError;
42
+ interface ErrorContext {
43
+ request: Request;
44
+ path: string;
45
+ code: string | number;
46
+ error: unknown;
47
+ }
48
+ interface HttpProblemJsonOptions {
49
+ /**
50
+ * 自定义错误类型的 Base URL
51
+ * @example "https://api.mysite.com/errors"
52
+ */
53
+ typeBaseUrl?: string;
54
+ /**
55
+ * 🪝 Transform Hook
56
+ * 将未知错误转换为 HttpError。
57
+ * 返回 undefined/null 表示不处理(走默认逻辑)。
58
+ */
59
+ transform?: (error: unknown, context: ErrorContext) => ProblemError | undefined | null;
60
+ /**
61
+ * 📢 Listen Hook
62
+ * 在响应发送前触发(用于日志)。
63
+ */
64
+ onBeforeRespond?: (problem: ProblemError, context: ErrorContext) => void | Promise<void>;
65
+ }
40
66
  type Pino = PinoLogger<never, boolean>;
41
- type Request2 = Request2;
42
67
  type LogLevel = "DEBUG" | "INFO" | "WARNING" | "ERROR";
43
68
  interface StoreData {
44
69
  beforeTime: bigint;
@@ -68,6 +93,13 @@ interface LogRotationConfig {
68
93
  compress?: boolean;
69
94
  compression?: "gzip";
70
95
  }
96
+ interface LogFilter {
97
+ /**
98
+ * Array of log levels to allow. If specified, only logs with these levels will be processed.
99
+ * If not specified, all log levels will be allowed.
100
+ */
101
+ level?: LogLevel[];
102
+ }
71
103
  interface Options {
72
104
  config?: {
73
105
  showStartupMessage?: boolean;
@@ -78,6 +110,7 @@ interface Options {
78
110
  translateTime?: string;
79
111
  };
80
112
  customLogFormat?: string;
113
+ logFilter?: LogFilter;
81
114
  transports?: Transport[];
82
115
  useTransportsOnly?: boolean;
83
116
  disableInternalLogger?: boolean;
@@ -94,27 +127,25 @@ interface Options {
94
127
  };
95
128
  };
96
129
  transform?: (error: unknown, context: {
97
- request: Request2;
130
+ request: Request;
98
131
  code: Code;
132
+ path: string;
99
133
  }) => ProblemError | unknown;
100
134
  }
101
- declare class HttpError2 extends Error {
102
- readonly status: number;
103
- constructor(status: number, message: string);
104
- }
105
135
  interface Logger {
106
136
  pino: Pino;
107
- log: (level: LogLevel, request: Request2, data: Record<string, unknown>, store: StoreData) => void;
108
- handleHttpError: (request: Request2, error: ProblemError, store: StoreData, options: Options) => void;
109
- debug: (request: Request2, message: string, context?: Record<string, unknown>) => void;
110
- info: (request: Request2, message: string, context?: Record<string, unknown>) => void;
111
- warn: (request: Request2, message: string, context?: Record<string, unknown>) => void;
112
- error: (request: Request2, message: string, context?: Record<string, unknown>) => void;
137
+ log: (level: LogLevel, request: Request, data: Record<string, unknown>, store: StoreData) => void;
138
+ handleHttpError: (request: Request, error: ProblemError, store: StoreData, options: Options) => void;
139
+ debug: (request: Request, message: string, context?: Record<string, unknown>) => void;
140
+ info: (request: Request, message: string, context?: Record<string, unknown>) => void;
141
+ warn: (request: Request, message: string, context?: Record<string, unknown>) => void;
142
+ error: (request: Request, message: string, context?: Record<string, unknown>) => void;
113
143
  }
114
144
  interface LogixlysiaContext {
115
- request: Request2;
145
+ request: Request;
116
146
  store: LogixlysiaStore;
117
147
  }
148
+ declare const normalizeToProblem: (error: any, code: Code, path: string, typeBaseUrl?: string) => ProblemError;
118
149
  interface ProblemJson {
119
150
  type?: string;
120
151
  title: string;
@@ -151,4 +182,4 @@ type Logixlysia = Elysia<"Logixlysia", SingletonBase & {
151
182
  store: LogixlysiaStore;
152
183
  }>;
153
184
  declare const logixlysia: (options?: Options) => Logixlysia;
154
- export { toProblemJson, logixlysia, formatProblemJsonLog, logixlysia as default, Transport, StoreData, ProblemJson, Pino, Options, LogixlysiaStore, LogixlysiaContext, Logixlysia, Logger, LogLevel, HttpError2 as HttpError };
185
+ export { toProblemJson, normalizeToProblem, logixlysia, formatProblemJsonLog, logixlysia as default, Transport, StoreData, ProblemJsonOptions, ProblemJson, ProblemError, ProblemDocument, Pino, Options, LogixlysiaStore, LogixlysiaContext, Logixlysia, Logger, LogLevel, HttpProblemJsonOptions, HttpErrorType, HttpError, ErrorContext, Code };