Skip to content

Commit

Permalink
ci: log
Browse files Browse the repository at this point in the history
  • Loading branch information
AvantLiu committed Sep 23, 2021
1 parent 807d64a commit 64290bf
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion apps/dgiot/src/channel/dgiot_channelx.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ do_event(ChannelType, ChannelId, EventId, Event, Timeout) ->
fun(Worker) ->
Worker ! {event, Pool, EventId, Event}, ok
end,
?LOG(error, "EventId ~p", [EventId]),
%% ?LOG(error, "EventId ~p", [EventId]),
poolboy:transaction(Pool, Fun, Timeout).

do_message(ChannelId, Message) ->
Expand Down
2 changes: 1 addition & 1 deletion apps/dgiot_device/src/dgiot_device.erl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ sync_parse(OffLine) ->
<<"">>
end,
?MLOG(info, #{<<"clientid">> => DeviceId, <<"devaddr">> => Devaddr, <<"productid">> => ProductId, <<"productname">> => Productname, <<"devicename">> => DeviceName, <<"status">> => <<"下线"/utf8>>}, ['device_statuslog']),
dgiot_umeng:save_devicestatus(DeviceId, <<"OFFLINE">>),
%% dgiot_umeng:sasve_devicestatus(DeviceId, <<"OFFLINE">>),
dgiot_mnesia:insert(DeviceId, {[false, Last, Acl, DeviceName, Devaddr, ProductId], Node});
_ ->
pass
Expand Down
2 changes: 1 addition & 1 deletion apps/dgiot_ffmpeg/src/dgiot_ffmpeg_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
-channel_type(#{

cType => ?TYPE,
type => ?BRIDGE_CHL,
type => ?PROTOCOL_CHL,
title => #{
zh => <<"视频采集资源通道"/utf8>>
},
Expand Down
4 changes: 0 additions & 4 deletions apps/dgiot_shouyincheng/src/dgiot_shouyincheng_tcp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,8 @@ handle_info({tcp, Buff}, #tcp{socket = Socket, state = #state{id = ChannelId, de
%% 3D302E30303030203D302E303030303530303138200D0A
handle_info({tcp, Buff}, #tcp{state = #state{id = ChannelId, devaddr = DevAddr, product = ProductId} = State} = TCPState) ->
dgiot_bridge:send_log(ChannelId, "revice from ~p", [Buff]),
?LOG(info, "revice from ~p~n", [Buff]),
?LOG(info, "Devaddr ~p~n", [DevAddr]),
?LOG(info, "DtuProductId ~p~n", [ProductId]),
case dgiot_shouyincheng:parse_frame(Buff, State) of
{params, Data} ->
?LOG(info, "Data ~p~n", [Data]),
dgiot_tdengine_adapter:save(ProductId, DevAddr, Data);
_ ->
pass
Expand Down
2 changes: 1 addition & 1 deletion apps/dgiot_task/src/dgiot_task_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
-channel_type(#{

cType => ?TYPE,
type => ?BACKEND_CHL,
type => ?BRIDGE_CHL,
title => #{
zh => <<"指令任务通道"/utf8>>
},
Expand Down
2 changes: 1 addition & 1 deletion apps/dgiot_tdengine/src/dgiot_tdengine_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ save_to_tdengine(_, []) -> ok;
save_to_tdengine(Channel, Requests) ->
case dgiot_tdengine:batch(Channel, Requests) of
{ok, _Results} ->
?LOG(info, "Batch ~p-> ~p~n", [length(Requests), _Results]),
%% ?LOG(info, "Batch ~p-> ~p~n", [length(Requests), _Results]),
ok;
{error, Reason} when Reason == timeout; Reason == disconnect ->
?LOG(error, "save cache,~p,~p~n", [Requests, Reason]),
Expand Down
2 changes: 1 addition & 1 deletion apps/dgiot_topo/src/dgiot_topo_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
%% 注册通道类型
-channel_type(#{
cType => ?TYPE,
type => ?BACKEND_CHL,
type => ?PROTOCOL_CHL,
title => #{
zh => <<"TOPO组态通道"/utf8>>
},
Expand Down
72 changes: 38 additions & 34 deletions src/emqx_tracer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@
-logger_header("[Tracer]").

%% APIs
-export([ trace/2
, start_trace/3
, lookup_traces/0
, stop_trace/1
]).
-export([trace/2
, start_trace/3
, lookup_traces/0
, stop_trace/1
]).

-type(trace_who() :: {clientid | topic, binary()}).

-define(TRACER, ?MODULE).
-define(FORMAT, {logger_formatter,
#{template =>
[time, " [", level, "] ",
{clientid,
[{peername,
[clientid, "@", peername, " "],
[clientid, " "]}],
[{peername,
[peername, " "],
[]}]},
msg, "\n"],
single_line => false
}}).
-define(TOPIC_TRACE_ID(T), "trace_topic_"++T).
-define(CLIENT_TRACE_ID(C), "trace_clientid_"++C).
#{template =>
[time, " [", level, "] ",
{clientid,
[{peername,
[clientid, "@", peername, " "],
[clientid, " "]}],
[{peername,
[peername, " "],
[]}]},
msg, "\n"],
single_line => false
}}).
-define(TOPIC_TRACE_ID(T), "trace_topic_" ++ T).
-define(CLIENT_TRACE_ID(C), "trace_clientid_" ++ C).
-define(TOPIC_TRACE(T), {topic, T}).
-define(CLIENT_TRACE(C), {clientid, C}).

-define(IS_LOG_LEVEL(L),
L =:= emergency orelse
L =:= emergency orelse
L =:= alert orelse
L =:= critical orelse
L =:= error orelse
Expand All @@ -71,10 +71,12 @@ trace(publish, #message{topic = <<"logger_trace", _/binary>>}) ->
%% Do not trace '$SYS' publish
ignore;
trace(publish, #message{from = From, topic = Topic, payload = Payload})
when is_binary(From); is_atom(From) ->
when is_binary(From); is_atom(From) ->
io:format("From ~p", From),
emqx_logger:info(#{topic => Topic,
mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY} },
"PUBLISH to ~s: ~0p", [Topic, Payload]).
mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY}},
"PUBLISH to ~s: ~0p ~p", [Topic, Payload, From]).

%% @doc Start to trace clientid or topic.
-spec(start_trace(trace_who(), logger:level() | all, string()) -> ok | {error, term()}).
start_trace(Who, all, LogFile) ->
Expand All @@ -86,14 +88,14 @@ start_trace(Who, Level, LogFile) ->
try logger:compare_levels(Level, PrimaryLevel) of
lt ->
{error,
io_lib:format("Cannot trace at a log level (~s) "
"lower than the primary log level (~s)",
[Level, PrimaryLevel])};
io_lib:format("Cannot trace at a log level (~s) "
"lower than the primary log level (~s)",
[Level, PrimaryLevel])};
_GtOrEq ->
install_trace_handler(Who, Level, LogFile)
catch
_:Error ->
{error, Error}
{error, Error}
end;
false -> {error, {invalid_log_level, Level}}
end.
Expand All @@ -109,13 +111,14 @@ lookup_traces() ->
lists:foldl(fun filter_traces/2, [], emqx_logger:get_log_handlers(started)).

install_trace_handler(Who, Level, LogFile) ->
io:format("Who1 ~p", Who),
case logger:add_handler(handler_id(Who), logger_disk_log_h,
#{level => Level,
formatter => ?FORMAT,
config => #{type => halt, file => LogFile},
filter_default => stop,
filters => [{meta_key_filter,
{fun filter_by_meta_key/2, Who}}]})
#{level => Level,
formatter => ?FORMAT,
config => #{type => halt, file => LogFile},
filter_default => stop,
filters => [{meta_key_filter,
{fun filter_by_meta_key/2, Who}}]})
of
ok ->
?LOG(info, "Start trace for ~p", [Who]);
Expand All @@ -125,6 +128,7 @@ install_trace_handler(Who, Level, LogFile) ->
end.

uninstall_trance_handler(Who) ->
io:format("Who2 ~p", Who),
case logger:remove_handler(handler_id(Who)) of
ok ->
?LOG(info, "Stop trace for ~p", [Who]);
Expand All @@ -135,7 +139,7 @@ uninstall_trance_handler(Who) ->

filter_traces(#{id := Id, level := Level, dst := Dst}, Acc) ->
case atom_to_list(Id) of
?TOPIC_TRACE_ID(T)->
?TOPIC_TRACE_ID(T) ->
[{?TOPIC_TRACE(T), {Level, Dst}} | Acc];
?CLIENT_TRACE_ID(C) ->
[{?CLIENT_TRACE(C), {Level, Dst}} | Acc];
Expand Down

0 comments on commit 64290bf

Please sign in to comment.