From 4b4246c1c5504e7b729d42240ddb33ce331f2743 Mon Sep 17 00:00:00 2001 From: "zhengyang226@outlook.com" Date: Thu, 20 Jul 2023 15:58:05 +0800 Subject: [PATCH] feat: new logger --- src/minirest.erl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/minirest.erl b/src/minirest.erl index a8308fc..44b2963 100644 --- a/src/minirest.erl +++ b/src/minirest.erl @@ -47,8 +47,19 @@ , handler/0 ]). reply(Code, Header,Body, Req) -> - io:format("Reply ~p ~0p~n ~0p~n ~0p~n", [Code, Header, Body, Req]), - cowboy_req:reply(Code, Header, Body, Req). + Res = cowboy_req:reply(Code, Header, Body, Req), + try persistent_term:get(minirest_logger, undefined) of + undefined -> + % ignore + ok; + {Module, Func} -> + erlang:apply(Module, Func, [Code, Header, Body, Req]); + Fun -> + Fun(Code, Header, Body, Req) + catch _:_ -> + ok + end, + Res. %%------------------------------------------------------------------------------ %% Start/Stop Http