Skip to content

Commit

Permalink
Merge pull request #20 from kipcole9/logger_warning
Browse files Browse the repository at this point in the history
Conditionally apply Logger.warning/2 or Logger.warn/1
  • Loading branch information
mathieuprog committed May 30, 2023
2 parents c7c3f1b + f95a7e7 commit b774002
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/tz/watch_periodically.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@ defmodule Tz.WatchPeriodically do
alias Tz.PeriodsProvider
alias Tz.Updater

# Logger.warn/1 is deprecated on Elixir 1.15 but since its
# a macro we can replace it without performance penalty by
# selecting the available Logger macro at compile time.
defmacrop logger_warning(message) do
if Code.ensure_loaded?(Logger) && function_exported?(Logger, :"MACRO-warning", 2) do
quote do
Logger.warning(unquote(message))
end
else
quote do
Logger.warn(unquote(message))
end
end
end

defp watch(on_update_callback) do
Logger.debug("Tz is checking for IANA time zone database updates")

case Updater.fetch_latest_iana_tz_version() do
{:ok, latest_version} ->
if latest_version != PeriodsProvider.iana_version() do
link = "https://data.iana.org/time-zones/releases/tzdata#{latest_version}.tar.gz"
Logger.warn("Tz found a more recent time zone database available for download at #{link}")
logger_warning("Tz found a more recent time zone database available for download at #{link}")
on_update_callback && on_update_callback.(latest_version)
end
:error ->
Expand Down
10 changes: 10 additions & 0 deletions test/support/holocene_calendar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,14 @@ defmodule Support.HoloceneCalendar do

@impl true
defdelegate valid_time?(hour, minute, second, microsecond), to: Calendar.ISO

if Code.ensure_loaded?(Calendar.ISO) && function_exported?(Calendar.ISO, :iso_days_to_beginning_of_day, 1) do
@impl true
defdelegate iso_days_to_beginning_of_day(date), to: Calendar.ISO
end

if Code.ensure_loaded?(Calendar.ISO) && function_exported?(Calendar.ISO, :iso_days_to_end_of_day, 1) do
@impl true
defdelegate iso_days_to_end_of_day(date), to: Calendar.ISO
end
end

0 comments on commit b774002

Please sign in to comment.