__initial-commit - loguix@1.0

This commit is contained in:
CICD - Pipeline 2022-08-13 14:18:38 +02:00
commit ec136897bc
2 changed files with 166 additions and 0 deletions

146
main.js Normal file
View File

@ -0,0 +1,146 @@
//Loguix - Système de log simplifié
//Concu par Raphael PICOT - Raphix
//GITLAB : https://gitlab.com/raphixscrap/loguix
const main = require("./main.js")
const check = require("./checksystem.js")
const fs = require("fs")
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()
}
var currentDate = date.getFullYear() + "-" + gmonth + "-" + gday + "-" + gHour + "h" + "-" + gMinute + "m" + "-" + gSecondes + "s"
var returnDate = currentDate
// [Return Date for other]
module.exports.getLogFormatDate = () => {
return returnDate
}
// [Log Settings] - Settings for LogSystem
if(!fs.existsSync("/logs/")) {
fs.mkdir(__dirname + "/logs/")
}
var logStream = fs.createWriteStream("logs/" + currentDate + ".log", {
flags: 'a'
});
var sys = {
"name":"LogSystem",
"version":"1.3"
}
// [Function] - Start Function - Check state
logStream.write("[" + sys.name + "@" + sys.version + "] - [" + currentDate + "]" + "\n")
logStream.write("Log System for Karl by Raphix" + "\n")
logStream.write("----------------------------------------------------------------" + "\n")
module.exports.start = () => {
check.sendState(sys.name, sys.version, "operationnal")
}
//[Function] - Write into console with priority and write in log file
module.exports.write = (level, msg) => {
if(level == "warn") {
var message = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg + "\n";
var consoleMessage = "[" + currentDate + "] - ["+ 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
logStream.write(message);
console.error(consoleMessage)
} else if(level == "info") {
var message = "[" + currentDate + "] - ["+ level.toUpperCase() + "] - " + msg + "\n";
var consoleMessage = "[" + currentDate + "] - ["+ 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
logStream.write(message);
console.log(consoleMessage)
} else {
logStream.write("[" + currentDate + "] - " + "[KLS] - LogSystem - Write - Level is not reconized\n")
}
}
// [Function] - Fatal Error - End programm when exit
module.exports.stop = (endCode) => {
process.on('uncaughtException', () => {
logStream.end( "["+ endCode + "]" + " - [END OF LOGS] - [" + currentDate + ']')
console.log("check")
logStream.close()
});
nonexistentFunc();
}
process.on('uncaughtException', (err) => {
logStream.write("[" + currentDate + "] - ["+ "FATAL" + "] - " + "Karl has encountered an error ! Please Restart ! #E = " + err + "\n")
logStream.end( "["+ "UNCAUGHT_EXCEPTION" + "]" + " - [END OF LOGS] - [" + currentDate + ']')
logStream.close()
});
process.on('beforeExit', () => {
logStream.end( "["+ "NORMAL_END" + "]" + " - [END OF LOGS] - [" + currentDate + ']')
logStream.close()
});
//[Sandbox] - Test

20
package.json Normal file
View File

@ -0,0 +1,20 @@
{
"name": "loguix",
"version": "1.0",
"description": "Log System for JS",
"main": "main.js",
"scripts": {
},
"repository": {
"type": "git",
"url": "git+https://gitlab.com/raphixscrap/loguix.git"
},
"keywords": [],
"author": "Raphix",
"license": "ISC",
"bugs": {
"url": "https://gitlab.com/raphixscrap/loguix/issues"
},
"homepage": "https://gitlab.com/raphixscrap/loguix#readme"
}