Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add automatic log rotation

  • Loading branch information...
commit 45816d864369cd52afd948cb348b438dc37ffe7b 1 parent 7beceb2
maneulyori authored

Showing 1 changed file with 17 additions and 4 deletions. Show diff stats Hide diff stats

  1. +17 4 modules/logger.js
21 modules/logger.js
@@ -8,6 +8,7 @@ var fs = require('fs');
8 8
9 9 var client;
10 10 var config;
  11 +var rotateTimer;
11 12 var channelHT = new Object();
12 13 var channelLogStream = new Object();
13 14
@@ -21,6 +22,11 @@ function init (initArg)
21 22 client = initArg.client;
22 23 config = initArg.config;
23 24
  25 + rotateTimer = setInterval( function () {
  26 + for (var channel in channelLogStream)
  27 + logRotate(channel);
  28 + }, 1000);
  29 +
24 30 return { moduleCommand: { command: ["로깅"] }, callBack: messageHandler, rawPromiscCallBack: promiscMessageHandler, unloadCallback: unload };
25 31 }
26 32
@@ -31,10 +37,14 @@ function getTimestamp(date)
31 37 return timestamp;
32 38 }
33 39
34   -function logRotate()
  40 +function logRotate(channel)
35 41 {
36 42 var date = new Date();
37   - //for (var channel in
  43 + if(channelLogStream[channel].date.getDate() != date.getDate())
  44 + {
  45 + closeLogStream(channel);
  46 + openLogStream(channel);
  47 + }
38 48 }
39 49
40 50 function openLogStream(channel)
@@ -66,9 +76,9 @@ function writeLog(channel, message)
66 76
67 77 channel = channel.replace(/\//g, "_");
68 78 if(channelLogStream[channel] == undefined)
69   - {
70 79 openLogStream(channel);
71   - }
  80 +
  81 + logRotate(channel);
72 82 channelLogStream[channel].stream.write(timestamp + " " + message + "\r\n", "UTF-8");
73 83 }
74 84
@@ -151,6 +161,9 @@ function promiscMessageHandler(message)
151 161 function unload()
152 162 {
153 163 console.log("Unloading logger.js");
  164 +
  165 + clearInterval(rotateTimer);
  166 +
154 167 for(var channel in channelLogStream)
155 168 closeLogStream(channel);
156 169 }

0 comments on commit 45816d8

Please sign in to comment.
Something went wrong with that request. Please try again.