Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Commit

Permalink
Add log level options
Browse files Browse the repository at this point in the history
  • Loading branch information
dhollinger committed Aug 3, 2020
1 parent 12ba249 commit 37f2292
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ type: Boolean
description: Allow uppercase within the name of the module or environment passed to the API.
default: true

### Logging Settings

#### `loglevel`

type: String
description: Set the Logging level for the application. Valid values are `debug`, `error`, `warn`, `fatal`, and `info`.
default `warn`

### Configure the webhook

This API provides two endpoints that need to be called:
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ class ApplicationController < Sinatra::Base
set :database, "sqlite3:db/#{ENV['SINATRA_ENV']}.sqlite3"
set :public_folder, 'public'
set :views, 'app/views'
set :logger, Logger.new(STDOUT)

# Logging settings
logger = Logger.new(STDOUT)
logger.level = LOGLEVEL
set :logger, logger
end

not_found do
Expand Down
3 changes: 3 additions & 0 deletions config/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ development:
ignore_environments: []
allow_uppercase: true

# Logging
loglevel: debug

test: &development
3 changes: 2 additions & 1 deletion config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

config_path = ENV['WEBHOOK_CONFDIR'] || 'config/config.yml'

require './lib/puppet_webhook'
config = YAML.load_file(config_path)
APP_CONFIG = OpenStruct.new(config[ENV['SINATRA_ENV']])
LOGLEVEL = PuppetWebhook.loglevel

ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: "db/#{ENV['SINATRA_ENV']}.sqlite3"
)

require './lib/puppet_webhook'
require './app/controllers/application_controller'
require_all 'app'
15 changes: 15 additions & 0 deletions lib/puppet_webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,19 @@

module PuppetWebhook
VERSION = '2.1.2'

def self.loglevel
case APP_CONFIG.loglevel
when 'debug'
Logger::DEBUG
when 'info'
Logger::INFO
when 'error'
Logger::ERROR
when 'fatal'
Logger::FATAL
else
Logger::WARN
end
end
end

0 comments on commit 37f2292

Please sign in to comment.