poo
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
||||
node_modules/
|
||||
.env
|
||||
logs.log
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
# DotEnv
|
||||
|
||||
```config
|
||||
NODE_ENV=dev/prod
|
||||
|
||||
PORT=port
|
||||
PORT_DEV=port
|
||||
|
||||
LOGLEVEL=verbose/debug/warn/info
|
||||
LOG_LEVEL=verbose/debug/warn/info
|
||||
LOG_TARGET=console/filesystem/network
|
||||
LOG_PATH=network ip/path
|
||||
|
||||
DATABASE_HOST=host
|
||||
DATABASE_
|
||||
```
|
||||
|
||||
859
package-lock.json
generated
859
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -12,8 +12,10 @@
|
||||
"author": "Ben Kyd <benjaminkyd@gmail.com> (https://benkyd.co.uk)",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cli-color": "^2.0.1",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.17.2",
|
||||
"jest": "^27.4.5"
|
||||
"jest": "^27.4.5",
|
||||
"moment": "^2.29.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
const Logger = require('./logger.js');
|
||||
|
||||
const dotenv = require('dotenv');
|
||||
|
||||
function load() {
|
||||
console.log('Loading config...');
|
||||
dotenv.config();
|
||||
|
||||
Logger.info('Loading config...');
|
||||
const res = dotenv.config();
|
||||
Logger.debug('Config: result.parsed');
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
load
|
||||
}
|
||||
|
||||
0
src/controllers/shopbuy.js
Normal file
0
src/controllers/shopbuy.js
Normal file
@@ -1,11 +1,14 @@
|
||||
const Logger = require('./logger.js');
|
||||
const Config = require('./config.js');
|
||||
const Server = require('./routes/server.js');
|
||||
|
||||
async function main() {
|
||||
console.log('Pre-Init Loading...');
|
||||
Logger.info('Pre-Init Loading...');
|
||||
Logger.init();
|
||||
Config.load();
|
||||
|
||||
|
||||
|
||||
Server.load();
|
||||
Server.listen(process.env.PORT);
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
@@ -1,35 +1,26 @@
|
||||
// Better than Log4J 2021TM
|
||||
|
||||
const colours = require('colors/safe');
|
||||
const clc = require('cli-color');
|
||||
const moment = require('moment');
|
||||
const fs = require('fs');
|
||||
|
||||
let LogLevel = 1;
|
||||
let Dialect;
|
||||
let logPath = 'logs.log';
|
||||
let dateFormat = 'DD-MM-YY HH:mm:ss'
|
||||
|
||||
module.exports.init = async function(path) {
|
||||
if (path) logPath = path;
|
||||
|
||||
Dialect = process.env.NODE_ENV == 'production' ? 'MARIADB' : 'SQLITE';
|
||||
|
||||
if (!fs.existsSync(logPath)) {
|
||||
fs.writeFileSync(logPath, '');
|
||||
}
|
||||
fs.appendFileSync(logPath, '[SYSTEM STARTING UP] \n');
|
||||
|
||||
console.log(colours.rainbow('Starting up...'));
|
||||
}
|
||||
|
||||
module.exports.SetLevel = function(level) {
|
||||
LogLevel = level;
|
||||
}
|
||||
|
||||
module.exports.SetDialect = function(dialect) {
|
||||
Dialect = dialect;
|
||||
}
|
||||
|
||||
module.exports.SetDateFormat = function(format) {
|
||||
dateFormat = format;
|
||||
}
|
||||
@@ -43,28 +34,12 @@ module.exports.welcome = function() {
|
||||
// Unused
|
||||
}
|
||||
|
||||
module.exports.database = function(message) {
|
||||
let d = moment().format(dateFormat);
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [${Dialect}] ${message} \n`);
|
||||
if (LogLevel > 0) return;
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.magenta(Dialect) + '] ' + message);
|
||||
}
|
||||
|
||||
module.exports.game = function(message) {
|
||||
let d = moment().format(dateFormat);
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [GAME] ${message} \n`);
|
||||
if (LogLevel > 1) return;
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.brightBlue('GAME') + '] ' + message);
|
||||
}
|
||||
|
||||
module.exports.middleware = function(origin, message) {
|
||||
let d = moment().format(dateFormat);
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [MIDDLEWARE: ${origin}] ${message} \n`);
|
||||
if (LogLevel > 0) return;
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.yellow(`MIDDLEWARE: ${origin}`) + '] ' + message);
|
||||
+ clc.yellow(`MIDDLEWARE: ${origin}`) + '] ' + message);
|
||||
}
|
||||
|
||||
module.exports.debug = function(message) {
|
||||
@@ -72,14 +47,14 @@ module.exports.debug = function(message) {
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [DEBUG] ${message} \n`);
|
||||
if (LogLevel > 1) return;
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.cyan('DEBUG') + '] ' + message);
|
||||
+ clc.cyan('DEBUG') + '] ' + message);
|
||||
}
|
||||
|
||||
module.exports.ready = function() {
|
||||
let d = moment().format(dateFormat);
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [READY] \n`);
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.rainbow('READY') + ']');
|
||||
+ clc.rainbow('READY') + ']');
|
||||
}
|
||||
|
||||
module.exports.info = function(message) {
|
||||
@@ -87,7 +62,7 @@ module.exports.info = function(message) {
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [INFO] ${message} \n`);
|
||||
if (LogLevel > 2) return;
|
||||
console.log('[' + d.toLocaleString() + '] ['
|
||||
+ colours.green('INFO') + '] ' + message);
|
||||
+ clc.green('INFO') + '] ' + message);
|
||||
}
|
||||
|
||||
module.exports.warn = function(message) {
|
||||
@@ -95,22 +70,22 @@ module.exports.warn = function(message) {
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [WARN] ${message} \n`);
|
||||
if (LogLevel > 3) return;
|
||||
console.warn('[' + d.toLocaleString() + '] ['
|
||||
+ colours.yellow('WARN') + '] ' + message);
|
||||
+ clc.yellow('WARN') + '] ' + message);
|
||||
}
|
||||
|
||||
module.exports.error = function(message) {
|
||||
let d = moment().format(dateFormat);
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [ERROR] ${message} \n`);
|
||||
console.error('[' + d.toLocaleString() + '] ['
|
||||
+ colours.red('ERROR') + '] ' + message);
|
||||
+ clc.red('ERROR') + '] ' + message);
|
||||
}
|
||||
|
||||
module.exports.panic = function(message) {
|
||||
let d = moment().format(dateFormat);
|
||||
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [PANIC] ${message} \n`);
|
||||
console.error('[' + d.toLocaleString() + '] ['
|
||||
+ colours.red('PANIC') + '] ' + message);
|
||||
+ clc.red('PANIC') + '] ' + message);
|
||||
console.error('[' + d.toLocaleString() + '] ['
|
||||
+ colours.red('PANIC') + '] ABORTING...');
|
||||
+ clc.red('PANIC') + '] ABORTING...');
|
||||
process.exit();
|
||||
}
|
||||
0
src/models/shopbuy.js
Normal file
0
src/models/shopbuy.js
Normal file
15
src/routes/server.js
Normal file
15
src/routes/server.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const Logger = require('../logger.js');
|
||||
|
||||
function load() {
|
||||
Logger.info('Loading config...');
|
||||
dotenv.config();
|
||||
}
|
||||
|
||||
function listen(port) {
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
load,
|
||||
listen
|
||||
};
|
||||
Reference in New Issue
Block a user