diff --git a/libraries/js/examples/configs/jsonConfig.json b/libraries/js/examples/configs/jsonConfig.json index d978f98..852c9cd 100644 --- a/libraries/js/examples/configs/jsonConfig.json +++ b/libraries/js/examples/configs/jsonConfig.json @@ -2,6 +2,6 @@ "env": "test", "logfile": "./examples//configs/log.log", "consoleOnly": false, - "logStatementPattern": "[ {component} ~ {logLevel} ] : {message}", + "logStatementPattern": "[ {component} ~ {status} ] : {message}", "logFormat": "statement" } \ No newline at end of file diff --git a/libraries/js/examples/index.js b/libraries/js/examples/index.js index 765bb35..fa8a100 100644 --- a/libraries/js/examples/index.js +++ b/libraries/js/examples/index.js @@ -1,48 +1,35 @@ -// import { PROTOCOLS } from "../logsmith/lib/specs.js"; import Logsmith from "../logsmith/logsmith.js"; -const logg = new Logsmith({ - monitor: { - port: "8080", - server: "localhost", - publisher: { - publisher: "test" - }, - context: { - context: "testcon" - } - } -}) +const logg = new Logsmith({}) -// const SampleLog = { -// status: "running", -// component: "logger", -// message: "The Test is Fine" -// } +const SampleLog = { + status: "running", + component : "logger", + message: "The Test is Fine" +} -console.log(logg) -// logg.WARN(SampleLog) -// logg.INFO(SampleLog) -// logg.SUCCESS(SampleLog) -// logg.FAILURE(SampleLog) -// logg.CRITICAL(SampleLog) -// logg.LOG("TRAILING", SampleLog) +logg.WARN(SampleLog) +logg.INFO(SampleLog) +logg.SUCCESS(SampleLog) +logg.FAILURE(SampleLog) +logg.CRITICAL(SampleLog) +logg.LOG("TRAILING", SampleLog) -// console.log() +console.log() -// logg.fetchConfigFromFile("./examples/configs/jsonConfig.json") -// logg.WARN(SampleLog) -// logg.INFO(SampleLog) -// logg.SUCCESS(SampleLog) -// logg.FAILURE(SampleLog) -// logg.CRITICAL(SampleLog) -// logg.LOG("TRAILING", SampleLog) +logg.fetchConfigFromFile("./examples/configs/jsonConfig.json") +logg.WARN(SampleLog) +logg.INFO(SampleLog) +logg.SUCCESS(SampleLog) +logg.FAILURE(SampleLog) +logg.CRITICAL(SampleLog) +logg.LOG("TRAILING", SampleLog) -// const logg1 = new Logsmith({ -// "logFormat": "statement" -// }) +const logg1 = new Logsmith({ + "logFormat" : "statement" +}) -// logg1.CRITICAL("test") \ No newline at end of file +logg1.CRITICAL("test") \ No newline at end of file diff --git a/libraries/js/logsmith/lib/specs.js b/libraries/js/logsmith/lib/specs.js index aca17f0..0bcae84 100644 --- a/libraries/js/logsmith/lib/specs.js +++ b/libraries/js/logsmith/lib/specs.js @@ -25,9 +25,4 @@ export const LogFormats = { STATEMENT: "statement" } -export var logs = [] - -const PROTOCOLS = { - "http" : "http://", - "https" : "https://" -} \ No newline at end of file +export var logs = [] \ No newline at end of file diff --git a/libraries/js/logsmith/logsmith.js b/libraries/js/logsmith/logsmith.js index ecb1db5..8689a4e 100644 --- a/libraries/js/logsmith/logsmith.js +++ b/libraries/js/logsmith/logsmith.js @@ -13,8 +13,6 @@ export default class Logsmith { this.consoleOnly = options.console_only || true this.logFormat = options.logFormat || LogFormats.JSON this.logStatementPattern = statement || DefaultLogStatementPattern - this.monitorLogging = options.monitorLogging || false - this.monitorConfigs = getMonitorConfigs(options) this.compiledLogPattern = compile(this.logStatementPattern) } @@ -26,9 +24,8 @@ export default class Logsmith { this.consoleOnly = configs.consoleOnly this.logFormat = Object.values(LogFormats).includes(configs.logFormat) ? configs.logFormat : LogFormats.JSON this.logStatementPattern = configs.logStatementPattern || DefaultLogStatementPattern - this.monitorLogging = configs.monitorLogging || false - this.monitorConfigs = getMonitorConfigs(configs) this.compiledLogPattern = compile(this.logStatementPattern) + this.monitorConfigs = getMonitorConfigs(configs) } else { return Error("File format error. Should be json or env.") } diff --git a/libraries/js/logsmith/monitor/monitorConfigs.js b/libraries/js/logsmith/monitor/monitorConfigs.js index 7be3420..671fd40 100644 --- a/libraries/js/logsmith/monitor/monitorConfigs.js +++ b/libraries/js/logsmith/monitor/monitorConfigs.js @@ -1,6 +1,6 @@ import compile from "string-template/compile.js" -const URITemplate = compile("{0}://{1}:{2}"); +const URITemplate = compile("{0}:{1}"); const DefaultPublisherTemplate = { Origin: compile("app.{0}.com"), Description: compile("Logs Published by {0}") @@ -32,19 +32,18 @@ function formatCotextConfig(publisher, monitorConfig) { export function getMonitorConfigs(config) { const monitorConfigs = {} - monitorConfigs.monitorPort = config.monitor.port || process.env.MONITOR_PORT - monitorConfigs.monitorURI = config.monitor.server || process.env.MONITOR_URI - monitorConfigs.monitorProtocol = config.monitor.protocol || process.env.MONITOR_PROTOCOL || "http" - monitorConfigs.monitorListener = URITemplate(monitorConfigs.monitorProtocol, monitorConfigs.monitorURI, monitorConfigs.monitorPort) || process.env.LISTENER - monitorConfigs.publisher = formatPublisherConfig(config.monitor.publisher) - monitorConfigs.context = formatCotextConfig(monitorConfigs.publisher.publisher, config.monitor.context) + monitorConfigs.monitorPort = config.MONITOR.port || process.env.MONITOR_PORT + monitorConfigs.monitorURI = config.MONITOR.server || process.env.MONITOR_URI + monitorConfigs.monitorListener = URITemplate(monitorConfigs.monitorURI, monitorConfigs.monitorPort) || process.env.LISTENER + monitorConfigs.publisher = formatPublisherConfig(config.MONITOR.publisher) + monitorConfigs.context = formatCotextConfig(monitorConfigs.publisher.publisher, config.MONITOR.context) return monitorConfigs } // can be used for test // console.log( // getMonitorConfigs({ -// monitor: { +// MONITOR: { // port: "8080", // server: "localhost", // publisher: {