Skip to content

Commit

Permalink
feat: add config noLogfiles, set noLogFiles for now
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Apr 28, 2020
1 parent 6eec02e commit fedfc74
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions api/now.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const config = require('../lib/config');
const app = require('../lib/app');

config.set({
noLogFiles: true,
});

module.exports = (req, res) => {
app.callback()(req, res);
};
3 changes: 2 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const calculateValue = () => {
}

value = {
isPackage: envs.isPackage,
isPackage: false,
noLogfiles: envs.NO_LOGFILES,
connect: {
port: envs.PORT || 1200, // 监听端口
socket: envs.SOCKET || null, // 监听 Unix Socket, null 为禁用
Expand Down
18 changes: 9 additions & 9 deletions lib/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ const { resolve } = require('path');
const winston = require('winston');
const config = require('@/config').value;

const logger = winston.createLogger({
level: config.loggerLevel,
format: winston.format.json(),
transports: [
//
// - Write to all logs with level `info` and below to `combined.log`
// - Write all logs error (and below) to `error.log`.
//
let transports = [];
if (!config.noLogfiles) {
transports = [
new winston.transports.File({
filename: resolve('logs/error.log'),
level: 'error',
}),
new winston.transports.File({ filename: resolve('logs/combined.log') }),
],
];
}
const logger = winston.createLogger({
level: config.loggerLevel,
format: winston.format.json(),
transports: transports,
});

//
Expand Down

0 comments on commit fedfc74

Please sign in to comment.