fix: better DEBUG var handling

This commit is contained in:
diced
2025-05-15 15:09:19 -07:00
parent 7ab5c4e180
commit f70eea97b0
2 changed files with 14 additions and 1 deletions

View File

@@ -9,6 +9,7 @@
"build:next": "ZIPLINE_BUILD=true next build",
"build:server": "tsup",
"dev": "cross-env TURBOPACK=1 NODE_ENV=development DEBUG=zipline tsx --require dotenv/config --enable-source-maps ./src/server",
"dev:nd": "cross-env TURBOPACK=1 NODE_ENV=development tsx --require dotenv/config --enable-source-maps ./src/server",
"dev:inspector": "cross-env TURBOPACK=1 NODE_ENV=development DEBUG=zipline tsx --require dotenv/config --inspect=0.0.0.0:9229 --enable-source-maps ./src/server",
"start": "cross-env NODE_ENV=production node --trace-warnings --require dotenv/config --enable-source-maps ./build/server",
"start:inspector": "cross-env NODE_ENV=production node --require dotenv/config --inspect=0.0.0.0:9229 --enable-source-maps ./build/server",

View File

@@ -15,6 +15,18 @@ export default class Logger {
return new Logger(`${this.name}::${name}`);
}
private isZiplineDebug(): boolean {
const debugVar = process.env.DEBUG;
if (!debugVar) return false;
if (debugVar === 'zipline') return true;
const parts = debugVar.split(',').map((v) => v.trim());
if (parts.includes('zipline') || parts.includes('*')) return true;
return false;
}
private format(message: string, level: LoggerLevel) {
const timestamp = dayjs().format('YYYY-MM-DDTHH:mm:ss');
@@ -81,7 +93,7 @@ export default class Logger {
}
public debug(args: string, extra?: Record<string, unknown>) {
if (process.env.DEBUG !== 'zipline') return this;
if (!this.isZiplineDebug()) return this;
this.write(args, 'debug', extra);