logger.hrl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2018-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. %% debug | info | notice | warning | error | critical | alert | emergency
  17. -compile({parse_transform, emqx_logger}).
  18. -define(DEBUG(Format), ?LOG(debug, Format, [])).
  19. -define(DEBUG(Format, Args), ?LOG(debug, Format, Args)).
  20. -define(INFO(Format), ?LOG(info, Format, [])).
  21. -define(INFO(Format, Args), ?LOG(info, Format, Args)).
  22. -define(NOTICE(Format), ?LOG(notice, Format, [])).
  23. -define(NOTICE(Format, Args), ?LOG(notice, Format, Args)).
  24. -define(WARN(Format), ?LOG(warning, Format, [])).
  25. -define(WARN(Format, Args), ?LOG(warning, Format, Args)).
  26. -define(ERROR(Format), ?LOG(error, Format, [])).
  27. -define(ERROR(Format, Args), ?LOG(error, Format, Args)).
  28. -define(CRITICAL(Format), ?LOG(critical, Format, [])).
  29. -define(CRITICAL(Format, Args), ?LOG(critical, Format, Args)).
  30. -define(ALERT(Format), ?LOG(alert, Format, [])).
  31. -define(ALERT(Format, Args), ?LOG(alert, Format, Args)).
  32. -define(LOG(Level, Format), ?LOG(Level, Format, [])).
  33. -define(LOG(Level, Format, Args),
  34. begin
  35. (logger:log(Level,#{},#{report_cb => fun(_) -> {'$logger_header'()++(Format), (Args)} end,
  36. mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY},
  37. line => ?LINE}))
  38. end).