You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2023/03/29 20:28:02 UTC

[couchdb] branch add-report-logging updated: Use bad formatting

This is an automated email from the ASF dual-hosted git repository.

chewbranca pushed a commit to branch add-report-logging
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/add-report-logging by this push:
     new 6c7f27097 Use bad formatting
6c7f27097 is described below

commit 6c7f27097c782b752172f8d505a11a7f2ebc705f
Author: Russell Branca <ch...@apache.org>
AuthorDate: Wed Mar 29 13:27:40 2023 -0700

    Use bad formatting
---
 src/couch_log/src/couch_log.erl                    | 13 ++++++-----
 src/couch_log/src/couch_log_formatter.erl          | 26 ++++++++++++++--------
 src/couch_log/src/couch_log_util.erl               |  2 +-
 src/couch_log/src/couch_log_writer_stderr.erl      |  2 +-
 .../test/eunit/couch_log_writer_syslog_test.erl    |  2 --
 src/mango/src/mango_execution_stats.erl            | 19 ++++++++--------
 6 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/src/couch_log/src/couch_log.erl b/src/couch_log/src/couch_log.erl
index 961569d9d..8b299e8b4 100644
--- a/src/couch_log/src/couch_log.erl
+++ b/src/couch_log/src/couch_log.erl
@@ -51,12 +51,13 @@ emergency(Fmt, Args) -> log(emergency, Fmt, Args).
 
 -spec report(string(), map()) -> true | false.
 report(ReportId, Meta0) when is_map(Meta0) ->
-    Meta = case maps:is_key(type, Meta0) of
-        true ->
-            Meta0;
-        false ->
-            Meta0#{type => ReportId}
-    end,
+    Meta =
+        case maps:is_key(type, Meta0) of
+            true ->
+                Meta0;
+            false ->
+                Meta0#{type => ReportId}
+        end,
     couch_stats:increment_counter([couch_log, level, report]),
     case couch_log_formatter:format_report(self(), ReportId, Meta) of
         {error, emsgtoolong} ->
diff --git a/src/couch_log/src/couch_log_formatter.erl b/src/couch_log/src/couch_log_formatter.erl
index 03c2a530e..a1c289533 100644
--- a/src/couch_log/src/couch_log_formatter.erl
+++ b/src/couch_log/src/couch_log_formatter.erl
@@ -37,12 +37,13 @@
 
 format_report(Pid, Type, Meta) ->
     MaxMsgSize = couch_log_config:get(max_message_size),
-    Msg = case format_meta(Meta) of
-        "" ->
-            "";
-        MetaStr ->
-            ["[", MetaStr, "]"]
-    end,
+    Msg =
+        case format_meta(Meta) of
+            "" ->
+                "";
+            MetaStr ->
+                ["[", MetaStr, "]"]
+        end,
     case length(Msg) > MaxMsgSize of
         true ->
             {error, emsgtoolong};
@@ -467,9 +468,16 @@ supervisor_name(Name) -> Name.
 format_meta(Meta) ->
     %% https://www.rfc-editor.org/rfc/rfc5424.html#section-6.3
     %% iut="3" eventSource="Application" eventID="1011"
-    string:join(maps:fold(fun(K, V, Acc) ->
-        [to_str(K, V) | Acc]
-    end, [], Meta), " ").
+    string:join(
+        maps:fold(
+            fun(K, V, Acc) ->
+                [to_str(K, V) | Acc]
+            end,
+            [],
+            Meta
+        ),
+        " "
+    ).
 
 %% passing complex terms as meta value is a mistake so we are going
 %% to eat it, because we cannot bubble up errors from logger
diff --git a/src/couch_log/src/couch_log_util.erl b/src/couch_log/src/couch_log_util.erl
index 4773ca46c..03af8e695 100644
--- a/src/couch_log/src/couch_log_util.erl
+++ b/src/couch_log/src/couch_log_util.erl
@@ -154,7 +154,7 @@ maybe_format_type(#log_entry{type = undefined} = Entry) ->
     Entry;
 maybe_format_type(#log_entry{type = Type, msg = [$[ | Msg]} = Entry) ->
     Entry#log_entry{msg = ["[", Type, " " | Msg]};
-maybe_format_type(#log_entry{type = Type, msg = [_|_]=Msg} = Entry) ->
+maybe_format_type(#log_entry{type = Type, msg = [_ | _] = Msg} = Entry) ->
     Entry#log_entry{msg = [Type, " " | Msg]};
 maybe_format_type(#log_entry{} = Entry) ->
     Entry.
diff --git a/src/couch_log/src/couch_log_writer_stderr.erl b/src/couch_log/src/couch_log_writer_stderr.erl
index 50aaaed9f..5c2c761fa 100644
--- a/src/couch_log/src/couch_log_writer_stderr.erl
+++ b/src/couch_log/src/couch_log_writer_stderr.erl
@@ -27,7 +27,7 @@ init() ->
 terminate(_, _St) ->
     ok.
 
-write(#log_entry{type=Type}=Entry, St) ->
+write(#log_entry{type = Type} = Entry, St) ->
     #log_entry{
         level = Level,
         pid = Pid,
diff --git a/src/couch_log/test/eunit/couch_log_writer_syslog_test.erl b/src/couch_log/test/eunit/couch_log_writer_syslog_test.erl
index bfac2bc92..8401a4ac4 100644
--- a/src/couch_log/test/eunit/couch_log_writer_syslog_test.erl
+++ b/src/couch_log/test/eunit/couch_log_writer_syslog_test.erl
@@ -121,8 +121,6 @@ check_format() ->
     ?assert(meck:called(gen_udp, close, 1)),
     ?assert(meck:validate(gen_udp)).
 
-
-
 facility_test() ->
     Names = [
         "kern",
diff --git a/src/mango/src/mango_execution_stats.erl b/src/mango/src/mango_execution_stats.erl
index 746cc4835..66104e89e 100644
--- a/src/mango/src/mango_execution_stats.erl
+++ b/src/mango/src/mango_execution_stats.erl
@@ -89,15 +89,16 @@ maybe_add_stats(Opts, UserFun, Stats0, UserAcc) ->
     %% TODO: add docs vs quorum docs
     chttpd_stats:incr_reads(Stats1#execution_stats.totalDocsExamined),
 
-    FinalAcc = case couch_util:get_value(execution_stats, Opts) of
-        true ->
-            JSONValue = to_json(Stats1),
-            Arg = {add_key, execution_stats, JSONValue},
-            {_Go, FinalUserAcc} = UserFun(Arg, UserAcc),
-            FinalUserAcc;
-        _ ->
-            UserAcc
-    end,
+    FinalAcc =
+        case couch_util:get_value(execution_stats, Opts) of
+            true ->
+                JSONValue = to_json(Stats1),
+                Arg = {add_key, execution_stats, JSONValue},
+                {_Go, FinalUserAcc} = UserFun(Arg, UserAcc),
+                FinalUserAcc;
+            _ ->
+                UserAcc
+        end,
     {FinalAcc, Stats1}.
 
 log_stats(Stats) ->