PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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