@@ -4,7 +4,8 @@ defmodule LoggerTelegramBackendTest do
44 require Logger
55
66 setup_all do
7- Logger . remove_backend ( :console )
7+ :ok = Logger . configure ( truncate: :infinity )
8+ :ok = Logger . remove_backend ( :console )
89 end
910
1011 test "logs the message to the specified sender" do
@@ -32,14 +33,52 @@ defmodule LoggerTelegramBackendTest do
3233 }
3334 end
3435
36+ test "shortens the message if necessary" do
37+ :ok = configure ( metadata: [ :function , :module ] )
38+
39+ message = List . duplicate ( "E" , 9999 ) |> to_string
40+ Logger . info ( message )
41+ assert_receive { :text , log }
42+
43+ assert log ==
44+ """
45+ <b>[info]</b> <b>#{ List . duplicate ( "E" , 4000 ) } ...</b>
46+ <pre>Function: \" test shortens the message if necessary/1\"
47+ Module: LoggerTelegramBackendTest</pre>
48+ """
49+ |> String . trim_trailing ( )
50+ end
51+
52+ test "shortens the message based on its graphemes not bytes" do
53+ :ok = configure ( metadata: [ ] )
54+
55+ for grapheme <- [ "A" , "é" , "💜" ] do
56+ message = List . duplicate ( grapheme , 9999 ) |> to_string
57+ Logger . info ( message )
58+
59+ assert_receive { :text , log }
60+ assert log == "<b>[info]</b> <b>#{ List . duplicate ( grapheme , 4086 ) } ...</b>\n <pre></pre>"
61+ end
62+ end
63+
64+ test "shortens the message and escapes special chars afterwards" do
65+ :ok = configure ( metadata: [ ] )
66+
67+ message = List . duplicate ( "&" , 9999 ) |> to_string
68+ Logger . info ( message )
69+
70+ assert_receive { :text , log }
71+ assert log == "<b>[info]</b> <b>#{ List . duplicate ( "&" , 4086 ) } ...</b>\n <pre></pre>"
72+ end
73+
3574 test "escapes special chars" do
3675 :ok = configure ( metadata: [ ] )
3776
3877 Logger . info ( "<>&" )
3978 Logger . info ( "<code>FOO</code>" )
4079
41- assert_receive { :text , "<b>[info]</b> <b><>&</b>\n <pre></pre>\n " }
42- assert_receive { :text , "<b>[info]</b> <b><code>FOO</code></b>\n <pre></pre>\n " }
80+ assert_receive { :text , "<b>[info]</b> <b><>&</b>\n <pre></pre>" }
81+ assert_receive { :text , "<b>[info]</b> <b><code>FOO</code></b>\n <pre></pre>" }
4382 end
4483
4584 test "logs multiple message smoothly" do
0 commit comments