Skip to content

Commit

Permalink
refactored logic for checking the logs_enabled env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanrahic committed Apr 6, 2020
1 parent f6e4976 commit a9c65f9
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions lib/plugins/input/docker/dockerInspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,41 @@ function getLogseneEnabled (info) {
let token = null

extractLoggingTags(info.Config.Labels, info.Config.Env, info)

// tag container info with LOGSENE_ENABLED flag
// check for Labels
if (info.Config && info.Config.Labels) {
info.LOGSENE_ENABLED = info.Config.Labels.LOGSENE_ENABLED || info.Config.Labels.LOGS_ENABLED || null
} else {
// no Label set, check for ENV var
info.LOGSENE_ENABLED = getEnvVar('LOGSENE_ENABLED', info.Config.Env)
if (!info.LOGSENE_ENABLED) {
info.LOGSENE_ENABLED = getEnvVar('LOGS_ENABLED', info.Config.Env)
}
}

if (info.LOGSENE_ENABLED === null) {
// no Label or env var set, use LOGS_ENABLED_DEFAULT
// console.log('Container ' + info.Id + ' ' + info.Name + ' setting LOGS_ENABLED not specified')
// set the desired default from Logagent config environment
info.LOGSENE_ENABLED = LOGS_ENABLED_DEFAULT

// no Label set, check for ENV var
const LOGSENE_ENABLED = getEnvVar('LOGSENE_ENABLED', info.Config.Env)
const LOGS_ENABLED = getEnvVar('LOGS_ENABLED', info.Config.Env)

if (LOGSENE_ENABLED !== null) {
info.LOGSENE_ENABLED = LOGSENE_ENABLED
}
if (LOGS_ENABLED !== null) {
info.LOGSENE_ENABLED = LOGS_ENABLED
}

if (info.LOGSENE_ENABLED === null) {
info.LOGSENE_ENABLED = LOGS_ENABLED_DEFAULT
}
}

if (info.LOGSENE_ENABLED === '0' || info.LOGSENE_ENABLED === 'false' || info.LOGSENE_ENABLED === 'no') {
consoleLogger.log('Container ' + info.Id + ' ' + info.Name + ' setting LOGSENE_ENABLED=false')
info.LOGSENE_ENABLED = false
} else {
info.LOGSENE_ENABLED = true
consoleLogger.log('Container ' + info.Id + ' ' + info.Name + ' setting LOGSENE_ENABLED=true')
}

if (info.Config && info.Config.Labels && info.Config.Labels.LOGSENE_TOKEN) {
token = info.Config.Labels.LOGSENE_TOKEN
info.LOGSENE_TOKEN = token
Expand All @@ -149,6 +160,7 @@ function getLogseneEnabled (info) {
}
}
info.LOGSENE_TOKEN = token || process.env.LOGS_TOKEN || process.env.LOGSENE_TOKEN

// get optional log receiver URLs
let logsReceiver = null
if (info.Config && info.Config.Labels && info.Config.Labels.LOGS_RECEIVER_URL) {
Expand Down

0 comments on commit a9c65f9

Please sign in to comment.