Skip to content

Commit

Permalink
replaced logging with log4js to provide more granular control over lo…
Browse files Browse the repository at this point in the history
…gs and simplify the codebase
  • Loading branch information
root authored and root committed Jun 11, 2024
1 parent 73b1548 commit a7505ee
Show file tree
Hide file tree
Showing 16 changed files with 296 additions and 213 deletions.
2 changes: 1 addition & 1 deletion accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var prettyprint = false;
var url;

function debug(message) {
dbg.message("<ACCOUNTS> " + message,4);
logger.debug("<ACCOUNTS> " + message);
}

function help() {
Expand Down
336 changes: 167 additions & 169 deletions experimental.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions flowservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
*/

const rest = require('./rest-fetch.js');
const dbg = require('./debug.js');


var domainName, username,password,timeout,prettyprint;
var url;

function debug(message){
dbg.message("<FLOWSERVICE> " + message,4);
logger.debug("<FLOWSERVICE> " + message);
}

function help(){
Expand Down
2 changes: 1 addition & 1 deletion idm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var url;
var bearerToken;

function debug(message) {
dbg.message("<IDM> " + message,4);
logger.debug("<IDM> " + message);
}
function help() {
return `
Expand Down
2 changes: 1 addition & 1 deletion monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var prettyprint = false;
var url;

function debug(message) {
dbg.message("<MONITOR> " + message,4);
logger.debug("<MONITOR> " + message);
}

function help() {
Expand Down
90 changes: 90 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"formdata-node": "^6.0.3",
"https-proxy-agent": "^7.0.4",
"log4js": "^6.9.1",
"node-fetch": "^3.3.2",
"readline-sync": "^1.4.10",
"tough-cookie": "^4.1.4"
Expand Down
2 changes: 1 addition & 1 deletion projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var prettyprint = false;
var url;

function debug(message) {
dbg.message("<PROJECTS> " + message,4);
logger.debug("<PROJECTS> " + message,4);
}

function help() {
Expand Down
2 changes: 1 addition & 1 deletion recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var domainName, username, password, timeout, prettyprint;
var url;

function debug(message) {
dbg.message("<RECIPE> " + message,4);
logger.debug("<RECIPE> " + message);
}
function help() {
return `
Expand Down
39 changes: 17 additions & 22 deletions rest-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,30 @@

const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
const { CookieJar } = require('tough-cookie');
const zlib = require('zlib');
//const zlib = require('zlib');
const fs = require ('fs')
const { FormData } = require('formdata-node');
const { fileFromPathSync } = require('formdata-node/file-from-path');
const { HttpsProxyAgent }= require('https-proxy-agent');
var proxyAgent = undefined;
const { message } = require('./debug');
const { warn } = require('console');
const cj = new CookieJar();
var cookieJar = [];
var domain

function consolelog(message,level)
{
dbg.message("<REST-FETCH>:" + message,level);
}
function debug(message){
consolelog(message,4);
logger.debug(message);
}

function info(message){
consolelog(message,3);
logger.info(message);
}

function warning(message){
consolelog(message,2);
logger.warn(message);
}

function error(message){
consolelog(message,1);
logger.error(message);
}


Expand Down Expand Up @@ -67,17 +61,18 @@ function addCookieToJar(cookie,domainName)
function displayCookies()
{
warning("------------------------- COOKIES -------------------------");
warning(`⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⠴⠶⠦⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣴⡯⠤⠴⠶⠶⠶⠿⠷⠶⠶⠦⠤⣴⠚⠛⠒⠶⣤⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⣀⣠⣄⣤⠶⢚⣯⠭⠤⠶⠤⢤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⢦⣀⡀⠀⠈⢹⣆⠀⠀⠀⠀⠀⠀
⠀⢀⡴⠞⠉⠀⠀⢀⡟⠀⢯⣄⣀⣀⣀⣀⣠⠿⠀⠀⢀⡤⠤⠒⠒⠒⠶⢤⡀⠈⠉⠉⣉⣭⣭⣗⣦⣄⡀⠀⠀
⠀⣟⣀⣀⣠⠴⠞⠉⠀⡠⠤⠶⠾⣍⡭⠥⠤⠤⣀⠀⠘⢧⣀⠀⠀⠀⠀⣀⣽⣀⣀⣈⣧⡀⠀⠀⠈⠙⢿⣦⡀
⣰⠋⠁⠀⠀⣀⣀⡀⠀⠀⠀⠀⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠉⡹⠛⠉⠀⠀⠈⠉⠻⣗⠲⠦⠤⠾⠋⢷
⡏⠀⣴⠋⠉⠁⠈⠉⣳⠀⠀⠀⢀⣠⠤⠶⠦⠤⣄⡀⠀⠀⠀⠀⠀⣀⠤⠴⠶⠦⣤⡀⠀⠀⠈⠓⠀⢀⣀⠀⣼
⢷⡀⠈⠙⠒⠒⠒⠋⠁⠈⣒⣤⣘⣧⣄⣀⠀⠀⢈⣻⠀⠀⠀⠀⠘⢥⣀⠀⠀⠀⠀⢹⡆⠀⢀⡴⠚⠉⣩⣷⠏
⠈⠳⣤⡀⠀⠀⠀⠀⠀⠉⠀⠀⠀⠈⠉⠛⠫⡍⠉⠁⠀⡴⠒⠤⣤⡀⠈⠉⠉⠙⠛⠋⠁⠀⠺⠤⢖⣫⠟⠃⠀
⠀⠀⠈⠙⠳⢦⣄⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠓⠒⠒⠃⠀⠀⠀⠀⠀⢀⣀⣤⠴⠞⠋⠁⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠛⠛⠛⠛⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠛⠛⠛⠛⠛⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀`);
// warning(`
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⠴⠶⠦⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣴⡯⠤⠴⠶⠶⠶⠿⠷⠶⠶⠦⠤⣴⠚⠛⠒⠶⣤⡀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⢀⣀⣠⣄⣤⠶⢚⣯⠭⠤⠶⠤⢤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⢦⣀⡀⠀⠈⢹⣆⠀⠀⠀⠀⠀⠀
// ⠀⢀⡴⠞⠉⠀⠀⢀⡟⠀⢯⣄⣀⣀⣀⣀⣠⠿⠀⠀⢀⡤⠤⠒⠒⠒⠶⢤⡀⠈⠉⠉⣉⣭⣭⣗⣦⣄⡀⠀⠀
// ⠀⣟⣀⣀⣠⠴⠞⠉⠀⡠⠤⠶⠾⣍⡭⠥⠤⠤⣀⠀⠘⢧⣀⠀⠀⠀⠀⣀⣽⣀⣀⣈⣧⡀⠀⠀⠈⠙⢿⣦⡀
// ⣰⠋⠁⠀⠀⣀⣀⡀⠀⠀⠀⠀⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠉⡹⠛⠉⠀⠀⠈⠉⠻⣗⠲⠦⠤⠾⠋⢷
// ⡏⠀⣴⠋⠉⠁⠈⠉⣳⠀⠀⠀⢀⣠⠤⠶⠦⠤⣄⡀⠀⠀⠀⠀⠀⣀⠤⠴⠶⠦⣤⡀⠀⠀⠈⠓⠀⢀⣀⠀⣼
// ⢷⡀⠈⠙⠒⠒⠒⠋⠁⠈⣒⣤⣘⣧⣄⣀⠀⠀⢈⣻⠀⠀⠀⠀⠘⢥⣀⠀⠀⠀⠀⢹⡆⠀⢀⡴⠚⠉⣩⣷⠏
// ⠈⠳⣤⡀⠀⠀⠀⠀⠀⠉⠀⠀⠀⠈⠉⠛⠫⡍⠉⠁⠀⡴⠒⠤⣤⡀⠈⠉⠉⠙⠛⠋⠁⠀⠺⠤⢖⣫⠟⠃⠀
// ⠀⠀⠈⠙⠳⢦⣄⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠓⠒⠒⠃⠀⠀⠀⠀⠀⢀⣀⣤⠴⠞⠋⠁⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠛⠛⠛⠛⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠛⠛⠛⠛⠛⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀`);
for(var i=0;i<cookieJar.length;i++)
{
var cookieVal = cookieJar[i].split(";")[0];
Expand Down
2 changes: 1 addition & 1 deletion roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function checkForErrors(inBody) {
}

function debug(message) {
dbg.message("<ROLES> " + message,4);
logger.debug("<ROLES> " + message);
}

function help() {
Expand Down
2 changes: 1 addition & 1 deletion sync-rest-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let cookieJar = [];
let domain;

function consolelog(message, level) {
dbg.message("<REST-FETCH>:" + message,level);
logger.debug("<REST-FETCH>:" + message,level);
}

function debug(message) {
Expand Down
2 changes: 1 addition & 1 deletion themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var prettyprint = false;
var url;

function debug(message) {
dbg.message("<THEMES> " + message,4);
logger.debug("<THEMES> " + message);
}

function help() {
Expand Down
2 changes: 1 addition & 1 deletion users.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function checkForErrors(inBody)
}

function debug(message){
dbg.message("<USERS> " + message,4);
logger.debug("<USERS> " + message);
}


Expand Down
19 changes: 10 additions & 9 deletions wmiocli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ var experimental = require('./experimental.js');
var hideExperimental = true;
returnStart = 0;
returnCount = 1000;
const { setLogLevel } = require('./debug.js');
const { isTypedArray } = require('util/types');
log4js = require("log4js");
logger = log4js.getLogger();
logger.level="off";

dbg = require('./debug.js');
prettyprint = false;
proxy = undefined;
caCertFile = undefined;
Expand Down Expand Up @@ -99,19 +99,19 @@ function checkOptions() {
else {
switch (levelInput) {
case "OFF":
dbg.setLogLevel(0);
logger.level= "off";
break;
case "ERROR":
dbg.setLogLevel(1);
logger.level = "error";
break;
case "WARN":
dbg.setLogLevel(2);
logger.level = "warn";
break;
case "INFO":
dbg.setLogLevel(3);
logger.level = "info";
break;
case "DEBUG":
dbg.setLogLevel(4);
logger.level = "debug";
break;
default:
console.log("-level incorrectly set, should be one of: OFF, ERROR, WARN, INFO, DEBUG");
Expand Down Expand Up @@ -147,8 +147,9 @@ function checkOptions() {
}

function debug(message) {
dbg.message("<MAIN> " + message, 4);
logger.debug(message);
}

const program = new Command();

program
Expand Down
2 changes: 1 addition & 1 deletion workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var domainName, username, password, timeout, prettyprint;
var url;

function debug(message) {
dbg.message("<WORKFLOW> " + message,4);
logger.debug("<WORKFLOW> " + message);
}

function help() {
Expand Down

0 comments on commit a7505ee

Please sign in to comment.