Explorar el Código

Adds excluding args to logging

main
Eric Amodio hace 6 años
padre
commit
8cf77169d1
Se han modificado 1 ficheros con 28 adiciones y 20 borrados
  1. +28
    -20
      src/system/decorators/log.ts

+ 28
- 20
src/system/decorators/log.ts Ver fichero

@ -44,34 +44,34 @@ export function logName(fn: (c: T, name: string) => string) {
export function debug<T>(
options: {
args?: boolean | { [arg: string]: (arg: any) => string };
condition?(this: any, ...args: any[]): boolean;
args?: false | { [arg: string]: (arg: any) => string | false };
condition?(...args: any[]): boolean;
correlate?: boolean;
enter?(this: any, ...args: any[]): string;
exit?(this: any, result: any): string;
prefix?(this: any, context: LogContext<T>, ...args: any[]): string;
sanitize?(this: any, key: string, value: any): any;
enter?(...args: any[]): string;
exit?(result: any): string;
prefix?(context: LogContext<T>, ...args: any[]): string;
sanitize?(key: string, value: any): any;
timed?: boolean;
} = { args: true, timed: true }
} = { timed: true }
) {
return log<T>({ debug: true, ...options });
}
export function log<T>(
options: {
args?: boolean | { [arg: number]: (arg: any) => string };
condition?(this: any, ...args: any[]): boolean;
args?: false | { [arg: number]: ((arg: any) => string | false) };
condition?(...args: any[]): boolean;
correlate?: boolean;
debug?: boolean;
enter?(this: any, ...args: any[]): string;
exit?(this: any, result: any): string;
prefix?(this: any, context: LogContext<T>, ...args: any[]): string;
sanitize?(this: any, key: string, value: any): any;
enter?(...args: any[]): string;
exit?(result: any): string;
prefix?(context: LogContext<T>, ...args: any[]): string;
sanitize?(key: string, value: any): any;
singleLine?: boolean;
timed?: boolean;
} = { args: true, timed: true }
} = { timed: true }
) {
options = { args: true, timed: true, ...options };
options = { timed: true, ...options };
const logFn = options.debug ? Logger.debug.bind(Logger) : Logger.log.bind(Logger);
@ -136,7 +136,7 @@ export function log(
const enter = options.enter != null ? options.enter(...args) : '';
let loggableParams: string;
if (!options.args || args.length === 0) {
if (options.args === false || args.length === 0) {
loggableParams = '';
if (!options.singleLine) {
@ -144,17 +144,25 @@ export function log(
}
}
else {
const argFns = typeof options.args === 'object' ? options.args : undefined;
let argFn;
let loggable;
loggableParams = args
.map((v: any, index: number) => {
const p = parameters[index];
const loggable =
typeof options.args === 'object' && options.args[index]
? options.args[index](v)
: Logger.toLoggable(v, options.sanitize);
argFn = argFns !== undefined ? argFns[index] : undefined;
if (argFn !== undefined) {
loggable = argFn(v);
if (loggable === false) return undefined;
}
else {
loggable = Logger.toLoggable(v, options.sanitize);
}
return p ? `${p}=${loggable}` : loggable;
})
.filter(Boolean)
.join(', ');
if (!options.singleLine) {

Cargando…
Cancelar
Guardar