Skip to content

Commit

Permalink
BrowserLogger: Use Console API functions for logs without data
Browse files Browse the repository at this point in the history
The Console API of browsers offer several functions for logs of
different severity levels, like error, warn, info, debug. This change
uses these functions instead of groupCollapsed for simple logs without data.
This allows to filter for logs in the browser console and allows the
browser to automatically group repeating logs.

Fixes: shakacode#17, shakacode#18

Signed-off-by: Sven Anderson <[email protected]>
  • Loading branch information
ansiwen committed Jul 15, 2020
1 parent 3b6f615 commit 66c8625
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/BrowserLogger.re
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ external debugGroup:
"group";

[@bs.val] [@bs.scope "console"]
external debugGroupCollapsed:
external debugJs:
(
[@bs.as "%c DEBUG "] _,
[@bs.as "background: #82658c; color: #fff;"] _,
'a,
'b
) =>
unit =
"groupCollapsed";
"debug";

let debug = (__module__: string, event: 'a) => {
__module__->Module.format->debugGroupCollapsed(event);
groupEnd();
__module__->Module.format->debugJs(event);
};

let debugWithData =
Expand Down Expand Up @@ -162,19 +161,18 @@ external infoGroup:
"group";

[@bs.val] [@bs.scope "console"]
external infoGroupCollapsed:
external infoJs:
(
[@bs.as "%c INFO "] _,
[@bs.as "background: #29d; color: #fff;"] _,
'a,
'b
) =>
unit =
"groupCollapsed";
"info";

let info = (__module__: string, event: 'a) => {
__module__->Module.format->infoGroupCollapsed(event);
groupEnd();
__module__->Module.format->infoJs(event);
};

let infoWithData =
Expand Down Expand Up @@ -305,19 +303,18 @@ external warnGroup:
"group";

[@bs.val] [@bs.scope "console"]
external warnGroupCollapsed:
external warnJs:
(
[@bs.as "%c WARNING "] _,
[@bs.as "background: #fce473; color: #573a08;"] _,
'a,
'b
) =>
unit =
"groupCollapsed";
"warn";

let warn = (__module__: string, event: 'a) => {
__module__->Module.format->warnGroupCollapsed(event);
groupEnd();
__module__->Module.format->warnJs(event);
};

let warnWithData =
Expand Down Expand Up @@ -448,19 +445,18 @@ external errorGroup:
"group";

[@bs.val] [@bs.scope "console"]
external errorGroupCollapsed:
external errorJs:
(
[@bs.as "%c ERROR "] _,
[@bs.as "background: #d11a1a; color: #fff;"] _,
'a,
'b
) =>
unit =
"groupCollapsed";
"error";

let error = (__module__: string, event: 'a) => {
__module__->Module.format->errorGroupCollapsed(event);
groupEnd();
__module__->Module.format->errorJs(event);
};

let errorWithData =
Expand Down

0 comments on commit 66c8625

Please sign in to comment.