puzzle/server/GameLog.js

26 lines
501 B
JavaScript
Raw Normal View History

2020-12-22 22:35:09 +01:00
import fs from 'fs'
const DATA_DIR = './../data'
const log = (gameId, ...args) => {
const str = JSON.stringify(args)
fs.appendFileSync(`${DATA_DIR}/log_${gameId}.log`, str + "\n")
}
const get = (gameId) => {
const all = fs.readFileSync(`${DATA_DIR}/log_${gameId}.log`, 'utf-8')
return all.split("\n").filter(line => !!line).map((line) => {
try {
return JSON.parse(line)
} catch (e) {
console.log(line)
console.log(e)
}
})
}
export default {
log,
get,
}