Skip to content

Commit 579c5fb

Browse files
committed
chore: Normalizing all loggers.
1 parent 9d42ca9 commit 579c5fb

10 files changed

+44
-48
lines changed

README.md

+20-23
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,7 @@ Add the following function in the module App.Image:
29722972

29732973
{:ok, %GenMagic.Result{} = res} ->
29742974
require Logger
2975-
Logger.warning(%{gen_magic_response: res})
2975+
Logger.warning("⚠️ MIME type error: #{inspect(res)}")
29762976
{:error, "Not acceptable."}
29772977
end
29782978
end
@@ -3074,7 +3074,7 @@ def handle_progress(:image_list, entry, socket) when entry.done? do
30743074
# Otherwise, if there was an error uploading the image, we log the error and show it to the person.
30753075
else
30763076
%{error: reason} ->
3077-
Logger.info("Error uploading image. #{inspect(reason)}")
3077+
Logger.warning("⚠️ Error uploading image. #{inspect(reason)}")
30783078
{:noreply, push_event(socket, "toast", %{message: "Image couldn't be uploaded to S3.\n#{reason}"})}
30793079

30803080
_ ->
@@ -3616,7 +3616,7 @@ def check_models_on_startup do
36163616
App.Models.verify_and_download_models()
36173617
|> case do
36183618
{:error, msg} ->
3619-
Logger.warning(msg)
3619+
Logger.error("⚠️ #{msg}")
36203620
System.stop(0)
36213621

36223622
:ok ->
@@ -3908,7 +3908,7 @@ defmodule App.Models do
39083908
# It will load the model and the respective the featurizer, tokenizer and generation config if needed,
39093909
# and return a map with all of these at the end.
39103910
defp load_offline_model(model) do
3911-
Logger.info("Loading #{model.name}...")
3911+
Logger.info("ℹ️ Loading #{model.name}...")
39123912

39133913
# Loading model
39143914
loading_settings = {:hf, model.name, cache_dir: model.cache_path, offline: true}
@@ -3957,7 +3957,7 @@ defmodule App.Models do
39573957
# Downloads the models according to a given %ModelInfo struct.
39583958
# It will load the model and the respective the featurizer, tokenizer and generation config if needed.
39593959
defp download_model(model) do
3960-
Logger.info("Downloading #{model.name}...")
3960+
Logger.info("ℹ️ Downloading #{model.name}...")
39613961

39623962
# Download model
39633963
downloading_settings = {:hf, model.name, cache_dir: model.cache_path}
@@ -3999,7 +3999,7 @@ defmodule App.Models do
39993999
end
40004000
else
40014001
_ ->
4002-
Logger.info("No dowlnoad")
4002+
# No download
40034003
:ok
40044004
end
40054005
end
@@ -4189,7 +4189,7 @@ defmodule App.KnnIndex do
41894189

41904190
# If the index file does exist, we compare the one with teh table and check for incoherences.
41914191
true ->
4192-
Logger.info("Index file found on disk. Let's compare it with the database...")
4192+
Logger.info("ℹ️ Index file found on disk. Let's compare it with the database...")
41934193

41944194
App.Repo.get_by(App.HnswlibIndex, id: 1)
41954195
|> case do
@@ -4214,7 +4214,7 @@ defmodule App.KnnIndex do
42144214
HNSWLib.Index.get_current_count(index),
42154215
true <-
42164216
index_count == db_count do
4217-
Logger.info("Integrity: " <> "\u2705.")
4217+
Logger.info("ℹ️ Integrity: ")
42184218
{:ok, {index, schema, space}}
42194219

42204220
# If it fails, we return an error.
@@ -4224,7 +4224,7 @@ defmodule App.KnnIndex do
42244224
{:error, "Integrity error. The count of images from index differs from the database."}}
42254225

42264226
{:error, msg} ->
4227-
Logger.warning(inspect(msg))
4227+
Logger.error("⚠️ #{msg}")
42284228
{:stop, {:error, msg}}
42294229
end
42304230
end
@@ -4260,7 +4260,7 @@ defmodule App.KnnIndex do
42604260
HNSWLib.Index.get_current_count(index),
42614261
:ok <-
42624262
HNSWLib.Index.save_index(index, @saved_index) do
4263-
Logger.info("idx: #{idx}")
4263+
42644264
{:reply, {:ok, idx}, state}
42654265
else
42664266
{:error, msg} ->
@@ -4275,8 +4275,7 @@ defmodule App.KnnIndex do
42754275
def handle_call({:knn_search, input}, _, {index, _, _} = state) do
42764276
# We search for the nearest neighbors of the input embedding.
42774277
case HNSWLib.Index.knn_query(index, input, k: 1) do
4278-
{:ok, labels, distances} ->
4279-
Logger.info(inspect(distances))
4278+
{:ok, labels, _distances} ->
42804279

42814280
response =
42824281
labels[0]
@@ -4297,7 +4296,7 @@ defmodule App.KnnIndex do
42974296
def handle_call(:not_empty, _, {index, _, _} = state) do
42984297
case HNSWLib.Index.get_current_count(index) do
42994298
{:ok, 0} ->
4300-
Logger.warning("Empty index.")
4299+
Logger.warning("⚠️ Empty index.")
43014300
{:reply, :error, state}
43024301

43034302
{:ok, _} ->
@@ -4388,20 +4387,20 @@ defmodule App.HnswlibIndex do
43884387
|> case do
43894388
# If the table is empty
43904389
nil ->
4391-
Logger.info("No index file found in DB. Creating new one...")
4390+
Logger.info("ℹ️ No index file found in DB. Creating new one...")
43924391
create(space, dim, max_elements)
43934392

43944393
# If the table is not empty but has no file
43954394
response when response.file == nil ->
4396-
Logger.info("Empty index file in DB. Recreating one...")
4395+
Logger.info("ℹ️ Empty index file in DB. Recreating one...")
43974396

43984397
# Purge the table and create a new file row in it
43994398
App.Repo.delete_all(App.HnswlibIndex)
44004399
create(space, dim, max_elements)
44014400

44024401
# If the table is not empty and has a file
44034402
index_db ->
4404-
Logger.info("Index file found in DB. Loading it...")
4403+
Logger.info("ℹ️ Index file found in DB. Loading it...")
44054404

44064405
# We get the path of the index
44074406
with path <- App.KnnIndex.index_path(),
@@ -4575,11 +4574,11 @@ defmodule App.Application do
45754574
App.Models.verify_and_download_models()
45764575
|> case do
45774576
{:error, msg} ->
4578-
Logger.warning(msg)
4577+
Logger.error("⚠️ #{msg}")
45794578
System.stop(0)
45804579

45814580
:ok ->
4582-
Logger.info("Models: " <> "\u2705")
4581+
Logger.info("ℹ️ Models: ")
45834582
:ok
45844583
end
45854584
end
@@ -5030,8 +5029,6 @@ def handle_info({ref, %{chunks: [%{text: text}]} = result}, %{assigns: assigns}
50305029
)}
50315030
# record without entries
50325031
{:not_empty_index, :error} ->
5033-
Logger.debug("No entries in Index")
5034-
50355032
{:noreply,
50365033
assign(socket,
50375034
mic_off?: false,
@@ -5362,7 +5359,7 @@ def handle_progress(:image_list, entry, socket) when entry.done? do
53625359

53635360
# Otherwise, if there was an error uploading the image, we log the error and show it to the person.
53645361
%{error: errors} ->
5365-
Logger.warning("Error uploading image. #{inspect(errors)}")
5362+
Logger.warning("⚠️ Error uploading image. #{inspect(errors)}")
53665363
{:noreply, push_event(socket, "toast", %{message: "Image couldn't be uploaded to S3"})}
53675364
end
53685365
end
@@ -5436,13 +5433,13 @@ def handle_upload({:ok, %{path: path, tensor: tensor, image_info: image_info} =
54365433

54375434
# If S3 upload fails, we return error
54385435
{:error, reason} ->
5439-
Logger.warning("Error uploading image: #{inspect(reason)}")
5436+
Logger.warning("⚠️ Error uploading image: #{inspect(reason)}")
54405437
{:postpone, %{error: "Bucket error"}}
54415438
end
54425439
end
54435440

54445441
def handle_upload({:error, error}) do
5445-
Logger.warning("Error creating partial image: #{inspect(error)}")
5442+
Logger.warning("⚠️ Error creating partial image: #{inspect(error)}")
54465443
{:postpone, %{error: "Error creating partial image"}}
54475444
end
54485445
```

_comparison/manage_models.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ defmodule Comparison.Models do
5353
# It will load the model and the respective the featurizer, tokenizer and generation config if needed,
5454
# and return a map with all of these at the end.
5555
defp load_offline_model_params(model) do
56-
Logger.info("Loading #{model.name}...")
56+
Logger.info("ℹ️ Loading #{model.name}...")
5757

5858
# Loading model
5959
loading_settings = {:hf, model.name, cache_dir: model.cache_path, offline: true}
@@ -95,7 +95,7 @@ defmodule Comparison.Models do
9595
# Downloads the models according to a given %ModelInfo struct.
9696
# It will load the model and the respective the featurizer, tokenizer and generation config if needed.
9797
defp download_model(model) do
98-
Logger.info("Downloading #{model.name}...")
98+
Logger.info("ℹ️ Downloading #{model.name}...")
9999

100100
# Download model
101101
downloading_settings = {:hf, model.name, cache_dir: model.cache_path}

_comparison/run.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ defmodule Benchmark do
120120

121121
# Go over each image and make prediction
122122
Enum.each(vips_images_with_captions, fn image ->
123-
Logger.info("Benchmarking image #{image.id}...")
123+
Logger.info("📊 Benchmarking image #{image.id}...")
124124

125125
# Run the prediction
126126
{time_in_microseconds, prediction} =

deployment.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ defmodule App.Models do
926926
# It will load the model and the respective the featurizer, tokenizer and generation config if needed,
927927
# and return a map with all of these at the end.
928928
defp load_offline_model(model) do
929-
Logger.info("Loading #{model.name}...")
929+
Logger.info("ℹ️ Loading #{model.name}...")
930930

931931
# Loading model
932932
loading_settings = {:hf, model.name, cache_dir: model.cache_path, offline: true}
@@ -968,7 +968,7 @@ defmodule App.Models do
968968
# Downloads the models according to a given %ModelInfo struct.
969969
# It will load the model and the respective the featurizer, tokenizer and generation config if needed.
970970
defp download_model(model) do
971-
Logger.info("Downloading #{model.name}...")
971+
Logger.info("ℹ️ Downloading #{model.name}...")
972972

973973
# Download model
974974
downloading_settings = {:hf, model.name, cache_dir: model.cache_path}

lib/app/application.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ defmodule App.Application do
1515
App.Models.verify_and_download_models()
1616
|> case do
1717
{:error, msg} ->
18-
Logger.warning(msg)
18+
Logger.error("⚠️ #{msg}")
1919
System.stop(0)
2020

2121
:ok ->
22-
Logger.info("Models: " <> "\u2705")
22+
Logger.info("ℹ️ Models: ")
2323
:ok
2424
end
2525
end

lib/app/hnswlib_index.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ defmodule App.HnswlibIndex do
3333
|> case do
3434
# If the table is empty
3535
nil ->
36-
Logger.info("No index file found in DB. Creating new one...")
36+
Logger.info("ℹ️ No index file found in DB. Creating new one...")
3737
create(space, dim, max_elements)
3838

3939
# If the table is not empty but has no file
4040
response when response.file == nil ->
41-
Logger.info("Empty index file in DB. Recreating one...")
41+
Logger.info("ℹ️ Empty index file in DB. Recreating one...")
4242

4343
# Purge the table and create a new file row in it
4444
App.Repo.delete_all(App.HnswlibIndex)
4545
create(space, dim, max_elements)
4646

4747
# If the table is not empty and has a file
4848
index_db ->
49-
Logger.info("Index file found in DB. Loading it...")
49+
Logger.info("ℹ️ Index file found in DB. Loading it...")
5050

5151
# We get the path of the index
5252
with path <- App.KnnIndex.index_path(),

lib/app/image.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ defmodule App.Image do
127127

128128
# In case the evaluation fails and it's not acceptable.
129129
{:ok, %GenMagic.Result{} = res} ->
130-
Logger.warning(%{gen_magic_response: res})
130+
Logger.warning("⚠️ MIME type error: #{inspect(res)}")
131131
{:error, "Not acceptable."}
132132
end
133133
end

lib/app/knn_index.ex

+6-7
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ defmodule App.KnnIndex do
6666

6767
# If the index file does exist, we compare the one with teh table and check for incoherences.
6868
true ->
69-
Logger.info("Index file found on disk. Let's compare it with the database...")
69+
Logger.info("ℹ️ Index file found on disk. Let's compare it with the database...")
7070

7171
App.Repo.get_by(App.HnswlibIndex, id: 1)
7272
|> case do
@@ -91,7 +91,7 @@ defmodule App.KnnIndex do
9191
HNSWLib.Index.get_current_count(index),
9292
true <-
9393
index_count == db_count do
94-
Logger.info("Integrity: " <> "\u2705.")
94+
Logger.info("ℹ️ Integrity: ")
9595
{:ok, {index, schema, space}}
9696

9797
# If it fails, we return an error.
@@ -101,7 +101,7 @@ defmodule App.KnnIndex do
101101
{:error, "Integrity error. The count of images from index differs from the database."}}
102102

103103
{:error, msg} ->
104-
Logger.warning(inspect(msg))
104+
Logger.error("⚠️ #{msg}")
105105
{:stop, {:error, msg}}
106106
end
107107
end
@@ -137,7 +137,7 @@ defmodule App.KnnIndex do
137137
HNSWLib.Index.get_current_count(index),
138138
:ok <-
139139
HNSWLib.Index.save_index(index, @saved_index) do
140-
Logger.info("idx: #{idx}")
140+
141141
{:reply, {:ok, idx}, state}
142142
else
143143
{:error, msg} ->
@@ -152,8 +152,7 @@ defmodule App.KnnIndex do
152152
def handle_call({:knn_search, input}, _, {index, _, _} = state) do
153153
# We search for the nearest neighbors of the input embedding.
154154
case HNSWLib.Index.knn_query(index, input, k: 1) do
155-
{:ok, labels, distances} ->
156-
Logger.info(inspect(distances))
155+
{:ok, labels, _distances} ->
157156

158157
response =
159158
labels[0]
@@ -174,7 +173,7 @@ defmodule App.KnnIndex do
174173
def handle_call(:not_empty, _, {index, _, _} = state) do
175174
case HNSWLib.Index.get_current_count(index) do
176175
{:ok, 0} ->
177-
Logger.warning("Empty index.")
176+
Logger.warning("⚠️ Empty index.")
178177
{:reply, :error, state}
179178

180179
{:ok, _} ->

lib/app/models.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ defmodule App.Models do
281281
{:ok, map()} | {:error, String.t()}
282282

283283
defp load_offline_model(model) do
284-
Logger.info("Loading #{model.name}...")
284+
Logger.info("ℹ️ Loading #{model.name}...")
285285

286286
# Loading model
287287
loading_settings = {:hf, model.name, cache_dir: model.cache_path, offline: true}
@@ -330,7 +330,7 @@ defmodule App.Models do
330330
# It will load the model and the respective the featurizer, tokenizer and generation config if needed.
331331
@spec download_model(map()) :: {:ok, map()} | {:error, binary()}
332332
defp download_model(model) do
333-
Logger.info("Downloading #{model.name}...")
333+
Logger.info("ℹ️ Downloading #{model.name}...")
334334

335335
# Download model
336336
downloading_settings = {:hf, model.name, cache_dir: model.cache_path}
@@ -370,7 +370,7 @@ defmodule App.Models do
370370
{:error, msg} -> {:error, msg}
371371
end
372372
else
373-
Logger.info("No download: #{model.name}")
373+
Logger.info("ℹ️ No download needed: #{model.name}")
374374
:ok
375375
end
376376
end

lib/app_web/live/page_live.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ defmodule AppWeb.PageLive do
200200

201201
# Otherwise, if there was an error uploading the image, we log the error and show it to the person.
202202
%{error: errors} ->
203-
Logger.warning("Error uploading image. #{inspect(errors)}")
203+
Logger.warning("⚠️ Error uploading image. #{inspect(errors)}")
204204
{:noreply, push_event(socket, "toast", %{message: "Image couldn't be uploaded to S3"})}
205205
end
206206
end
@@ -264,13 +264,13 @@ defmodule AppWeb.PageLive do
264264

265265
# If S3 upload fails, we return error
266266
{:error, reason} ->
267-
Logger.warning("Error uploading image: #{inspect(reason)}")
267+
Logger.warning("⚠️ Error uploading image: #{inspect(reason)}")
268268
{:postpone, %{error: "Bucket error"}}
269269
end
270270
end
271271

272272
def handle_upload({:error, error}) do
273-
Logger.warning("Error creating partial image: #{inspect(error)}")
273+
Logger.warning("⚠️ Error creating partial image: #{inspect(error)}")
274274
{:postpone, %{error: "Error creating partial image"}}
275275
end
276276

@@ -496,7 +496,7 @@ defmodule AppWeb.PageLive do
496496
|> Map.merge(%{url: url})
497497
else
498498
{_, {:error, msg}} ->
499-
:ok = Logger.warning(inspect(msg))
499+
:ok = Logger.error("⚠️ #{msg}")
500500
end
501501
end
502502

0 commit comments

Comments
 (0)