0

我打电话时看不到任何日志winston.debug。我认为是因为我需要更改允许看到的日志级别? 链接到温斯顿文档Loggly node.js 文档

安装npm i winston-loggly-bulk @types/winston-loggly-bulk winston

import { Loggly, LogglyOptions } from "winston-loggly-bulk";
import winston from 'winston';

export class Server {
    private logOptions: LogglyOptions = {
        token: "my-customer-token",
        subdomain: "myDomain.com",
        tags: ["Winston-NodeJS"],
        json: true,
    };
    private logger: winston.Logger;
    private test: Test;

    constructor() {
        this.logger = winston.add(new Loggly(this.logOptions));

        this.test = new Test(this.logger);

        this.logger.info("mark1");   // I can see this in the loggly UI
        this.logger.debug("mark2");  // I cannot see this log in the loggly UI
    }
}
4

1 回答 1

0

我联系了 loggly 的支持,他们告诉我设置 winston'slevel

private logOptions: LogglyOptions = {
    token: "my-customer-token",
    level: config.production ? "error" : "debug",
    subdomain: "myDomain.com",
    tags: ["Winston-NodeJS"],
    json: true,
};

enum为了方便起见,我创建了一个:

export enum WinstonLogLevelsEnum {
    ERROR = "error",
    WARN = "warn",
    INFO = "info",
    HTTP = "http",
    VERBOSE = "verbose",
    DEBUG = "debug",
    SILLY = "silly",
};
于 2021-09-03T13:10:43.697 回答