mirror of
https://github.com/ClaytonWWilson/stokpile.git
synced 2025-12-15 23:18:50 +00:00
Switch to dual-type strategy for parsing Logger constructor args
This commit is contained in:
parent
4b0097f941
commit
f3e1ffd692
@ -1,4 +1,9 @@
|
||||
import { LogLabel, LogLevel, LogOutputs } from "./types/logger";
|
||||
import {
|
||||
LogLabel,
|
||||
LogLevel,
|
||||
StrictLogConfig,
|
||||
StrictLogOutputs,
|
||||
} from "./types/logger";
|
||||
import { gzip, randomString, stringifyInstance, ungzip } from "./lib/utilities";
|
||||
import { DEFAULT_STYLES } from "./lib/defaults";
|
||||
|
||||
@ -24,13 +29,13 @@ export class Logger {
|
||||
private buffer: string[];
|
||||
private bufferLength: number;
|
||||
private bucketIndex: BucketInfo[];
|
||||
private outputs: LogOutputs;
|
||||
private outputs: StrictLogOutputs;
|
||||
private bufferCapacity: number;
|
||||
|
||||
constructor(config: Partial<LogConfig> = {}) {
|
||||
constructor(config: LogConfig = {}) {
|
||||
this.buffer = [];
|
||||
this.bufferLength = 0;
|
||||
const parsedConfig = LogConfig.parse(config);
|
||||
const parsedConfig = StrictLogConfig.parse(config);
|
||||
this.bufferCapacity = parsedConfig.bufferCapacity;
|
||||
this.outputs = parsedConfig.outputs;
|
||||
|
||||
|
||||
@ -27,6 +27,33 @@ export interface ConsoleOutputOpts {
|
||||
}
|
||||
|
||||
export const LogOutputs = z.object({
|
||||
console: z
|
||||
.object({
|
||||
enabled: z.boolean().default(true).optional(),
|
||||
})
|
||||
.default({})
|
||||
.optional(),
|
||||
tampermonkey: z
|
||||
.object({
|
||||
enabled: z.boolean().default(false).optional(),
|
||||
maxBuckets: z.number().default(10).optional(),
|
||||
bucketIndexKey: z.string().default("bucket_index").optional(),
|
||||
})
|
||||
.default({})
|
||||
.optional(),
|
||||
callback: z.function().args(z.string()).optional(),
|
||||
});
|
||||
|
||||
export type LogOutputs = z.infer<typeof LogOutputs>;
|
||||
|
||||
export const LogConfig = z.object({
|
||||
outputs: LogOutputs.default({}).optional(),
|
||||
bufferCapacity: z.number().default(100000).optional(),
|
||||
});
|
||||
|
||||
export type LogConfig = z.infer<typeof LogConfig>;
|
||||
|
||||
export const StrictLogOutputs = z.object({
|
||||
console: z
|
||||
.object({
|
||||
enabled: z.boolean().default(true),
|
||||
@ -39,17 +66,17 @@ export const LogOutputs = z.object({
|
||||
bucketIndexKey: z.string().default("bucket_index"),
|
||||
})
|
||||
.default({}),
|
||||
callback: z.function().args(z.string()).nullish(),
|
||||
callback: z.function().args(z.string()).optional(),
|
||||
});
|
||||
|
||||
export type LogOutputs = z.infer<typeof LogOutputs>;
|
||||
export type StrictLogOutputs = z.infer<typeof StrictLogOutputs>;
|
||||
|
||||
export const LogConfig = z.object({
|
||||
outputs: LogOutputs.default({}),
|
||||
export const StrictLogConfig = z.object({
|
||||
outputs: StrictLogOutputs.default({}),
|
||||
bufferCapacity: z.number().default(100000),
|
||||
});
|
||||
|
||||
export type LogConfig = z.infer<typeof LogConfig>;
|
||||
export type StrictLogConfig = z.infer<typeof StrictLogConfig>;
|
||||
|
||||
export interface LogContext {
|
||||
level?: number;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user