Skip to content

Commit

Permalink
Teeworlds styled timestamp in logs
Browse files Browse the repository at this point in the history
Generate a new timestamp on restart.
  • Loading branch information
ChillerDragon committed Aug 31, 2023
1 parent 5bda197 commit 5238a80
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

const fs = require('fs')

let _logfile = null

const log = (type, msg) => {
const ts = new Date().toISOString().split('T').join(' ').split(':').join(':').split('.')[0]
const logmsg = `[${ts}][${type}] ${msg}`
console.log(logmsg)
fs.appendFile('logs/logfile.txt', logmsg + '\n', (err) => {
if (!_logfile) {
// 2023-08-31 09:30:15 -> 2023-08-31_09-30
const ts_slug = ts.replace(' ', '_').replace(':', '-').split(':')[0]
_logfile = `logs/chillerbot_api_${ts_slug}.txt`
}
fs.appendFile(_logfile, logmsg + '\n', (err) => {
if (err) {
throw err
}
Expand Down

0 comments on commit 5238a80

Please sign in to comment.