Skip to content

Commit

Permalink
tweaks logger class to always show in stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Jan 5, 2016
1 parent b15925d commit 25a2784
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ output:

debug:
level: "info"
file:
file: output/log.txt

config:
user: config/user.yml
Expand Down
Empty file added output/.gitkeep
Empty file.
11 changes: 8 additions & 3 deletions src/blast.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'logger'
require_relative 'my_logger'
require 'yaml'
#
require_relative 'blast_interface'
Expand All @@ -23,17 +23,22 @@ def initialize(config_path = nil)
super(config_path)
# create logger object
if @store.debug.file.nil?
@logger = Logger.new(STDOUT)
@logger = MyLogger.new(STDOUT)
else
@logger = Logger.new(@store.debug.file)
@logger = MyLogger.new(@store.debug.file)
end
#
if @store.debug.level == 'info'
logger.level = Logger::INFO
elsif @store.debug.level == 'debug'
logger.level = Logger::DEBUG
else
logger.level = Logger::INFO
end
#
logger.progname = 'Blast'
#
logger.info "Log level: #{@store.debug.level}"
# load config file
reload_config(config_path)
#
Expand Down
5 changes: 3 additions & 2 deletions src/download.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'logger'
require_relative 'my_logger'
require 'net/ftp'
require 'net/http'

Expand Down Expand Up @@ -72,7 +72,8 @@ def self.download_fvesca(parent_path, logger)
end

def self.download(parent_path = 'db_and_queries/db')
logger = Logger.new(STDOUT)
logger = MyLogger.new(STDOUT)
logger.progname = 'Download'
#
run = proc do |files, parent, fun|
#
Expand Down
14 changes: 14 additions & 0 deletions src/my_logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'logger'

#
class MyLogger < Logger

def add(*args)
super
puts format_message(format_severity(args[0]),
Time.now,
progname,
args[2]) if @logdev.dev != STDOUT &&
level <= args[0]
end
end
7 changes: 4 additions & 3 deletions src/orf_common.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require 'logger'
require_relative 'my_logger'
#
#
#
module ORFCommon
#
def initialize(sequence, options)
# logger for instance
@logger = Logger.new(STDOUT)
logger.level = (options[:debug] ? Logger::INFO : Logger::UNKNOWN)
@logger = MyLogger.new(STDOUT)
logger.progname = 'ORFCommon'
logger.level = (options[:debug] ? Logger::INFO : Logger::UNKNOWN)
end

def range_to_s(range, str = '')
Expand Down

0 comments on commit 25a2784

Please sign in to comment.