From c7ca9927200e55e1645c1475677b3a5bf56256c2 Mon Sep 17 00:00:00 2001 From: Andrei Kislichenko Date: Thu, 4 Jul 2024 13:46:23 -0400 Subject: [PATCH] Update logger (#2) - Switch to using relaton-logger to log messages --- README.adoc | 21 ++++------- lib/relaton_xsf.rb | 1 - lib/relaton_xsf/bibliography.rb | 6 +-- lib/relaton_xsf/config.rb | 10 ----- lib/relaton_xsf/data_fetcher.rb | 2 +- lib/relaton_xsf/util.rb | 5 +-- lib/relaton_xsf/version.rb | 2 +- relaton_xsf.gemspec | 2 +- spec/fixtures/bibdata.xml | 6 +-- spec/relaton_xsf/config_spec.rb | 10 ----- spec/relaton_xsf/data_fetcher_spec.rb | 4 +- spec/relaton_xsf/util_spec.rb | 5 --- spec/relaton_xsf/xsf_bibliography_spec.rb | 12 +++--- spec/vcr_cassettes/get_successful.yml | 45 ++++++++++++----------- 14 files changed, 47 insertions(+), 84 deletions(-) delete mode 100644 lib/relaton_xsf/config.rb delete mode 100644 spec/relaton_xsf/config_spec.rb delete mode 100644 spec/relaton_xsf/util_spec.rb diff --git a/README.adoc b/README.adoc index c8ac84e..68999d1 100644 --- a/README.adoc +++ b/README.adoc @@ -38,24 +38,13 @@ Or install it yourself as: == Usage -=== Configuration - -Configuration is optional. The available option is `logger` which is a `Logger` instance. By default, the logger is `Logger.new($stderr)` with `Logger::WARN` level. To change the logger level, use `RelatonXsf.configure` block. +=== Search for a standard using keywords [source,ruby] ---- require 'relaton_xsf' => true -RelatonXsf.configure do |config| - config.logger.level = Logger::DEBUG -end ----- - -=== Search for a standard using keywords - -[source,ruby] ----- hit_collection = RelatonXsf::Bibliography.search("XEP 0001") => @@ -68,7 +57,7 @@ item = hit_collection[0].fetch [source,ruby] ---- item.to_xml -=> " +=> " 2023-07-18 XMPP Extension Protocols ... @@ -78,7 +67,7 @@ With argument `bibdata: true` it outputs XML wrapped by `bibdata` element and ad [source,ruby] ---- item.to_xml bibdata: true -=> " +=> " 2023-07-18 XMPP Extension Protocols ... @@ -134,6 +123,10 @@ Done in: 42 sec. => nil ---- +=== Logging + +RelatonXsf uses the relaton-logger gem for logging. By default, it logs to STDOUT. To change the log levels and add other loggers, read the https://github.com/relaton/relaton-logger#usage[relaton-logger] documentation. + == Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. diff --git a/lib/relaton_xsf.rb b/lib/relaton_xsf.rb index 4d8d2fe..2f15c88 100644 --- a/lib/relaton_xsf.rb +++ b/lib/relaton_xsf.rb @@ -4,7 +4,6 @@ require "relaton/index" require "relaton_bib" require_relative "relaton_xsf/version" -require_relative "relaton_xsf/config" require_relative "relaton_xsf/util" require_relative "relaton_xsf/bibliographic_item" require_relative "relaton_xsf/bibliography" diff --git a/lib/relaton_xsf/bibliography.rb b/lib/relaton_xsf/bibliography.rb index 0320ae0..be7507e 100644 --- a/lib/relaton_xsf/bibliography.rb +++ b/lib/relaton_xsf/bibliography.rb @@ -7,15 +7,15 @@ def search(ref) end def get(code, _year = nil, _opts = {}) - Util.warn "(#{code}) Fetching from Relaton repository ..." + Util.info "Fetching from Relaton repository ...", key: code result = search(code) if result.empty? - Util.warn "(#{code}) Not found." + Util.info "Not found.", key: code return end bib = result.first.fetch - Util.warn "(#{code}) Found: `#{bib.docidentifier.first.id}`" + Util.info "Found: `#{bib.docidentifier.first.id}`", key: code bib end end diff --git a/lib/relaton_xsf/config.rb b/lib/relaton_xsf/config.rb deleted file mode 100644 index d98def1..0000000 --- a/lib/relaton_xsf/config.rb +++ /dev/null @@ -1,10 +0,0 @@ -module RelatonXsf - module Config - include RelatonBib::Config - end - extend Config - - class Configuration < RelatonBib::Configuration - PROGNAME = "relaton-xsf".freeze - end -end diff --git a/lib/relaton_xsf/data_fetcher.rb b/lib/relaton_xsf/data_fetcher.rb index 1340995..4c3dfc5 100644 --- a/lib/relaton_xsf/data_fetcher.rb +++ b/lib/relaton_xsf/data_fetcher.rb @@ -39,7 +39,7 @@ def write_doc(bib) id = bib.docidentifier.find(&:primary).id file = File.join @output, "#{id.gsub(' ', '-').downcase}.#{@ext}" if @files.include? file - warn "WARNING: #{file} already exists" + Util.warn "#{file} already exists" end File.write file, serialize(bib), encoding: "UTF-8" @files << file diff --git a/lib/relaton_xsf/util.rb b/lib/relaton_xsf/util.rb index 0395d1e..c6a102f 100644 --- a/lib/relaton_xsf/util.rb +++ b/lib/relaton_xsf/util.rb @@ -1,9 +1,6 @@ module RelatonXsf module Util extend RelatonBib::Util - - def self.logger - RelatonXsf.configuration.logger - end + PROGNAME = "relaton-xsf".freeze end end diff --git a/lib/relaton_xsf/version.rb b/lib/relaton_xsf/version.rb index 29add25..d1b39d0 100644 --- a/lib/relaton_xsf/version.rb +++ b/lib/relaton_xsf/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RelatonXsf - VERSION = "1.18.1" + VERSION = "1.19.0" end diff --git a/relaton_xsf.gemspec b/relaton_xsf.gemspec index 77aac16..3b93a27 100644 --- a/relaton_xsf.gemspec +++ b/relaton_xsf.gemspec @@ -37,7 +37,7 @@ Gem::Specification.new do |spec| # spec.add_dependency "example-gem", "~> 1.0" spec.add_dependency "mechanize", "~> 2.10" - spec.add_dependency "relaton-bib", "~> 1.18.0" + spec.add_dependency "relaton-bib", "~> 1.19.0" spec.add_dependency "relaton-index", "~> 0.2.0" # For more information and examples about making a new gem, check out our diff --git a/spec/fixtures/bibdata.xml b/spec/fixtures/bibdata.xml index e3b613d..0502d7b 100644 --- a/spec/fixtures/bibdata.xml +++ b/spec/fixtures/bibdata.xml @@ -1,5 +1,5 @@ - - 2024-06-18 + + 2023-11-08 XMPP Extension Protocols http://xmpp.org/extensions/xep-0001.html XEP 0001 @@ -44,4 +44,4 @@ rfc - \ No newline at end of file + diff --git a/spec/relaton_xsf/config_spec.rb b/spec/relaton_xsf/config_spec.rb deleted file mode 100644 index 52c1811..0000000 --- a/spec/relaton_xsf/config_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -describe RelatonXsf do - after { described_class.instance_variable_set :@configuration, nil } - - it "configure" do - described_class.configure do |conf| - conf.logger = :logger - end - expect(described_class.configuration.logger).to eq :logger - end -end diff --git a/spec/relaton_xsf/data_fetcher_spec.rb b/spec/relaton_xsf/data_fetcher_spec.rb index 01a14b6..efc419f 100644 --- a/spec/relaton_xsf/data_fetcher_spec.rb +++ b/spec/relaton_xsf/data_fetcher_spec.rb @@ -59,8 +59,8 @@ it "duplications" do subject.instance_variable_set :@files, ["data/xep-0001.yaml"] expect { subject.write_doc bib }.to output( - "WARNING: data/xep-0001.yaml already exists\n", - ).to_stderr + "\[relaton-xsf\] WARN: data/xep-0001.yaml already exists\n", + ).to_stderr_from_any_process end end diff --git a/spec/relaton_xsf/util_spec.rb b/spec/relaton_xsf/util_spec.rb deleted file mode 100644 index 6c3307c..0000000 --- a/spec/relaton_xsf/util_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -describe RelatonXsf::Util do - it "#respond_to_missing?" do - expect(described_class.respond_to?(:warn)).to be true - end -end diff --git a/spec/relaton_xsf/xsf_bibliography_spec.rb b/spec/relaton_xsf/xsf_bibliography_spec.rb index 94ae160..e18bd33 100644 --- a/spec/relaton_xsf/xsf_bibliography_spec.rb +++ b/spec/relaton_xsf/xsf_bibliography_spec.rb @@ -1,6 +1,4 @@ describe RelatonXsf::Bibliography do - before { RelatonXsf.instance_variable_set :@configuration, nil } - context "get" do it "successful", vcr: "get_successful" do expect do @@ -14,15 +12,15 @@ /(?<=)\d{4}-\d{2}-\d{2}/, Date.today.to_s ) end.to output( - include("[relaton-xsf] (XEP 0001) Fetching from Relaton repository ...", - "[relaton-xsf] (XEP 0001) Found: `XEP 0001`"), - ).to_stderr + include("[relaton-xsf] INFO: (XEP 0001) Fetching from Relaton repository ...", + "[relaton-xsf] INFO: (XEP 0001) Found: `XEP 0001`"), + ).to_stderr_from_any_process end it "not found", vcr: "get_not_found" do expect { RelatonXsf::Bibliography.get "XEP nope" }.to output( - /\[relaton-xsf\] \(XEP nope\) Not found\./, - ).to_stderr + /\[relaton-xsf\] INFO: \(XEP nope\) Not found\./, + ).to_stderr_from_any_process end end end diff --git a/spec/vcr_cassettes/get_successful.yml b/spec/vcr_cassettes/get_successful.yml index 7ba1e87..24d9b21 100644 --- a/spec/vcr_cassettes/get_successful.yml +++ b/spec/vcr_cassettes/get_successful.yml @@ -21,7 +21,7 @@ http_interactions: Connection: - keep-alive Content-Length: - - '2512' + - '2522' Cache-Control: - max-age=300 Content-Security-Policy: @@ -29,7 +29,7 @@ http_interactions: Content-Type: - application/zip Etag: - - W/"76d69b333189384992b79b16291ac49d94370ade76c148e5e6eadaec39f0a80a" + - W/"8fa796769d4371a8e965bf5a6bca3ceb8ec1885dbc8079b9de6755a1d7dbd7e6" Strict-Transport-Security: - max-age=31536000 X-Content-Type-Options: @@ -39,21 +39,21 @@ http_interactions: X-Xss-Protection: - 1; mode=block X-Github-Request-Id: - - 80BB:1626F7:145189:16793A:6671868B + - B114:3311AF:17EDFA5:1AAC39A:6683472E Accept-Ranges: - bytes Date: - - Tue, 18 Jun 2024 13:07:24 GMT + - Tue, 02 Jul 2024 00:17:50 GMT Via: - 1.1 varnish X-Served-By: - - cache-pdk-kpdk1780098-PDK + - cache-iad-kjyo7100104-IAD X-Cache: - MISS X-Cache-Hits: - '0' X-Timer: - - S1718716045.708903,VS0,VE120 + - S1719879471.735618,VS0,VE107 Vary: - Authorization,Accept-Encoding,Origin Access-Control-Allow-Origin: @@ -61,16 +61,16 @@ http_interactions: Cross-Origin-Resource-Policy: - cross-origin X-Fastly-Request-Id: - - c09e80f16849aac3188f1ac219a638ad3ced93d9 + - 0124b3219197dca3f046743382efd1db8b800bb5 Expires: - - Tue, 18 Jun 2024 13:12:24 GMT + - Tue, 02 Jul 2024 00:22:50 GMT Source-Age: - '0' body: encoding: ASCII-8BIT base64_string: | - UEsDBBQAAAAIAGRyw1jLTFSCIAkAAJhUAAANABwAaW5kZXgtdjEueWFtbFVU - CQAD29BdZtvQXWZ1eAsAAQTpAwAABH8AAABt2LsKLgYVhNE+T3Fe4OiZmf3f + UEsDBBQAAAAIADpy4Vic/jzyKgkAAPBUAAANABwAaW5kZXgtdjEueWFtbFVU + CQADj7qCZo+6gmZ1eAsAAQTpAwAABH8AAABt2LsKLgYVhNE+T3Fe4OiZmf3f 0gmmFMTKNpAIgoKIhb69Bjtdu9xM93Xr69ev33398v2ff/r+yx9/+P2Xb9++ 5bsvX77/05//8vP3X3768R8//vqfP//t6y/vX/3rx7/+5X+29bbazttpe96e tg9vH9o+vX1q+/L2pe3b27e2H28/2OYbt/mmrbtF3eJuUbe4W9Qt7hZ1i7tF @@ -121,11 +121,12 @@ http_interactions: S85ecvKSs5ecvOTsJScvOXvJyUvOXnLykrOXnLzk7CUnLzl7yclLzl5y8pKz l5y85OwlJy85e8nJS85ecvKSs5ecvOTsJScvOXvJyUvOXnLykrOXnLzk7CUn Lzl7yclLzl5y8pKzl5y85OwlJy85e8nJS85ecvKSs5ecvOTsJScvOXvJyUvO - XnLykrOXnLzk7CUnLzl7yclLzl5y8pKzl5y85OwlJy85e8nBS/7ww29++7sf - sP77zz/+9Nef/2//z/8c1r+8/7v9N1BLAQIeAxQAAAAIAGRyw1jLTFSCIAkA - AJhUAAANABgAAAAAAAEAAACkgQAAAABpbmRleC12MS55YW1sVVQFAAPb0F1m - dXgLAAEE6QMAAAR/AAAAUEsFBgAAAAABAAEAUwAAAGcJAAAAAA== - recorded_at: Tue, 18 Jun 2024 13:07:24 GMT + XnLykrOXnLzk7CUnLzl7yclLzl5y8pKzl5y85OwlJy85e8nJS85ecvKSs5cc + vOQPP/zmt7/7Aeu///zjT3/9+f/2//zPYf3L+7/bfwNQSwECHgMUAAAACAA6 + cuFYnP488ioJAADwVAAADQAYAAAAAAABAAAApIEAAAAAaW5kZXgtdjEueWFt + bFVUBQADj7qCZnV4CwABBOkDAAAEfwAAAFBLBQYAAAAAAQABAFMAAABxCQAA + AAA= + recorded_at: Tue, 02 Jul 2024 00:17:50 GMT - request: method: get uri: https://raw.githubusercontent.com/relaton/relaton-data-xsf/main/data/xep-0001.yaml @@ -175,23 +176,23 @@ http_interactions: X-Xss-Protection: - 1; mode=block X-Github-Request-Id: - - 958A:3A63B6:16DAC5:190274:6671868C + - FF07:3FB39B:2619F5:29D417:6683472E Content-Encoding: - gzip Accept-Ranges: - bytes Date: - - Tue, 18 Jun 2024 13:07:25 GMT + - Tue, 02 Jul 2024 00:17:51 GMT Via: - 1.1 varnish X-Served-By: - - cache-pdk-kpdk1780111-PDK + - cache-iad-kjyo7100102-IAD X-Cache: - MISS X-Cache-Hits: - '0' X-Timer: - - S1718716045.972474,VS0,VE92 + - S1719879471.990420,VS0,VE115 Vary: - Authorization,Accept-Encoding,Origin Access-Control-Allow-Origin: @@ -199,9 +200,9 @@ http_interactions: Cross-Origin-Resource-Policy: - cross-origin X-Fastly-Request-Id: - - 5da33f4569a6d95caef68a97a33b78bc4d7f5364 + - 84a60a9c8349d503bf91dbbc5bcb7dcc6c7a1fbf Expires: - - Tue, 18 Jun 2024 13:12:25 GMT + - Tue, 02 Jul 2024 00:22:51 GMT Source-Age: - '0' body: @@ -220,5 +221,5 @@ http_interactions: 9vUMwNuMYUIxW/We2+Y+VQhtN1ivp+elWFfkLDODyARABeEyi00SGRrnvZhd tfL68n0Y8H92MJ7+omETFbupY/SUBlFYJEVYJJnoTjBqCb5J9hvKzWQ4ewcA AA== - recorded_at: Tue, 18 Jun 2024 13:07:24 GMT + recorded_at: Tue, 02 Jul 2024 00:17:51 GMT recorded_with: VCR 6.2.0