TIL #035
2019.12.17
오늘 배운 것>
nodejs
- parse()
- foramt()
- queryString 모듈
- stringify()
-로그 파일 남기기
//logger.js
var winston = require('winston'); //로그 처리 모듈
var winstonDaily = require('winston-daily-rotate-file'); //로그 일별 처리 모듈
var moment = require('moment'); //시간 처리 모듈
// const logDir = 'log';
function timeStampFormat(){
return moment().format('YYYY-MM-DD HH:mm:ss.SSS ZZ');
};
var logger = new (winston.createLogger) ({ //createLogger 로 바꿔야 에러 안남
transports: [
new (winstonDaily) ({
name: 'info-file',
filename: './log/server_%DATE%.log', //%DATE% 필요
datePattern: 'YYYY-MM-DD', //datePattern 수정
colorize: false,
maxsize: 50000000,
maxFiles: 1000,
level: 'info',
showLevel: true,
json: false,
timestamp: timeStampFormat
}),
new (winston.transports.Console) ({
name: 'debug-console',
colorize:true,
level: 'debug',
showLevel: true,
json: false,
timestamp: timeStampFormat
})
],
exceptionHandlers: [
new(winstonDaily)({
name: 'exception-file',
filename: './log/exception_%DATE%.log',
datePattern: 'YYYY-MM-DD',
colorize: false,
maxsize: 50000000,
level: 'error',
showLevel: true,
json: false,
timestamp: timeStampFormat
}),
new(winston.transports.Console)({
name: 'exception-console',
colorize: true,
level: 'debug',
showLevel: true,
json: false,
timestamp: timeStampFormat
})
]
});
// var fs = require('fs');
// var inname = './output.txt';
// var outname = './output2.txt';
// fs.exists(outname, function(exists){
// if(exists) {
// fs.unlink(outname, function(err) {
// if(err) throw err;
// logger.info('기존 파일 [' + outname + '] 삭제함');
// });
// }
// var infile = fs.createReadStream(inname, {flags: 'r'});
// var outfile = fs.createWriteStream(outname, {flags: 'w'});
// infile.pipe(outfile);
// logger.info('파일 복사 [' + inname+ '] -> [' + outname + ']' );
// });
logger.debug('hi');
오늘의 생각>
- 오늘 컴공교수님을 만났다. 내년도 계획에 대하여 생각이 많아지는 밤이다.
내일 배울 것>
'두드리는 개발자 홍차 > TIL(Today I learned)' 카테고리의 다른 글
TIL #037 서울일러스트레이션페어 2019 (0) | 2019.12.20 |
---|---|
TIL #036 백엔드 개발자의 틸 (0) | 2019.12.18 |
TIL #034 백엔드 개발자의 틸 (1) | 2019.12.16 |
TIL #033 넷플릭스가 쏘아올린 공 (0) | 2019.12.15 |
TIL #032 콘텐츠 주제, 블록체인 회의 (0) | 2019.12.14 |
댓글