/include/zotonic_log.hrl

http://github.com/zotonic/zotonic · Erlang · 81 lines · 45 code · 14 blank · 22 comment · 0 complexity · cad8ac3ea673567afe243e744630dfe3 MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2011 Marc Worrell
  3. %% @doc Log record definitions for zotonic
  4. %% Copyright 2011 Marc Worrell
  5. %%
  6. %% Licensed under the Apache License, Version 2.0 (the "License");
  7. %% you may not use this file except in compliance with the License.
  8. %% You may obtain a copy of the License at
  9. %%
  10. %% http://www.apache.org/licenses/LICENSE-2.0
  11. %%
  12. %% Unless required by applicable law or agreed to in writing, software
  13. %% distributed under the License is distributed on an "AS IS" BASIS,
  14. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. %% See the License for the specific language governing permissions and
  16. %% limitations under the License.
  17. -define(LOG_FATAL, 0).
  18. -define(LOG_ERROR, 1).
  19. -define(LOG_WARNING, 2).
  20. -define(LOG_INFO, 3).
  21. -define(LOG_DEBUG, 4).
  22. -record(log_message, {
  23. type = error,
  24. user_id,
  25. message,
  26. props = []
  27. }).
  28. -record(log_email, {
  29. severity = ?LOG_ERROR,
  30. message_nr,
  31. mailer_status, % sending, sent, error, retry, warning, bounce, received
  32. mailer_message, % any text, to clarify the mailer_status
  33. mailer_host, % SMTP server or client we are talking with
  34. envelop_to, % the 'to' on the envelop
  35. envelop_from, % the 'from' on the envelop
  36. to_id, % who is receiving the e-mail
  37. from_id, % who is sending (user in the #context)
  38. content_id, % The page being sent (if any)
  39. other_id, % In case of a mailinglist the mailinglist id
  40. message_template, % template used for rendering the e-mail (if any)
  41. props = [] % optional extra properties to be logged
  42. }).
  43. % NOTE: Make sure to extend record_to_proplist/1 in mod_logging.erl when adding log types.
  44. -record(zlog, {
  45. type = undefined :: atom(),
  46. user_id = undefined :: integer(),
  47. timestamp = undefined :: erlang:timestamp(),
  48. props = [] :: list() | #log_message{} | #log_email{}
  49. }).
  50. %% Below is copied (and adapted) from Nitrogen, which is copyright 2008-2009 Rusty Klophaus
  51. %%% LOGGING %%%
  52. %% Log notifications
  53. -define(zDebug(Msg, Context), z:debug(Msg, [{module, ?MODULE}, {line, ?LINE}], Context)).
  54. -define(zInfo(Msg, Context), z:info(Msg, [{module, ?MODULE}, {line, ?LINE}], Context)).
  55. -define(zWarning(Msg, Context), z:warning(Msg, [{module, ?MODULE}, {line, ?LINE}], Context)).
  56. -define(zError(Msg, Context), z:error(Msg, [{module, ?MODULE}, {line, ?LINE}], Context)).
  57. -define(zDebug(Msg, Args, Context), z:debug(Msg, Args, [{module, ?MODULE}, {line, ?LINE}], Context)).
  58. -define(zInfo(Msg, Args, Context), z:info(Msg, Args, [{module, ?MODULE}, {line, ?LINE}], Context)).
  59. -define(zWarning(Msg, Args, Context), z:warning(Msg, Args, [{module, ?MODULE}, {line, ?LINE}], Context)).
  60. -define(zError(Msg, Args, Context), z:error(Msg, Args, [{module, ?MODULE}, {line, ?LINE}], Context)).
  61. %% Easy to use macros for debugging/development
  62. -define(PRINT(Var), lager:info("DEBUG: ~p:~p - ~p: ~p~n", [?MODULE, ?LINE, ??Var, Var])).
  63. -define(STACKTRACE, erlang:display(try throw(a) of _ -> a catch _:_ -> erlang:get_stacktrace() end)).
  64. -define(DEBUG(Msg), z:debug_msg(?MODULE, ?LINE, Msg)).
  65. %% Deprecated shortcuts
  66. -define(LOG(Msg, Args), lager:info(Msg, Args)).
  67. -define(ERROR(Msg, Args), lager:error("~p:~p "++Msg, [?MODULE, ?LINE|Args])).