From cbd209d018437225ea95b00b2ddfbaf885baf92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Reyes=20Monge?= Date: Thu, 16 May 2019 16:46:26 +0200 Subject: [PATCH] lambda-log Adding more of the top level definitions and fixed the LogMessage references (#35513) * Adding some missing definitions * Added more definitions * removed some merge artifacts * Fixes lint issue --- types/lambda-log/index.d.ts | 43 +++++++++++++++++++++------- types/lambda-log/lambda-log-tests.ts | 31 ++++++++++++++++---- 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/types/lambda-log/index.d.ts b/types/lambda-log/index.d.ts index 5bb25313c1..55fa08ee26 100644 --- a/types/lambda-log/index.d.ts +++ b/types/lambda-log/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for lambda-log 2.0 +// Type definitions for lambda-log 2.2 // Project: https://github.com/KyleRoss/node-lambda-log // Definitions by: Andrés Reyes Monge // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -28,6 +28,7 @@ export class LogMessage { msg: string; meta?: any; + tags?: string[]; constructor(logRecordOptions: LogRecordOptions, opts: LambdaLogOptions); @@ -35,7 +36,7 @@ export class LogMessage { log: LogRecord; throw: undefined; - toJSON(format?: number): string; + toJSON(format?: boolean): string; static isError(val: any): boolean; } @@ -80,16 +81,38 @@ export class LambdaLog extends EventEmitter { constructor(options?: LambdaLogOptions, levels?: any); - log(level: string, msg: string, meta?: object, tags?: string[]): string; - info(msg: string, meta?: object, tags?: string[]): string; - warn(msg: string, meta?: object, tags?: string[]): string; - error(msg: string | Error, meta?: object, tags?: string[]): string; - debug(msg: string, meta?: object, tags?: string[]): string; + log(level: string, msg: string, meta?: object, tags?: string[]): LogMessage; + info(msg: string, meta?: object, tags?: string[]): LogMessage; + warn(msg: string, meta?: object, tags?: string[]): LogMessage; + error(msg: string | Error, meta?: object, tags?: string[]): LogMessage; + debug(msg: string, meta?: object, tags?: string[]): LogMessage; assert( test: any, msg: string, - meta: object, - tags: string[] - ): boolean | string; + meta?: object, + tags?: string[] + ): boolean | LogMessage; } + +export function log( + level: string, + msg: string, + meta?: object, + tags?: string[] +): LogMessage; +export function info(msg: string, meta?: object, tags?: string[]): LogMessage; +export function warn(msg: string, meta?: object, tags?: string[]): LogMessage; +export function error( + msg: string | Error, + meta?: object, + tags?: string[] +): LogMessage; +export function assert( + test: any, + msg: string, + meta?: object, + tags?: string[] +): LogMessage; +export function debug(msg: string, meta?: object, tags?: string[]): LogMessage; +export const options: LambdaLogOptions; diff --git a/types/lambda-log/lambda-log-tests.ts b/types/lambda-log/lambda-log-tests.ts index 09a4429c46..8ef1869f0e 100644 --- a/types/lambda-log/lambda-log-tests.ts +++ b/types/lambda-log/lambda-log-tests.ts @@ -1,11 +1,32 @@ -import { LambdaLog, LogMessage } from "lambda-log"; +import * as log from "lambda-log"; -const log = new LambdaLog({ - dynamicMeta: (logMessage: LogMessage) => { +const logMessage: log.LogMessage = log.log("customLevel", "custom", { + key: "value" +}); +logMessage.level; +logMessage.meta; +logMessage.tags; +logMessage.msg; +logMessage.value; +logMessage.log; +logMessage.toJSON(true); + +log.info("info", { key: "value" }); +log.warn("warn", { key: "value" }); +log.error(new Error("This is an error"), { key: "value" }); +log.debug("debug", { key: "value" }); +log.assert(true, "this will print"); + +const logInstance = new log.LambdaLog({ + dynamicMeta: (logMessage: log.LogMessage) => { return { value: logMessage.value }; } }); -log.log("info", "Some Message", {}, ["tag1", "tag2"]); -log.info("info", { key: "value" }); +logInstance.log("customLevel", "custom", { key: "value" }); +logInstance.info("info", { key: "value" }); +logInstance.warn("warn", { key: "value" }); +logInstance.error(new Error("This is an error"), { key: "value" }); +logInstance.debug("debug", { key: "value" }); +logInstance.assert(true, "this will print");