本文介绍了Sailsjs - 俗与温斯顿记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写自定义记录器将使用温斯顿将文件发送到任何一个S3桶或Mon​​goDB数据库sailsjs。

I am currently trying to write a custom logger for sailsjs that will use winston to send files to either an s3 bucket or a mongodb database.

文档似乎缺乏,但到目前为止,我发现这一点:

The documentation seems to be lacking but so far i have found this:

var customLogger = new winston.Logger({
transports: [
    new(winston.transports.File)({
        level: 'debug',
        filename: './logs/my_log_file.log'
    })
]
});

module.exports.log = {
    colors: false,  // To get clean logs without prefixes or color codings
    custom: customLogger
};

这总不是为我工作。

Which overall is not working for me.

任何想法?

推荐答案

上面MayBeColin的工作,延长了工作液后:

创建一个配置文件夹内的一个新的js文件(这将由帆自动执行在code)和添加的MongoDB传输如下,

Create a new js file inside a config folder(code inside of this will be executed automatically by sails) and add mongodb transports as below,

var winston = require('winston');
var MongoDB = require('winston-mongodb').MongoDB;

var customLogger = new(winston.Logger)({
    transports: [
        new(winston.transports.MongoDB)({
            db: 'mongodb://localhost:27017/test',
            collection: 'logs',
            level: 'debug'
        })
    ]
});

module.exports.logging = {
    colors: false, // To get clean logs without prefixes or color codings
    custom: customLogger
};

和使用它的任何地方像

sails.config.logging.custom.debug("winston mongodb transport logging");

这篇关于Sailsjs - 俗与温斯顿记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:35