Skip to content

Commit

Permalink
UrlFetchTitle: ロガーを IRC ボットのものと統合する
Browse files Browse the repository at this point in the history
refs #67
  • Loading branch information
ochaochaocha3 committed Apr 20, 2016
1 parent be74f42 commit c34a7db
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/rgrb/plugin/url_fetch_title/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require 'nokogiri'
require 'rgrb/version'
require 'rgrb/plugin/configurable_generator'
require 'rgrb/plugin/use_logger'

module RGRB
module Plugin
Expand All @@ -30,12 +31,12 @@ module UrlFetchTitle
# @see https://github.com/sparklemotion/mechanize/blob/master/lib/mechanize/page.rb Mechanize::Page
class Generator
include ConfigurableGenerator
include UseLogger

def initialize
super

@logger = Lumberjack::Logger.new($stdout,
progname: self.class.to_s)
prepare_default_logger
end

# 設定データを解釈してプラグインの設定を行う
Expand All @@ -61,6 +62,8 @@ def configure(config_data)
"RGRB/%s (Creator's Network IRC bot)"
@user_agent = user_agent_format % RGRB::VERSION

set_logger(config_data)

self
end

Expand Down Expand Up @@ -178,7 +181,7 @@ def detect_encodings(html_code, response_header_charset)
GuessHtmlEncoding::HTMLScanner.new(html_code).encoding
encodings << html_encoding if html_encoding
rescue guess_html_encoding_error
@logger.debug(
logger.debug(
"GuessHtmlEncoding error: #{guess_html_encoding_error}"
)
end
Expand All @@ -205,7 +208,7 @@ def get_html_doc(html_code, encodings)
doc = Nokogiri::HTML(html_code, nil, encoding)
return doc unless encoding_error?(doc)
rescue e
@logger.debug("Nokogiri::HTML error: #{e}")
logger.debug("Nokogiri::HTML error: #{e}")
end
end

Expand Down

0 comments on commit c34a7db

Please sign in to comment.