Skip to content

Commit

Permalink
Update logger (#2)
Browse files Browse the repository at this point in the history
- Switch to using relaton-logger to log messages
  • Loading branch information
andrew2net authored Jul 4, 2024
1 parent 662f5dc commit c7ca992
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 84 deletions.
21 changes: 7 additions & 14 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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")
=> <RelatonXsf::HitCollection:0x00000000019780 @ref=XEP 0001 @fetched=false>
Expand All @@ -68,7 +57,7 @@ item = hit_collection[0].fetch
[source,ruby]
----
item.to_xml
=> "<bibitem id="XEP0001" type="standard" schema-version="v1.2.8">
=> "<bibitem id="XEP0001" type="standard" schema-version="v1.2.9">
<fetched>2023-07-18</fetched>
<title format="text/plain" language="en" script="Latn">XMPP Extension Protocols</title>
...
Expand All @@ -78,7 +67,7 @@ With argument `bibdata: true` it outputs XML wrapped by `bibdata` element and ad
[source,ruby]
----
item.to_xml bibdata: true
=> "<bibdata type="standard" schema-version="v1.2.8">
=> "<bibdata type="standard" schema-version="v1.2.9">
<fetched>2023-07-18</fetched>
<title format="text/plain" language="en" script="Latn">XMPP Extension Protocols</title>
...
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion lib/relaton_xsf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions lib/relaton_xsf/bibliography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions lib/relaton_xsf/config.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/relaton_xsf/data_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions lib/relaton_xsf/util.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module RelatonXsf
module Util
extend RelatonBib::Util

def self.logger
RelatonXsf.configuration.logger
end
PROGNAME = "relaton-xsf".freeze
end
end
2 changes: 1 addition & 1 deletion lib/relaton_xsf/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RelatonXsf
VERSION = "1.18.1"
VERSION = "1.19.0"
end
2 changes: 1 addition & 1 deletion relaton_xsf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/fixtures/bibdata.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<bibdata type="standard" schema-version="v1.2.8">
<fetched>2024-06-18</fetched>
<bibdata type="standard" schema-version="v1.2.9">
<fetched>2023-11-08</fetched>
<title format="text/plain" language="en" script="Latn">XMPP Extension Protocols</title>
<uri type="src">http://xmpp.org/extensions/xep-0001.html</uri>
<docidentifier type="XEP" primary="true">XEP 0001</docidentifier>
Expand Down Expand Up @@ -44,4 +44,4 @@
<ext>
<doctype>rfc</doctype>
</ext>
</bibdata>
</bibdata>
10 changes: 0 additions & 10 deletions spec/relaton_xsf/config_spec.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/relaton_xsf/data_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions spec/relaton_xsf/util_spec.rb

This file was deleted.

12 changes: 5 additions & 7 deletions spec/relaton_xsf/xsf_bibliography_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,15 +12,15 @@
/(?<=<fetched>)\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
45 changes: 23 additions & 22 deletions spec/vcr_cassettes/get_successful.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c7ca992

Please sign in to comment.