__release-loguix@1.0 - Simple package of log

This commit is contained in:
CICD - Pipeline 2022-08-13 19:05:19 +02:00
parent ec136897bc
commit 2797e4a8be

73
main.js
View File

@ -3,8 +3,6 @@
//GITLAB : https://gitlab.com/raphixscrap/loguix //GITLAB : https://gitlab.com/raphixscrap/loguix
const main = require("./main.js")
const check = require("./checksystem.js")
const fs = require("fs") const fs = require("fs")
var date = new Date() 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 currentDate = date.getFullYear() + "-" + gmonth + "-" + gday + "-" + gHour + "h" + "-" + gMinute + "m" + "-" + gSecondes + "s"
var returnDate = currentDate 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
// [Log Settings] - Settings for LogSystem if(!fs.existsSync("logs/")) {
fs.mkdir("logs", (err) => {
if(err) {
if(!fs.existsSync("/logs/")) { console.log("[Loguix] - Error on initialization phase : #E : LOGS_DIR_ERROR")
fs.mkdir(__dirname + "/logs/") }
})
} }
@ -61,59 +62,73 @@ var logStream = fs.createWriteStream("logs/" + currentDate + ".log", {
}); });
var sys = { var sys = {
"name":"LogSystem", "name":"Loguix",
"version":"1.3" "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("[" + sys.name + "@" + sys.version + "] - [" + currentDate + "]" + "\n")
logStream.write("Log System for Karl by Raphix" + "\n") logStream.write("Loguix by Raphix" + "\n")
logStream.write("----------------------------------------------------------------" + "\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
//[Function] - Write into console with priority and write in log file
module.exports.write = (level, msg) => { module.exports.write = (level, msg) => {
if(env_set == true) {
if(level == "warn") { if(level == "warn") {
var message = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg + "\n"; var message = "[" + currentDate + "] - [" + env_name + "]" + "["+ level.toUpperCase() + "] - " + msg + "\n";
var consoleMessage = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg var consoleMessage = "[" + currentDate + "] - [" + env_name + "]" + " - ["+ level.toUpperCase() + "] - " + msg
logStream.write(message); logStream.write(message);
console.warn(consoleMessage) console.warn(consoleMessage)
} else if(level == "error") { } else if(level == "error") {
var message = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg + "\n"; var message = "[" + currentDate + "] - [" + env_name + "]" + "["+ level.toUpperCase() + "] - " + msg + "\n";
var consoleMessage = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg var consoleMessage = "[" + currentDate + "] - [" + env_name + "]" + " - ["+ level.toUpperCase() + "] - " + msg
logStream.write(message); logStream.write(message);
console.error(consoleMessage) console.error(consoleMessage)
} else if(level == "info") { } else if(level == "info") {
var message = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg + "\n"; var message = "[" + currentDate + "] - [" + env_name + "]" + "["+ level.toUpperCase() + "] - " + msg + "\n";
var consoleMessage = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg var consoleMessage = "[" + currentDate + "] - [" + env_name + "]" + " - ["+ level.toUpperCase() + "] - " + msg
logStream.write(message); logStream.write(message);
console.log(consoleMessage) console.log(consoleMessage)
} else if(level == "fatal") { } else if(level == "fatal") {
var message = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg + "\n"; var message = "[" + currentDate + "] - [" + env_name + "]" + "["+ level.toUpperCase() + "] - " + msg + "\n";
var consoleMessage = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg var consoleMessage = "[" + currentDate + "] - [" + env_name + "]" + " - ["+ level.toUpperCase() + "] - " + msg
logStream.write(message); logStream.write(message);
console.log(consoleMessage) console.log(consoleMessage)
} else { } 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 // [Function] - Fatal Error - End programm when exit
module.exports.stop = (endCode) => { module.exports.stop = (endCode) => {
@ -131,7 +146,7 @@ module.exports.stop = (endCode) => {
} }
process.on('uncaughtException', (err) => { 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.end( "["+ "UNCAUGHT_EXCEPTION" + "]" + " - [END OF LOGS] - [" + currentDate + ']')
logStream.close() logStream.close()