Skip to content

Commit

Permalink
Merge pull request #1306 from yeti-switch/pgq-stdout-logger
Browse files Browse the repository at this point in the history
stdout logger supporting for pgq-processors
  • Loading branch information
dmitry-sinina authored Jun 29, 2023
2 parents 791a06e + 1836e9c commit 8fd7864
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pgq-processors/pgq_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def initialize

@config = ::PgqConfig.new(ENV['config_file'], ENV['processor'])
ActiveRecord::Base.establish_connection(@config['source_database'])
@logger = Logger::Syslog.new(@config['syslog_program_name'], Syslog::LOG_LOCAL7)
@logger = build_logger
HttpLogger.logger = @logger
Pgq::Worker.logger = @logger

Expand All @@ -43,4 +43,27 @@ def initialize
subject: @config['mail_subject']
}
end

private

def build_logger
if ENV['LOG_TO_STDOUT'].present?
stdout_logger
else
syslog_logger
end
end

def stdout_logger
STDOUT.sync = true
logger = Logger.new(STDOUT)
logger.level = Logger::INFO
logger
end

def syslog_logger
logger = Logger::Syslog.new(@config['syslog_program_name'], Syslog::LOG_LOCAL7)
logger.level = Logger::INFO
logger
end
end

0 comments on commit 8fd7864

Please sign in to comment.