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
This commit is contained in:
Andrés Reyes Monge 2019-05-16 16:46:26 +02:00 committed by Nathan Shively-Sanders
parent e5ac06081f
commit cbd209d018
2 changed files with 59 additions and 15 deletions

View File

@ -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 <https://github.com/armonge>
// 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;

View File

@ -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");