10000 Update logger by andrew2net · Pull Request #13 · relaton/relaton-cen · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update logger #13

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,13 @@ $ gem install relaton-cen

For CENELEC standards, use references with the prefix `CEN/CLC`. For example, `CEN/CLC Guide 6`.

=== 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 `RelatonCen.configure` block.
=== Search for a standard using keywords

[source,ruby]
----
require 'relaton_cen'
=> true

RelatonCen.configure do |config|
config.logger.level = Logger::DEBUG
end
----

=== Search for a standard using keywords

[source,ruby]
----
hit_collection = RelatonCen::CenBibliography.search("CEN ISO/TS 21003-7")
=> <RelatonCen::HitCollection:0x00000000017de0 @ref=ISO/TS 21003-7 @fetched=false>

Expand Down Expand Up @@ -177,6 +166,9 @@ RelatonCen::XMLParser.from_xml File.read("spec/fixtures/bibdata.xml", encoding:
...
----

=== Logging

RelatonCen 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

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
17 changes: 8 additions & 9 deletions lib/relaton_cen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
require "nokogiri"
require "relaton_iso_bib"
require_relative "relaton_cen/version"
require "relaton_cen/config"
require "relaton_cen/util"
require "relaton_cen/biblographic_item"
require "relaton_cen/scrapper"
require "relaton_cen/hit_collection"
require "relaton_cen/hit"
require "relaton_cen/xml_parser"
require "relaton_cen/hash_converter"
require "relaton_cen/cen_bibliography"
require_relative "relaton_cen/util"
require_relative "relaton_cen/biblographic_item"
require_relative "relaton_cen/scrapper"
require_relative "relaton_cen/hit_collection"
require_relative "relaton_cen/hit"
require_relative "relaton_cen/xml_parser"
require_relative "relaton_cen/hash_converter"
require_relative "relaton_cen/cen_bibliography"

module RelatonCen
# Returns hash of XML greammar
Expand Down
8 changes: 4 additions & 4 deletions lib/relaton_cen/cen_bibliography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLeng
# Util.warn "WARNING: No match found online for `#{id}`. " \
# "The code must be exactly like it is on the standards website."
unless missed_years.empty?
Util.warn "There was no match for `#{year}`, though there " \
Util.info "There was no match for `#{year}`, though there " \
"were matches found for `#{missed_years.join('`, `')}`."
end
# if /\d-\d/.match? code
Expand Down Expand Up @@ -102,15 +102,15 @@ def isobib_results_filter(result, year)

def bib_get(code, year, opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
ref = year.nil? || code.match?(/:\d{4}/) ? code : "#{code}:#{year}"
Util.warn "(#{ref}) Fetching from standards.cencenelec.eu ..."
Util.info "Fetching from standards.cencenelec.eu ...", key: ref
result = search_filter(code) || return
ret = isobib_results_filter(result, year)
if ret[:ret]
bib = year || opts[:keep_year] ? ret[:ret] : ret[:ret].to_most_recent_reference
Util.warn "(#{ref}) Found: `#{bib.docidentifier.first&.id}`"
Util.info "Found: `#{bib.docidentifier.first&.id}`", key: ref
bib
else
Util.warn "(#{ref}) No found."
Util.info "No found.", key: ref
fetch_ref_err(code, year, ret[:years])
end
end
Expand Down
10 changes: 0 additions & 10 deletions lib/relaton_cen/config.rb

This file was deleted.

5 changes: 1 addition & 4 deletions lib/relaton_cen/util.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module RelatonCen
module Util
extend RelatonBib::Util

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

module RelatonCen
VERSION = "1.18.1"
VERSION = "1.19.0"
end
2 changes: 1 addition & 1 deletion relaton_cen.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "mechanize", "~> 2.10"
spec.add_dependency "relaton-iso-bib", "~> 1.18.0"
spec.add_dependency "relaton-iso-bib", "~> 1.19.0"

# For more information and examples about making a new gem, checkout our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/bibdata.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-09-06</fetched>
<title type="title-main" format="text/plain" language="en" script="Latn">Multilayer piping systems for hot and cold water installations inside buildings</title>
<title type="title-part" format="text/plain" language="en" script="Latn">Part 7: Guidance for the assessment of conformity (ISO/TS 21003-7:2019)</title>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/bibdata.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: CENISO/TS21003-7-2019
schema-version: v1.2.8
schema-version: v1.2.9
title:
- type: title-main
content: Multilayer piping systems for hot and cold water installations inside buildings
Expand Down
10 changes: 0 additions & 10 deletions spec/relaton_cen/config_spec.rb

This file was deleted.

5 changes: 0 additions & 5 deletions spec/relaton_cen/util_spec.rb

This file was deleted.

14 changes: 5 additions & 9 deletions spec/relaton_cen_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

RSpec.describe RelatonCen do
before { RelatonCen.instance_variable_set :@configuration, nil }

it "has a version number" do
expect(RelatonCen::VERSION).not_to be nil
end
Expand Down Expand Up @@ -39,7 +37,7 @@
expect do
bib = RelatonCen::CenBibliography.get "EN 13306"
expect(bib.docidentifier[0].id).to eq "EN 13306"
end.to output(/Found: `EN 13306`/).to_stderr
end.to output(/Found: `EN 13306`/).to_stderr_from_any_process
end

it "get ENV", vcr: "env_1993_1_1" do
Expand All @@ -66,7 +64,7 @@
expect do
bib = RelatonCen::CenBibliography.get "EN 13306", nil, keep_year: true
expect(bib.docidentifier[0].id).to eq "EN 13306:2017"
end.to output(/Found: `EN 13306:2017`/).to_stderr
end.to output(/Found: `EN 13306:2017`/).to_stderr_from_any_process
end

it "get amendment" do
Expand All @@ -84,8 +82,6 @@
end

context "get document by year" do
before { RelatonCen.instance_variable_set :@configuration, nil }

it "in code" do
VCR.use_cassette "cen_iso_ts_21003_7" do
bib = RelatonCen::CenBibliography.get "CEN ISO/TS 21003-7:2019"
Expand All @@ -97,15 +93,15 @@
expect do
bib = RelatonCen::CenBibliography.get "CEN ISO/TS 21003-7", "2019"
expect(bib.docidentifier[0].id).to eq "CEN ISO/TS 21003-7:2019"
end.to output(/\(CEN ISO\/TS 21003-7:2019\) Found: `CEN ISO\/TS 21003-7:2019`/).to_stderr
end.to output(/\(CEN ISO\/TS 21003-7:2019\) Found: `CEN ISO\/TS 21003-7:2019`/).to_stderr_from_any_process
end

it "return nil when year is incorrect" do
VCR.use_cassette "cen_iso_ts_21003_7" do
bib = ""
expect do
bib = RelatonCen::CenBibliography.get "CEN ISO/TS 21003-7", "2018"
end.to output(/There was no match for `2018`/).to_stderr
end.to output(/There was no match for `2018`/).to_stderr_from_any_process
expect(bib).to be_nil
end
end
Expand All @@ -127,7 +123,7 @@
bib = ""
expect do
bib = RelatonCen::CenBibliography.get "CEN NOT FOUND"
end.to output(/\[relaton-cen\] \(CEN NOT FOUND\) No found\./).to_stderr
end.to output(/\[relaton-cen\] INFO: \(CEN NOT FOUND\) No found\./).to_stderr_from_any_process
expect(bib).to be_nil
end
end
Expand Down
58 changes: 29 additions & 29 deletions spec/vcr_cassettes/cen_iso_ts_21003_7.yml

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions spec/vcr_cassettes/cr_12101_5_2000.yml

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions spec/vcr_cassettes/cwa_14050_21_2000.yml

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions spec/vcr_cassettes/en_1325.yml

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions spec/vcr_cassettes/en_13306.yml

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions spec/vcr_cassettes/en_285_2015_a1_2021.yml

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions spec/vcr_cassettes/env_1993_1_1.yml

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions spec/vcr_cassettes/hd_1215_2_1988.yml

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions spec/vcr_cassettes/not_found.yml

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions spec/vcr_cassettes/subcommittee.yml

Large diffs are not rendered by default.

Loading
0