winston에서는 로그 파일 관리를 위해 다음과 같은 설정을 제공한다.

  • File Transport Options
    • maxsize: Max size in bytes of the logfile, if the size is exceeded then a new file is created, a counter will become a suffix of the log file.
      • 로그파일의 최대 크기를 지정가능하고, 해당 크기를 넘을 경우 새로운 로그파일을 생성
        • ex) error.log, error1.log, error2.log
    • maxFiles: Limit the number of files created when the size of the logfile is exceeded.
      • 생성되는 로그 파일의 갯수를 지정가능하고, maxFiles 갯수를 넘어갈경우 가장 오래된 파일을 삭제하고 새로 생성
    • zippedArchive: If true, all log files but the current one will be zipped.
      • 로그파일을 zip 파일로 유지
  • 예제
    • 로그파일을 최대 100MB x 5 개로 유지
    • var fileAppender = new winston.transports.File({
          timestamp: _timestamp,
          formatter: _customFormatter,
          json: false,
          filename: 'filelog.log',
          maxsize: 104857600, // 100 MB = 1024 * 1024 * 100 = 104857600 Bytes
          maxFiles: 5
      });
      
  • winston-daily-rotate-file
    • Daily로 로그를 생성하고 싶을 경우 winston-daily-rotate-file 모듈을 사용하면 된다.


Posted by leechwin
,

Winston의 Log Format을 Customizing 하는 방법에 대해 알아본다.


Winston Log Format을 수정하기 위해서는 Winston Transport의 formatter 설정을 구현해야 한다.

  • timestamp 및 output format 함수를 재구현
function _timestamp() {
        return moment().format("YYYY-MM-DD HH:mm:ss.SSS");
}
function _customFormatter(options) {
    return options.timestamp() +
            ' ['+ options.level.toUpperCase() + ']' +
            '['+ options.meta.loggerName + '] ' +
            (!options.meta.clientMessage ? options.message : options.meta.clientMessage);
}
var consoleAppender = new winston.transports.Console({
    timestamp: _timestamp,
    formatter: _customFormatter
});
var fileAppender = new winston.transports.File({
    timestamp: _timestamp,
    formatter: _customFormatter,
    json: false,
    filename: 'filelog.log'
});


Posted by leechwin
,

[Ubuntu] hostname 변경

OS/Linux 2017. 1. 19. 16:00

Ubuntu에서 현재 컴퓨터의 이름인 hostname 을 변경하는 법에 대해 알아보자.


현재 hostname은 shell 에서 $ hostname 명령을 통하여 알 수 있다.


hostname을 수정하려면 다음 2개의 파일을 원하는 이름으로 수정하고 재부팅하면 hostname이 수정되어 반영된다. 

  • sudo vi /etc/hostname
  • sudo vi /etc/hosts

$ hostname

leechwin-linux $ cat /etc/hostname leechwin-linux $ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 leechwin-linux # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters



'OS > Linux' 카테고리의 다른 글

[Ubuntu] ln 명령으로 링크 만들기  (0) 2019.02.27
[Ubuntu] sudo 권한 등록  (0) 2017.08.09
[Ubuntu] Word Count  (0) 2017.01.19
[Ubuntu] Memory 확인  (0) 2017.01.19
[Ubuntu] Filesystem 용량 확인  (0) 2017.01.19
Posted by leechwin
,