Skip to content

Commit

Permalink
Revert "Updated code to handle Monitor Configs #39"
Browse files Browse the repository at this point in the history
This reverts commit 596c415.
  • Loading branch information
TanmoySG authored Jun 17, 2022
1 parent febe0d6 commit d879fdb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 56 deletions.
2 changes: 1 addition & 1 deletion libraries/js/examples/configs/jsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"env": "test",
"logfile": "./examples//configs/log.log",
"consoleOnly": false,
"logStatementPattern": "[ {component} ~ {logLevel} ] : {message}",
"logStatementPattern": "[ {component} ~ {status} ] : {message}",
"logFormat": "statement"
}
61 changes: 24 additions & 37 deletions libraries/js/examples/index.js
Original file line number Diff line number Diff line change
@@ -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")
logg1.CRITICAL("test")
7 changes: 1 addition & 6 deletions libraries/js/logsmith/lib/specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,4 @@ export const LogFormats = {
STATEMENT: "statement"
}

export var logs = []

const PROTOCOLS = {
"http" : "http://",
"https" : "https://"
}
export var logs = []
5 changes: 1 addition & 4 deletions libraries/js/logsmith/logsmith.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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.")
}
Expand Down
15 changes: 7 additions & 8 deletions libraries/js/logsmith/monitor/monitorConfigs.js
Original file line number Diff line number Diff line change
@@ -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}")
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit d879fdb

Please sign in to comment.