Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #10585: Migrate to custom logging now in Foreman core. #5253

Merged
merged 1 commit into from
Jun 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def system_params
end

def logger
::Logging.logger['cp_proxy']
Foreman::Logging.logger('katello/cp_proxy')
end

def respond_for_index(options = {})
Expand Down
6 changes: 3 additions & 3 deletions app/lib/katello/resources/candlepin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Resources
module Candlepin
class Proxy
def self.logger
::Logging.logger['cp_proxy']
Foreman::Logging.logger('katello/cp_proxy')
end

def self.post(path, body)
Expand Down Expand Up @@ -50,7 +50,7 @@ class CandlepinResource < HttpResource
self.ca_cert_file = cfg.ca_cert_file

def self.logger
::Logging.logger['cp_rest']
Foreman::Logging.logger('katello/cp_rest')
end

def self.default_headers(uuid = nil)
Expand Down Expand Up @@ -284,7 +284,7 @@ def update_content_override(id, content_label, name, value = nil)

class UpstreamConsumer < HttpResource
def self.logger
::Logging.logger['cp_rest']
Foreman::Logging.logger('katello/cp_rest')
end

def self.resource(url, client_cert, client_key, ca_file)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/katello/util/thread_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def self.pulp_config(user_remote_id, &_block)
:open_timeout => Katello.config.rest_client_timeout,
:oauth => {:oauth_secret => Katello.config.pulp.oauth_secret,
:oauth_key => Katello.config.pulp.oauth_key },
:logging => {:logger => ::Logging.logger['pulp_rest'],
:logging => {:logger => ::Foreman::Logging.logger('katello/pulp_rest'),
:exception => true,
:debug => true }
)
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/glue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Katello
module Glue
singleton_class.send :attr_writer, :logger
def self.logger
@logger ||= ::Logging.logger['glue']
@logger ||= Foreman::Logging.logger('katello/glue')
end

def self.included(base)
Expand Down
33 changes: 10 additions & 23 deletions app/models/katello/glue/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ def owner_imports
Resources::Candlepin::Owner.imports self.organization.label
end

def import_logger
Foreman::Logging.logger('katello/manifest_import_logger')
end

# TODO: break up method
def queue_import_manifest(options) # rubocop:disable MethodLength
options = options.with_indifferent_access
Expand All @@ -215,13 +219,7 @@ def queue_import_manifest(options) # rubocop:disable MethodLength
#are we refreshing from upstream?
manifest_refresh = options['zip_file_path'].nil?

output = ::Logging.appenders.string_io.new('manifest_import_appender')
import_logger = ::Logging.logger['manifest_import_logger']
import_logger.additive = false
import_logger.add_appenders(output)

options.merge!(:import_logger => import_logger)
[Rails.logger, import_logger].each { |l| l.debug "Importing manifest for provider #{self.name}" }
import_logger.debug "Importing manifest for provider #{self.name}"

begin
if manifest_refresh
Expand Down Expand Up @@ -257,8 +255,7 @@ def refresh_existing_products
end

# TODO: break up method
def import_products_from_cp(options = {}) # rubocop:disable MethodLength
import_logger = options[:import_logger]
def import_products_from_cp # rubocop:disable MethodLength
product_in_katello_ids = self.organization.providers.redhat.first.products.pluck("cp_id")
products_in_candlepin_ids = []

Expand All @@ -272,23 +269,16 @@ def import_products_from_cp(options = {}) # rubocop:disable MethodLength
adjusted_eng_products = []
added_eng_products.each do |product_attrs|
begin
product_attrs.merge!(:import_logger => import_logger)

Glue::Candlepin::Product.import_from_cp(product_attrs) do |p|
p.provider = self
p.organization_id = self.organization.id
end
adjusted_eng_products << product_attrs
if import_logger
import_logger.info "import of product '#{product_attrs["name"]}' from Candlepin OK"
end
import_logger.info "import of product '#{product_attrs["name"]}' from Candlepin OK"
rescue Errors::SecurityViolation => e
# Do not add non-accessible products
[Rails.logger, import_logger].each do |logger|
next if logger.nil?
logger.info "import of product '#{product_attrs["name"]}' from Candlepin failed"
import_logger.info e
end
logger.info "import of product '#{product_attrs["name"]}' from Candlepin failed"
import_logger.info e
end
end

Expand Down Expand Up @@ -357,10 +347,7 @@ def rollback_delete_manifest
end

def queue_delete_manifest(options)
output = StringIO.new
import_logger = Logger.new(output)
options.merge!(:import_logger => import_logger)
[Rails.logger, import_logger].each { |l| l.debug "Deleting manifest for provider #{self.name}" }
import_logger.debug "Deleting manifest for provider #{self.name}"

begin
pre_queue.create(:name => "delete manifest for owner: #{self.organization.name}",
Expand Down
4 changes: 0 additions & 4 deletions config/initializers/tire.rb

This file was deleted.

39 changes: 39 additions & 0 deletions config/katello.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
common:

rest_client_timeout: 120

post_sync_url: https://localhost/katello/api/v2/repositories/sync_complete?token=test

candlepin:
url: https://localhost:8443/candlepin
oauth_key: bb5uJCZSUdvRAcrrejP8RC8gYuFXDfr8
oauth_secret: 4DdSEh7dGkGKC5DGoE4CdWdFXap36Dqa

pulp:
url: https://katello-devel.example.com/pulp/api/v2/
oauth_key: bb5uJCZSUdvRAcrrejP8RC8gYuFXDfr8
oauth_secret: 4DdSEh7dGkGKC5DGoE4CdWdFXap36Dqa

qpid:
url: amqp:ssl:katello-devel.example.com:5671
subscriptions_queue_address: katello_event_queue

# Logging configuration can be changed by uncommenting the loggers
# section and the logger configuration desired.
#
#:katello:
# :loggers:
# :glue:
# :enabled: true
# :pulp_rest:
# :enabled: true
# :cp_rest:
# :enabled: true
# :cp_proxy:
# :enabled: true
# :action:
# :enabled: true
# :tire_rest:
# :enabled: false
# :manifest_import_logger:
# :enabled: true
140 changes: 0 additions & 140 deletions config/katello_defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,143 +92,3 @@ common:
# port: 3128
# user: login
# password: password

# when adding a new logger don't forget to add it in here even if it's disabled by default
# otherwise log trace feature won't work for such logger
logging:
# enable logging output inline in rails console
console_inline: true
# colorize log including level token based on severity
colorize: false
# adds an extra line after each log message with information from which file:line and method
# was this message logged
log_trace: false
#do not log certain paths (example /notices/get_new)
ignored_paths: []
# configuration of all loggers used in app
loggers:
# this logger is parent of all other loggers, by default this is the only one having appender
# which is used by all other loggers
root:
# only messages with severity >= this level from all loggers will be logged
level: warn
# file or syslog, for file variant you can specify other options below like filename,
# pattern or rolling options
type: file
# 'daily', 'weekly', 'monthly' or number as seconds
age: 'weekly'
# how many old log files to keep (156 = 52 * 3 = 3 years for weekly age)
keep: 156
# logger line pattern, you can use following macros
# [%c] name of the logger that generate the log event
# [%d] datestamp
# [%m] the user supplied log message
# [%p] PID of the current process
# [%r] the time in milliseconds since the program started
# [%T] the name of the thread Thread.current[:name]
# [%t] object_id of the thread
# [%F] filename where the logging request was issued
# [%L] line number where the logging request was issued
# [%M] method name where the logging request was issued
# [%X{string}] variable set using ::Logging.mdc['string'] =
pattern: "[%5l %d %c %X{uuid} #%p] %m\n"
# log filename for this environment, it will be placed into #{Rails.root}/log directory
filename: "production.log"
# you log files will be stored here
# note when you log outside of standard rails path you won't see log output in WEBrick
# STDOUT (usually not wanted in development), to use Rails default path, don't set path
# path: /var/log/katello

# you can configure each logger individually, you can turn it off completely by using key
# 'enabled' or you can adjust it's logging 'level'. If you specify level higher than root
# logger has, messages below this level are ignored. If you specify lower level than root
# they are still ignored but you can add appender in Katello::Logging just for this logger
# and see these logs outside of main log.
sql:
enabled: false
app:
enabled: true
glue:
enabled: true
pulp_rest:
enabled: true
cp_rest:
enabled: true
cp_proxy:
enabled: true
foreman_rest:
enabled: true
action:
enabled: true
# tire is a special case, all logs coming from it are debug level however they count depends
# on root level configuration, e.g. root debug level will print most info from tire
# unfortunately there is currently no better way
tire_rest:
enabled: false
yard:
enabled: false
#
# Production environment configuration
#
# The following configuration values override ones from the common section
#
production:
logging:
loggers:
sql:
level: fatal

#
# Development environment configuration
#
# The following configuration values override ones from the common section
#
development:
logging:
ignored_paths: ['/notices/get_new', '/assets/', '/api/tasks/bulk_search']
colorize: true
loggers:
root:
level: debug
type: file
age: 'monthly'
keep: 1
pattern: "[%5l %d %c] %m\n"
filename: "development.log"
yard:
level: info

# To enable external logs tailing add optional 'tail_command:' option to a logger configuration,
# standard output of the command is logged. Useful with `tail` command. E.g.
#
# tail-pulp:
# enabled: true
# tail_command: ssh root@a_host -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tail -f /var/log/pulp/pulp.log
# tail-cp:
# enabled: true
# tail_command: ssh root@a_host -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tail -f /var/log/tomcat6/catalina.out
# tail-kt-client:
# enabled: true
# tail_command: tail -f ~/.katello/client.log
# tail-foreman:
# enabled: true
# tail_command: tail -f ~/Workspace/redhat/foreman/log/development.log


#
# Test environment configuration
#
# The following configuration values override ones from the common section
#
test:
elastic_index: katello_test
logging:
colorize: false
loggers:
root:
level: debug
type: file
age: 'monthly'
keep: 1
pattern: "[%5l %d %c] %m\n"
filename: "test.log"
1 change: 0 additions & 1 deletion katello.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Gem::Specification.new do |gem|

gem.add_dependency "rabl"
gem.add_dependency "tire", "~> 0.6.2"
gem.add_dependency "logging", ">= 1.8.0", '< 2.0.0'
gem.add_dependency "hooks"
gem.add_dependency "foreman-tasks", "~> 0.6.0"
gem.add_dependency "foreman_docker", ">= 0.2.0"
Expand Down
3 changes: 1 addition & 2 deletions lib/katello.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@

module Katello
require "katello/version"
require "katello/tire_bridge"
require "katello/app_config"
require "katello/engine"
require "katello/load_configuration"
require "katello/logging"
require 'katello/middleware/silenced_logger.rb'
end
21 changes: 2 additions & 19 deletions lib/katello/configuration/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,11 @@ def early_config
@early_config ||= load
end

# @return [Hash{String => Hash}] database configurations
def database_configs
@database_configs ||= begin
%w(production development test).inject({}) do |hash, environment|
common = config_data.common.database.to_hash
if config_data.present?(environment.to_sym, :database)
hash.update(
environment =>
common.merge(config_data[environment.to_sym].database.to_hash).stringify_keys)
else
hash
end
end
end
end

private

def load(environment = nil)
Node.new.tap do |c|
load_config_file c, environment
load_config_file c
config_post_process.call c, environment if config_post_process
validate c, environment
end
Expand All @@ -97,9 +81,8 @@ def environment
Rails.env.to_sym rescue raise 'Rails.env is not accessible, try to use #early_config instead'
end

def load_config_file(config, environment = nil)
def load_config_file(config)
config.deep_merge! config_data[:common]
config.deep_merge! config_data[environment] if environment
end

def validate(config, environment)
Expand Down