@jable/logging
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

logging

Decorate methods for logging

Log

Log the start and end of a function

type IStartLogString = (construcotrName: string, propertyKey: string, args: IArguments) => string;
type IEndLogString = (construcotrName: string, propertyKey: string, result: any) => string;

/**
 * Log start and end of functions
 * 
 * @export
 * @param {(out: string) => void} [pipe=console.log] Pipe method
 * @param {IStartLogString} [start=defaultStart] Start text
 * @param {IEndLogString} [end=defaultEnd] End text
 * @returns Decorator
 */
function Log(pipe: (out: string) => void = console.log, start: IStartLogString = defaultStart, end: IEndLogString = defaultEnd) { ... }

Log Error

Log errors of a function

type IOutLogErrorString = (constructorName: string, propertyKey: string, err: any) => string

/**
 * Log method errors
 * 
 * @export
 * @param {(out: string) => void} [pipe=console.error] Pipe method
 * @param {IOutLogErrorString} [errorLog=defaultErrorLog] Error text to log
 * @param {boolean} [reThrow=true] Rethrow the error
 * @returns Decorator
 */
function LogError(pipe: (out: string) => void = console.error, errorLog: IOutLogErrorString = defaultErrorLog, reThrow: boolean = true) { ... }

Example

class Test {
    @Log(console.log, (ctorN, pkey) => `Start ${ctorN}.${pkey}`, (ctorN, pkey, result) => `End ${ctorN}.${pkey} with result: ${result}`)
    public logging() {

    }

    @Log()
    @LogError(console.error, (ctorN, pKey, er) => `${ctorN}.${pKey} throws: ${er}`, false)
    public loggingError() {
        throw "Some Error";
    }
}

Dependencies (1)

Dev Dependencies (1)

Package Sidebar

Install

npm i @jable/logging

Weekly Downloads

2

Version

2.0.0

License

MIT

Last publish

Collaborators

  • cpamperin
  • jable