Skip to content

Commit

Permalink
Split log files by day
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelauer committed Apr 9, 2021
1 parent 6fae629 commit 4df0763
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
18 changes: 11 additions & 7 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions src/socketlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ const path = require("path");

let allMessages = [];
let socketMessages = [];
let filename = `../logs/log_${Date.now()}.log`;
const filePath = path.join(__dirname, filename);
fs.writeFileSync(path.join(__dirname, filename), "");

let filename, filePath, lastHour;

const makeLogFile = () => {
filename = `../logs/log_${Date.now()}.log`;
filePath = path.join(__dirname, filename);
fs.writeFileSync(path.join(__dirname, filename), "");
}

makeLogFile();

const doMessage = (messageString) => {
const nowMoment = moment();
if(nowMoment.hour() < 1 && lastHour !== nowMoment.hour())
{
lastHour = nowMoment.hour();
makeLogFile();
}

const withTimestamp = `${moment().format()} // ${messageString}`;
const lastMessage = socketMessages.length > 0 ? socketMessages[socketMessages.length - 1] : null;
const secondToLastMessage = socketMessages.length > 1 ? socketMessages[socketMessages.length - 2] : null;
Expand Down

0 comments on commit 4df0763

Please sign in to comment.