style: prettified
This commit is contained in:
parent
185e22cb84
commit
a8f7cb4f95
@ -5,10 +5,10 @@ import {loggedParam, scopedLogger} from "./reflected";
|
||||
import objectContainedLogged from "./functions";
|
||||
|
||||
function loggerInit(_target: any) {
|
||||
if (!Object.getOwnPropertyNames(_target).includes('logger')) {
|
||||
if (!Object.getOwnPropertyNames(_target).includes("logger")) {
|
||||
const newTargetLogger = new Logger(_target.constructor.name);
|
||||
newTargetLogger.log('Logger Initialized.');
|
||||
Object.defineProperty(_target, 'logger', {
|
||||
newTargetLogger.log("Logger Initialized.");
|
||||
Object.defineProperty(_target, "logger", {
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
@ -20,7 +20,7 @@ function loggerInit(_target: any) {
|
||||
export function LoggedFunction<F extends Array<any>, R>(
|
||||
_target: any,
|
||||
key: string,
|
||||
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R>>,
|
||||
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R>>
|
||||
) {
|
||||
loggerInit(_target);
|
||||
|
||||
@ -34,50 +34,52 @@ export function LoggedFunction<F extends Array<any>, R>(
|
||||
const scopedLoggerInjectableParam: number = Reflect.getOwnMetadata(
|
||||
scopedLogger,
|
||||
_target,
|
||||
key,
|
||||
key
|
||||
);
|
||||
|
||||
if (
|
||||
typeof scopedLoggerInjectableParam !== 'undefined' &&
|
||||
typeof scopedLoggerInjectableParam !== "undefined" &&
|
||||
(args.length <= scopedLoggerInjectableParam ||
|
||||
!(args[scopedLoggerInjectableParam] instanceof ScopedLogger))
|
||||
) {
|
||||
args[scopedLoggerInjectableParam] = new ScopedLogger(logger, key);
|
||||
} else if (typeof scopedLoggerInjectableParam !== 'undefined') {
|
||||
} else if (typeof scopedLoggerInjectableParam !== "undefined") {
|
||||
args[scopedLoggerInjectableParam] = new ScopedLogger(
|
||||
args[scopedLoggerInjectableParam],
|
||||
key,
|
||||
key
|
||||
);
|
||||
}
|
||||
|
||||
const injectedLogger =
|
||||
typeof scopedLoggerInjectableParam !== 'undefined'
|
||||
typeof scopedLoggerInjectableParam !== "undefined"
|
||||
? args[scopedLoggerInjectableParam]
|
||||
: logger;
|
||||
|
||||
const loggedParams: LoggedParamReflectData[] = Reflect.getOwnMetadata(
|
||||
loggedParam,
|
||||
_target,
|
||||
key,
|
||||
)
|
||||
key
|
||||
);
|
||||
|
||||
injectedLogger.log(
|
||||
`CALL ${key} ${
|
||||
loggedParams && loggedParams.length > 0
|
||||
? 'WITH ' +
|
||||
? "WITH " +
|
||||
(
|
||||
await Promise.all(
|
||||
loggedParams.map(
|
||||
async ({ name, index, include, exclude }) =>
|
||||
name + '=' + (await objectContainedLogged(args[index], {
|
||||
name +
|
||||
"=" +
|
||||
(await objectContainedLogged(args[index], {
|
||||
include,
|
||||
exclude,
|
||||
})),
|
||||
),
|
||||
}))
|
||||
)
|
||||
).join(', ')
|
||||
: ''
|
||||
}`,
|
||||
)
|
||||
).join(", ")
|
||||
: ""
|
||||
}`
|
||||
);
|
||||
|
||||
try {
|
||||
@ -95,7 +97,7 @@ export function LoggedRoute<F extends Array<any>, R>(route: string) {
|
||||
return (
|
||||
_target: any,
|
||||
key: string,
|
||||
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R>>,
|
||||
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R>>
|
||||
) => {
|
||||
loggerInit(_target);
|
||||
|
||||
@ -110,11 +112,11 @@ export function LoggedRoute<F extends Array<any>, R>(route: string) {
|
||||
const scopedLoggerInjectableParam: number = Reflect.getOwnMetadata(
|
||||
scopedLogger,
|
||||
_target,
|
||||
key,
|
||||
key
|
||||
);
|
||||
|
||||
if (
|
||||
typeof scopedLoggerInjectableParam !== 'undefined' &&
|
||||
typeof scopedLoggerInjectableParam !== "undefined" &&
|
||||
(args.length <= scopedLoggerInjectableParam ||
|
||||
!(args[scopedLoggerInjectableParam] instanceof ScopedLogger))
|
||||
) {
|
||||
@ -122,33 +124,35 @@ export function LoggedRoute<F extends Array<any>, R>(route: string) {
|
||||
}
|
||||
|
||||
const injectedLogger =
|
||||
typeof scopedLoggerInjectableParam !== 'undefined'
|
||||
typeof scopedLoggerInjectableParam !== "undefined"
|
||||
? args[scopedLoggerInjectableParam]
|
||||
: logger;
|
||||
|
||||
const loggedParams: LoggedParamReflectData[] = Reflect.getOwnMetadata(
|
||||
loggedParam,
|
||||
_target,
|
||||
key,
|
||||
)
|
||||
key
|
||||
);
|
||||
|
||||
injectedLogger.log(
|
||||
`HIT HTTP ${fullRoute} (${key}) ${
|
||||
loggedParams && loggedParams.length > 0
|
||||
? 'WITH ' +
|
||||
? "WITH " +
|
||||
(
|
||||
await Promise.all(
|
||||
loggedParams.map(
|
||||
async ({ name, index, include, exclude }) =>
|
||||
name + '=' + (await objectContainedLogged(args[index], {
|
||||
name +
|
||||
"=" +
|
||||
(await objectContainedLogged(args[index], {
|
||||
include,
|
||||
exclude,
|
||||
})),
|
||||
),
|
||||
}))
|
||||
)
|
||||
).join(', ')
|
||||
: ''
|
||||
}`,
|
||||
)
|
||||
).join(", ")
|
||||
: ""
|
||||
}`
|
||||
);
|
||||
|
||||
try {
|
||||
@ -160,5 +164,5 @@ export function LoggedRoute<F extends Array<any>, R>(route: string) {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user