87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
|
const fs = require("fs")
|
||
|
|
||
|
|
||
|
if(!fs.existsSync("logs/")) {
|
||
|
fs.mkdirSync("logs")
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
var logStream = fs.createWriteStream("logs/" + getDate() + ".log", {
|
||
|
flags: 'a'
|
||
|
});
|
||
|
|
||
|
logStream.write("[" + require("./package.json").name + "@" + require("./package.json").version + "] - [" + getDate() + "]" + "\n")
|
||
|
logStream.write("Submanager by Raphix" + "\n")
|
||
|
logStream.write("----------------------------------------------------------------" + "\n")
|
||
|
|
||
|
|
||
|
|
||
|
module.exports.client = (message) => {
|
||
|
|
||
|
logStream.write("[Subsonics-Client] - " + getDate() + " - " + message + "\n")
|
||
|
console.log("[Subsonics-Client] - " + getDate() + " - " + message)
|
||
|
}
|
||
|
|
||
|
module.exports.client.error = (message) => {
|
||
|
|
||
|
logStream.write("[Subsonics-Client] - [ERROR] - " + getDate() + " - " + message + "\n")
|
||
|
console.error("[Subsonics-Client] - [ERROR] - " + getDate() + " - " + message)
|
||
|
}
|
||
|
|
||
|
module.exports.update = (message) => {
|
||
|
|
||
|
|
||
|
logStream.write("[Subsonics-Update] - " + getDate() + " - " + message + "\n")
|
||
|
console.error("[Subsonics-Update] - " + getDate() + " - " + message)
|
||
|
}
|
||
|
|
||
|
|
||
|
function getDate() {
|
||
|
|
||
|
var date = new Date()
|
||
|
|
||
|
// [Date Format] - Format de la date
|
||
|
|
||
|
var gmonth = date.getMonth()
|
||
|
var gday = date.getDate()
|
||
|
var gHour = date.getHours()
|
||
|
var gMinute = date.getMinutes()
|
||
|
var gSecondes = date.getSeconds()
|
||
|
|
||
|
|
||
|
if(date.getMonth() + 1 <= 9) {
|
||
|
gmonth = "0" + (date.getMonth() + 1)
|
||
|
}
|
||
|
|
||
|
if(date.getDate() + 1 <= 9) {
|
||
|
gday = "0" + date.getDate()
|
||
|
}
|
||
|
|
||
|
if(date.getHours() + 1 <= 9) {
|
||
|
gHour = "0" + date.getHours()
|
||
|
}
|
||
|
|
||
|
if(date.getMinutes() + 1 <= 9) {
|
||
|
gMinute = "0" + date.getMinutes()
|
||
|
}
|
||
|
|
||
|
if(date.getSeconds() + 1 <= 9) {
|
||
|
gSecondes = "0" + date.getSeconds()
|
||
|
}
|
||
|
|
||
|
return date.getFullYear() + "-" + gmonth + "-" + gday + "-" + gHour + "h" + "-" + gMinute + "m" + "-" + gSecondes + "s"
|
||
|
}
|
||
|
|
||
|
process.on('uncaughtException', (err) => {
|
||
|
logStream.write("[" + getDate() + "] - ["+ "FATAL" + "] - [ Subsonics-Manager ]" + " The programm has encountered an error ! Please Restart ! #E = " + err + "\n")
|
||
|
logStream.end( "["+ "UNCAUGHT_EXCEPTION" + "]" + " - [END OF LOGS] - [" + getDate() + ']')
|
||
|
logStream.close()
|
||
|
|
||
|
});
|
||
|
|
||
|
process.on('beforeExit', () => {
|
||
|
logStream.end( "["+ "NORMAL_END" + "]" + " - [END OF LOGS] - [" + getDate() + ']')
|
||
|
logStream.close()
|
||
|
});
|