Skip to content

Commit

Permalink
add dgiot log save to parse
Browse files Browse the repository at this point in the history
  • Loading branch information
lsxredrain committed Aug 26, 2021
1 parent adcf6da commit ed0371a
Show file tree
Hide file tree
Showing 19 changed files with 16,862 additions and 77 deletions.
59 changes: 34 additions & 25 deletions apps/dgiot/include/logger.hrl
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------

%% debug | info | notice | warning | error | critical | alert | emergency

-compile({parse_transform, emqx_logger}).

-define(DEBUG(Format), ?LOG(debug, Format, [])).
Expand All @@ -42,10 +24,37 @@
-define(LOG(Level, Format), ?LOG(Level, Format, [])).

-define(LOG(Level, Format, Args),
begin
(logger:log(Level,#{},#{report_cb => fun(_) ->
{'$logger_header'() ++ (Format), ( Args)} end,
mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY},
line => ?LINE}))
end).

begin
(logger:log(Level, #{}, #{
report_cb => fun(_) -> {'$logger_header'() ++ (Format), (Args)} end,
domain => [public_dgiot],
mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY},
line => ?LINE}))
end).

-define(LOG(Level, Format, Args, ACL),
begin
(logger:log(Level, #{}, #{
report_cb => fun(_) -> {'$logger_header'() ++ (Format), (Args)} end,
domain => ACL,
mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY},
line => ?LINE}))
end).

-define(MLOG(Level, Map),
begin
(logger:log(Level, Map, #{
report_cb => fun(_) -> Map end,
domain => [publiclog],
mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY},
line => ?LINE}))
end).

-define(MLOG(Level, Map, ACL),
begin
(logger:log(Level, Map, #{
report_cb => fun(_) -> Map end,
domain => ACL,
mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY},
line => ?LINE}))
end).
9 changes: 8 additions & 1 deletion apps/dgiot/src/otp/dgiot_logger.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

-module(dgiot_logger).
-author("johnliu").
-include_lib("dgiot/include/logger.hrl").

-export([test/0]).
%% Logs
-export([ debug/1
-export([debug/1
, debug/2
, debug/3
, info/1
Expand All @@ -35,6 +37,10 @@
, critical/3
]).

test() ->
Test = <<"test">>,
?MLOG(info, #{<<"test">> => Test}),
?MLOG(info, #{<<"test">> => Test},['acl_test']).

%%--------------------------------------------------------------------
%% APIs
Expand Down Expand Up @@ -100,3 +106,4 @@ critical(Format, Args) ->
-spec(critical(logger:metadata(), io:format(), [term()]) -> ok).
critical(Metadata, Format, Args) when is_map(Metadata) ->
logger:critical(Format, Args, Metadata).

1 change: 1 addition & 0 deletions apps/dgiot/src/storage/dgiot_cache_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ stop(NameOrPid) ->
%%%===================================================================

init(Opts) ->
?LOG(info,"Opts ~p",[Opts]),
MaxSize = proplists:get_value(ets_maxsize, Opts, 8 * 1024 * 1024),
Threshold = proplists:get_value(ets_threshold, Opts, 0.85),
CheckPid = proplists:get_value(checkpid, Opts),
Expand Down
1 change: 0 additions & 1 deletion apps/dgiot_ffmpeg/src/dgiot_ffmpeg_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
-emqx_plugin(?MODULE).
-behaviour(application).

-include("dgiot_ffmpeg.hrl").

%% Application callbacks
-export([start/2, stop/1]).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def OnProviderLoaded(self, request, context):
exhook_pb2.HookSpec(name="session.takeovered"),
exhook_pb2.HookSpec(name="session.terminated"),

exhook_pb2.HookSpec(name="message.publish"),
exhook_pb2.HookSpec(name="message.publish",topics = ["test"]),
exhook_pb2.HookSpec(name="message.delivered"),
exhook_pb2.HookSpec(name="message.acked"),
exhook_pb2.HookSpec(name="message.dropped")
Expand Down
Loading

0 comments on commit ed0371a

Please sign in to comment.