Skip to content

Commit

Permalink
Revert "Added Monitor Config Parser - #39"
Browse files Browse the repository at this point in the history
This reverts commit 4c68abe.
  • Loading branch information
TanmoySG authored Jun 17, 2022
1 parent a9d03c5 commit a19a17b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 60 deletions.
3 changes: 0 additions & 3 deletions libraries/js/logsmith/logsmith.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as path from 'path';
import compile from 'string-template/compile.js';
import { loggerRunner } from './lib/drivers.js';
import { readConfigFile } from './lib/fetchConfigs.js';
import { getMonitorConfigs } from './monitor/monitorConfigs.js';
import { LogFormats, LogLevels, DefaultLogStatementPattern } from './lib/specs.js';


Expand All @@ -25,13 +24,11 @@ export default class Logsmith {
this.logFormat = Object.values(LogFormats).includes(configs.logFormat) ? configs.logFormat : LogFormats.JSON
this.logStatementPattern = configs.logStatementPattern || DefaultLogStatementPattern
this.compiledLogPattern = compile(this.logStatementPattern)
this.monitorConfigs = getMonitorConfigs(configs)
} else {
return Error("File format error. Should be json or env.")
}
}


INFO(log) {
loggerRunner(
LogLevels.INFO,
Expand Down
61 changes: 4 additions & 57 deletions libraries/js/logsmith/monitor/monitorConfigs.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,4 @@
import compile from "string-template/compile.js"

const URITemplate = compile("{0}:{1}");
const DefaultPublisherTemplate = {
Origin: compile("app.{0}.com"),
Description: compile("Logs Published by {0}")
}
const DefaultContextTemplate = {
Origin: compile("app.{0}.com/{1}"),
Description: compile("Log Published by {0} to context {1}"),
Kind: {
logs: []
}
}

function formatPublisherConfig(monitorConfig) {
const publisherConfig = {}
publisherConfig.publisher = monitorConfig.publisher || process.env.PUBLISHER
publisherConfig.origin = monitorConfig.origin || DefaultPublisherTemplate.Origin(publisherConfig.publisher)
publisherConfig.description = monitorConfig.description || DefaultPublisherTemplate.Description(publisherConfig.publisher)
return publisherConfig
}

function formatCotextConfig(publisher, monitorConfig) {
const contextConfig = {}
contextConfig.context = monitorConfig.context || process.env.CONTEXT
contextConfig.origin = monitorConfig.origin || DefaultContextTemplate.Origin(publisher, contextConfig.context)
contextConfig.description = monitorConfig.description || DefaultPublisherTemplate.Description(publisher, contextConfig.context)
contextConfig.kind = monitorConfig.kind || DefaultContextTemplate.Kind
return contextConfig
}

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.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: {
// port: "8080",
// server: "localhost",
// publisher: {
// publisher: "test"
// },
// context: {
// context: "testcon"
// }
// }
// })
// )
export function getMonitorConfigs(params) {
var monitorAddresses = []

}

0 comments on commit a19a17b

Please sign in to comment.