__release-loguix@1.0 - Simple package of log
This commit is contained in:
parent
ec136897bc
commit
2797e4a8be
71
main.js
71
main.js
@ -3,8 +3,6 @@
|
||||
//GITLAB : https://gitlab.com/raphixscrap/loguix
|
||||
|
||||
|
||||
const main = require("./main.js")
|
||||
const check = require("./checksystem.js")
|
||||
const fs = require("fs")
|
||||
var date = new Date()
|
||||
|
||||
@ -42,17 +40,20 @@ if(date.getSeconds() + 1 <= 9) {
|
||||
var currentDate = date.getFullYear() + "-" + gmonth + "-" + gday + "-" + gHour + "h" + "-" + gMinute + "m" + "-" + gSecondes + "s"
|
||||
var returnDate = currentDate
|
||||
|
||||
// [Return Date for other]
|
||||
|
||||
module.exports.getLogFormatDate = () => {
|
||||
// [Loguix Init Phase] - Settings for LogSystem
|
||||
|
||||
return returnDate
|
||||
var env_name = null
|
||||
var env_set = false
|
||||
|
||||
if(!fs.existsSync("logs/")) {
|
||||
fs.mkdir("logs", (err) => {
|
||||
if(err) {
|
||||
|
||||
console.log("[Loguix] - Error on initialization phase : #E : LOGS_DIR_ERROR")
|
||||
}
|
||||
|
||||
// [Log Settings] - Settings for LogSystem
|
||||
|
||||
if(!fs.existsSync("/logs/")) {
|
||||
fs.mkdir(__dirname + "/logs/")
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@ -61,59 +62,73 @@ var logStream = fs.createWriteStream("logs/" + currentDate + ".log", {
|
||||
});
|
||||
|
||||
var sys = {
|
||||
"name":"LogSystem",
|
||||
"version":"1.3"
|
||||
"name":"Loguix",
|
||||
"version":"1.0"
|
||||
}
|
||||
|
||||
// [Function] - Start Function - Check state
|
||||
|
||||
|
||||
// [Loguix Start Phase] - Start Function - Check state
|
||||
|
||||
logStream.write("[" + sys.name + "@" + sys.version + "] - [" + currentDate + "]" + "\n")
|
||||
logStream.write("Log System for Karl by Raphix" + "\n")
|
||||
logStream.write("Loguix by Raphix" + "\n")
|
||||
logStream.write("----------------------------------------------------------------" + "\n")
|
||||
|
||||
module.exports.start = () => {
|
||||
|
||||
check.sendState(sys.name, sys.version, "operationnal")
|
||||
// [Function] - Get Loguix Date Format
|
||||
|
||||
module.exports.getLogFormatDate = () => {
|
||||
|
||||
return returnDate
|
||||
}
|
||||
|
||||
// [Function] - Environnement Settings
|
||||
|
||||
module.exports.setName = (name) => {
|
||||
env_name = name
|
||||
env_set = true
|
||||
|
||||
}
|
||||
|
||||
// [Function] - Write into console with priority and write in log file
|
||||
|
||||
module.exports.write = (level, msg) => {
|
||||
|
||||
if(env_set == true) {
|
||||
|
||||
if(level == "warn") {
|
||||
var message = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg + "\n";
|
||||
var consoleMessage = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg
|
||||
var message = "[" + currentDate + "] - [" + env_name + "]" + "["+ level.toUpperCase() + "] - " + msg + "\n";
|
||||
var consoleMessage = "[" + currentDate + "] - [" + env_name + "]" + " - ["+ level.toUpperCase() + "] - " + msg
|
||||
logStream.write(message);
|
||||
console.warn(consoleMessage)
|
||||
|
||||
} else if(level == "error") {
|
||||
var message = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg + "\n";
|
||||
var consoleMessage = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg
|
||||
var message = "[" + currentDate + "] - [" + env_name + "]" + "["+ level.toUpperCase() + "] - " + msg + "\n";
|
||||
var consoleMessage = "[" + currentDate + "] - [" + env_name + "]" + " - ["+ level.toUpperCase() + "] - " + msg
|
||||
logStream.write(message);
|
||||
console.error(consoleMessage)
|
||||
|
||||
} else if(level == "info") {
|
||||
var message = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg + "\n";
|
||||
var consoleMessage = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg
|
||||
var message = "[" + currentDate + "] - [" + env_name + "]" + "["+ level.toUpperCase() + "] - " + msg + "\n";
|
||||
var consoleMessage = "[" + currentDate + "] - [" + env_name + "]" + " - ["+ level.toUpperCase() + "] - " + msg
|
||||
logStream.write(message);
|
||||
console.log(consoleMessage)
|
||||
|
||||
} else if(level == "fatal") {
|
||||
var message = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg + "\n";
|
||||
var consoleMessage = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg
|
||||
var message = "[" + currentDate + "] - [" + env_name + "]" + "["+ level.toUpperCase() + "] - " + msg + "\n";
|
||||
var consoleMessage = "[" + currentDate + "] - [" + env_name + "]" + " - ["+ level.toUpperCase() + "] - " + msg
|
||||
logStream.write(message);
|
||||
console.log(consoleMessage)
|
||||
} else {
|
||||
logStream.write("[" + currentDate + "] - " + "[KLS] - LogSystem - Write - Level is not reconized\n")
|
||||
logStream.write("[" + currentDate + "] - " + "[Loguix] - Write - Level is not reconized\n")
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
console.error("[Loguix] - Name is not configure.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// [Function] - Fatal Error - End programm when exit
|
||||
|
||||
module.exports.stop = (endCode) => {
|
||||
@ -131,7 +146,7 @@ module.exports.stop = (endCode) => {
|
||||
}
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
logStream.write("[" + currentDate + "] - ["+ "FATAL" + "] - " + "Karl has encountered an error ! Please Restart ! #E = " + err + "\n")
|
||||
logStream.write("[" + currentDate + "] - ["+ "FATAL" + "] - [" + env_name + "]" + " The programm has encountered an error ! Please Restart ! #E = " + err + "\n")
|
||||
logStream.end( "["+ "UNCAUGHT_EXCEPTION" + "]" + " - [END OF LOGS] - [" + currentDate + ']')
|
||||
logStream.close()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user