Skip to content

Commit

Permalink
Update logger (#121)
Browse files Browse the repository at this point in the history
* Switch to using relaton-logger to log messages
* fix base64 issue with Ruby 3.4
  • Loading branch information
andrew2net authored Jul 3, 2024
1 parent 50d146b commit b6dc86d
Show file tree
Hide file tree
Showing 32 changed files with 31,920 additions and 30,793 deletions.
17 changes: 5 additions & 12 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,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 `RelatonIetf.configure` block.
=== Fetching documents

[source,ruby]
----
require 'relaton_ietf'
=> true
RelatonIetf.configure do |config|
config.logger.level = Logger::DEBUG
end
----

=== Fetching documents

[source,ruby]
----
# Fetch RFC document
item = RelatonIetf::IetfBibliography.get 'IETF RFC 8341'
[relaton-ietf] (IETF RFC 8341) Fetching from Relaton repository ...
Expand Down Expand Up @@ -165,6 +154,10 @@ Done in: 360 sec.
=> nil
----

=== Logging

RelatonIetf 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.

== Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/metanorma/relaton-ietf.
Expand Down
3 changes: 3 additions & 0 deletions grammars/basicdoc.rng
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@
<data type="ID"/>
</attribute>
<attribute name="reviewer"/>
<optional>
<attribute name="type"/>
</optional>
<optional>
<attribute name="date">
<data type="dateTime"/>
Expand Down
1 change: 0 additions & 1 deletion lib/relaton_ietf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require "relaton/index"
require "relaton_bib"
require "relaton_ietf/version"
require "relaton_ietf/config"
require "relaton_ietf/util"
require "relaton_ietf/document_type"
require "relaton_ietf/bibxml_parser"
Expand Down
10 changes: 0 additions & 10 deletions lib/relaton_ietf/config.rb

This file was deleted.

6 changes: 3 additions & 3 deletions lib/relaton_ietf/data_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ def fetch_ieft_rfcs
rfc_index.xpath("xmlns:rfc-entry").each do |doc|
save_doc RfcEntry.parse(doc)
rescue StandardError => e
warn "Error parsing #{doc.at('./xmlns:doc-id').text}: #{e.message}"
warn e.backtrace[0..5].join("\n")
Util.error "Error parsing #{doc.at('./xmlns:doc-id').text}: #{e.message}\n" \
"#{e.backtrace[0..5].join("\n")}"
end
end

Expand Down Expand Up @@ -199,7 +199,7 @@ def save_doc(entry, check_duplicate: true) # rubocop:disable Metrics/MethodLengt
end
file = file_name entry
if check_duplicate && @files.include?(file)
warn "File #{file} already exists. Document: #{entry.docnumber}"
Util.warn "File #{file} already exists. Document: #{entry.docnumber}"
elsif check_duplicate
@files << file
end
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_ietf/document_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(type:, abbreviation: nil)

def check_type(type)
unless DOCTYPES.include? type
Util.warn "WARNING: Invalid doctype: `#{type}`"
Util.warn "Invalid doctype: `#{type}`"
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/relaton_ietf/ietf_bibliography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def search(text)
# reference is required
# @return [RelatonIetf::IetfBibliographicItem] Relaton of reference
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
docid = result.docidentifier.detect(&:primary) || result.docidentifier.first
Util.warn "(#{code}) Found: `#{docid.id}`"
Util.info "Found: `#{docid.id}`", key: code
else
Util.warn "(#{code}) Not found."
Util.info "Not found.", key: code
end
result
end
Expand Down
5 changes: 1 addition & 4 deletions lib/relaton_ietf/util.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module RelatonIetf
module Util
extend RelatonBib::Util

def self.logger
RelatonIetf.configuration.logger
end
PROGNAME = "relaton-ietf".freeze
end
end
2 changes: 1 addition & 1 deletion lib/relaton_ietf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonIetf
VERSION = "1.18.0".freeze
VERSION = "1.19.0".freeze
end
4 changes: 4 additions & 0 deletions lib/relaton_ietf/xml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def fetch_editorialgroup(ext)
end
RelatonBib::EditorialGroup.new eg if eg.any?
end

def create_doctype(type)
DocumentType.new type: type.text, abbreviation: type[:abbreviation]
end
end
end
end
3 changes: 2 additions & 1 deletion relaton_ietf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")

spec.add_dependency "relaton-bib", "~> 1.18.0"
spec.add_dependency "base64"
spec.add_dependency "relaton-bib", "~> 1.19.0"
spec.add_dependency "relaton-index", "~> 0.2.3"
end
115 changes: 109 additions & 6 deletions spec/examples/bcp_47.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,124 @@
<bibdata type="standard" schema-version="v1.2.8">
<fetched>2022-11-26</fetched>
<bibdata type="standard" schema-version="v1.2.9">
<fetched>2024-03-07</fetched>
<title format="text/plain" language="en" script="Latn">Best Current Practice 47</title>
<uri type="src">https://www.rfc-editor.org/info/bcp47</uri>
<docidentifier type="IETF" primary="true">BCP 47</docidentifier>
<docnumber>BCP0047</docnumber>
<language>en</language>
<script>Latn</script>
<relation type="includes">
<bibitem>
<formattedref format="text/plain">RFC4647</formattedref>
<bibitem type="standard">
<title type="main" format="text/plain">Matching of Language Tags</title>
<uri type="src">https://www.rfc-editor.org/info/rfc4647</uri>
<docidentifier type="IETF" primary="true">RFC 4647</docidentifier>
<docidentifier type="DOI">10.17487/RFC4647</docidentifier>
<docnumber>RFC4647</docnumber>
<date type="published">
<on>2006-09</on>
</date>
<contributor>
<role type="editor"/>
<person>
<name>
<completename language="en" script="Latn">A. Phillips</completename>
</name>
</person>
</contributor>
<contributor>
<role type="editor"/>
<person>
<name>
<completename language="en" script="Latn">M. Davis</completename>
</name>
</person>
</contributor>
<contributor>
<role type="publisher"/>
<organization>
<name>RFC Publisher</name>
</organization>
</contributor>
<contributor>
<role type="authorizer"/>
<organization>
<name>RFC Series</name>
</organization>
</contributor>
<language>en</language>
<script>Latn</script>
<abstract format="text/html" language="en" script="Latn">
<p>This document describes a syntax, called a "language-range", for specifying items in a user's list of language preferences. It also describes different mechanisms for comparing and matching these to language tags. Two kinds of matching mechanisms, filtering and lookup, are defined. Filtering produces a (potentially empty) set of language tags, whereas lookup produces a single language tag. Possible applications include language negotiation or content selection. This document, in combination with RFC 4646, replaces RFC 3066, which replaced RFC 1766. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</p>
</abstract>
<series>
<title format="text/plain">BCP</title>
<number>47</number>
</series>
<series>
<title format="text/plain">RFC</title>
<number>4647</number>
</series>
<series type="stream">
<title format="text/plain">IETF</title>
</series>
<keyword>Lang-Tag</keyword>
</bibitem>
</relation>
<relation type="includes">
<bibitem>
<formattedref format="text/plain">RFC5646</formattedref>
<bibitem type="standard">
<title type="main" format="text/plain">Tags for Identifying Languages</title>
<uri type="src">https://www.rfc-editor.org/info/rfc5646</uri>
<docidentifier type="IETF" primary="true">RFC 5646</docidentifier>
<docidentifier type="DOI">10.17487/RFC5646</docidentifier>
<docnumber>RFC5646</docnumber>
<date type="published">
<on>2009-09</on>
</date>
<contributor>
<role type="editor"/>
<person>
<name>
<completename language="en" script="Latn">A. Phillips</completename>
</name>
</person>
</contributor>
<contributor>
<role type="editor"/>
<person>
<name>
<completename language="en" script="Latn">M. Davis</completename>
</name>
</person>
</contributor>
<contributor>
<role type="publisher"/>
<organization>
<name>RFC Publisher</name>
</organization>
</contributor>
<contributor>
<role type="authorizer"/>
<organization>
<name>RFC Series</name>
</organization>
</contributor>
<language>en</language>
<script>Latn</script>
<abstract format="text/html" language="en" script="Latn">
<p>This document describes the structure, content, construction, and semantics of language tags for use in cases where it is desirable to indicate the language used in an information object. It also describes how to register values for use in language tags and the creation of user-defined extensions for private interchange. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</p>
</abstract>
<series>
<title format="text/plain">BCP</title>
<number>47</number>
</series>
<series>
<title format="text/plain">RFC</title>
<number>5646</number>
</series>
<series type="stream">
<title format="text/plain">IETF</title>
</series>
<keyword>language tags</keyword>
<keyword>private interchange</keyword>
</bibitem>
</relation>
</bibdata>
2 changes: 1 addition & 1 deletion spec/examples/bib_item.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.8">
<bibdata type="standard" schema-version="v1.2.9">
<fetched>2023-07-02</fetched>
<title type="main" format="text/plain">Network Configuration Access Control Model</title>
<uri type="src">https://www.rfc-editor.org/info/rfc8341</uri>
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/from-bibxm-ids.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.8">
<bibdata type="standard" schema-version="v1.2.9">
<title format="text/plain" language="en" script="Latn">Forming Intuitive Email Addresses</title>
<uri type="src">https://datatracker.ietf.org/doc/html/draft--pale-email-00</uri>
<docidentifier type="Internet-Draft" primary="true">draft--pale-email-00</docidentifier>
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/from_yaml.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.8">
<bibdata type="standard" schema-version="v1.2.9">
<fetched>2022-06-22</fetched>
<title format="text/plain" language="en" script="Latn">Network Configuration Access Control Model</title>
<uri type="src">https://www.rfc-editor.org/info/rfc8341</uri>
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/i_d_bib_item.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.8">
<bibdata type="standard" schema-version="v1.2.9">
<fetched>2023-03-08</fetched>
<title format="text/plain" language="en" script="Latn">Centralized Conferencing (XCON) Media Models</title>
<uri type="src">https://datatracker.ietf.org/doc/html/draft-burger-xcon-mmodels-00</uri>
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/rfc_xml.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.8">
<bibdata type="standard" schema-version="v1.2.9">
<title format="text/plain" language="en" script="Latn">ACVP Secure Hash Algorithm (SHA) JSON Specification</title>
<docidentifier type="Internet-Draft" primary="true">draft-ietf-acvp-subsha-1.0</docidentifier>
<docidentifier type="IETF" scope="docName">draft-ietf-acvp-subsha-1.0</docidentifier>
Expand Down
10 changes: 0 additions & 10 deletions spec/relaton_ietf/config_spec.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/relaton_ietf/data_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
expect(File).to receive(:write)
.with("dir/RFC0001.xml", "<xml/>", encoding: "UTF-8")
expect { subject.save_doc entry }
.to output(/File dir\/RFC0001.xml already exists/).to_stderr
.to output(/File dir\/RFC0001.xml already exists/).to_stderr_from_any_process
end

it "downcase file name for ID" do
Expand Down
2 changes: 1 addition & 1 deletion spec/relaton_ietf/document_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
it "warn if doctype is invalid" do
expect do
described_class.new type: "type"
end.to output(/\[relaton-ietf\] WARNING: Invalid doctype: `type`/).to_stderr_from_any_process
end.to output(/\[relaton-ietf\] WARN: Invalid doctype: `type`/).to_stderr_from_any_process
end
end
4 changes: 2 additions & 2 deletions spec/relaton_ietf/ietf_bibliographic_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
expect(subject.to_hash).to eq(
"docid" => [{ "id" => "RFC 123", "type" => "IETF" }], "doctype" => { "type" => "RFC" },
"ext" => { "schema-version" => "v1.0.1", "stream" => "IETF" },
"id" => "RFC123", "schema-version" => "v1.2.8"
"id" => "RFC123", "schema-version" => "v1.2.9"
)
end

it "to_xml" do
expect(subject.to_xml(bibdata: true)).to be_equivalent_to <<~XML
<bibdata schema-version="v1.2.8">
<bibdata schema-version="v1.2.9">
<docidentifier type="IETF">RFC 123</docidentifier>
<ext schema-version="v1.0.1">
<doctype>RFC</doctype>
Expand Down
5 changes: 0 additions & 5 deletions spec/relaton_ietf/util_spec.rb

This file was deleted.

9 changes: 9 additions & 0 deletions spec/relaton_ietf/xml_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@
expect(bib.docidentifier.first.id).to eq "RFC0001"
expect(bib.stream).to eq "IETF"
end

it "create_doctype" do
node = double(text: "rfc")
expect(node).to receive(:[]).with(:abbreviation).and_return("RFC")
dt = described_class.send(:create_doctype, node)
expect(dt).to be_instance_of RelatonIetf::DocumentType
expect(dt.type).to eq "rfc"
expect(dt.abbreviation).to eq "RFC"
end
end
Loading

0 comments on commit b6dc86d

Please sign in to comment.