1%% This Source Code Form is subject to the terms of the Mozilla Public
2%% License, v. 2.0. If a copy of the MPL was not distributed with this
3%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4%%
5%% Copyright (c) 2007-2021 VMware, Inc. or its affiliates.  All rights reserved.
6%%
7
8-module(rabbit_log).
9
10-export([log/3, log/4]).
11-export([debug/1, debug/2, debug/3,
12         info/1, info/2, info/3,
13         notice/1, notice/2, notice/3,
14         warning/1, warning/2, warning/3,
15         error/1, error/2, error/3,
16         critical/1, critical/2, critical/3,
17         alert/1, alert/2, alert/3,
18         emergency/1, emergency/2, emergency/3,
19         none/1, none/2, none/3]).
20
21-include("logging.hrl").
22
23-compile({no_auto_import, [error/2, error/3]}).
24
25%%----------------------------------------------------------------------------
26
27-type category() :: atom().
28
29-spec debug(string()) -> 'ok'.
30-spec debug(string(), [any()]) -> 'ok'.
31-spec debug(pid() | [tuple()], string(), [any()]) -> 'ok'.
32-spec info(string()) -> 'ok'.
33-spec info(string(), [any()]) -> 'ok'.
34-spec info(pid() | [tuple()], string(), [any()]) -> 'ok'.
35-spec notice(string()) -> 'ok'.
36-spec notice(string(), [any()]) -> 'ok'.
37-spec notice(pid() | [tuple()], string(), [any()]) -> 'ok'.
38-spec warning(string()) -> 'ok'.
39-spec warning(string(), [any()]) -> 'ok'.
40-spec warning(pid() | [tuple()], string(), [any()]) -> 'ok'.
41-spec error(string()) -> 'ok'.
42-spec error(string(), [any()]) -> 'ok'.
43-spec error(pid() | [tuple()], string(), [any()]) -> 'ok'.
44-spec critical(string()) -> 'ok'.
45-spec critical(string(), [any()]) -> 'ok'.
46-spec critical(pid() | [tuple()], string(), [any()]) -> 'ok'.
47-spec alert(string()) -> 'ok'.
48-spec alert(string(), [any()]) -> 'ok'.
49-spec alert(pid() | [tuple()], string(), [any()]) -> 'ok'.
50-spec emergency(string()) -> 'ok'.
51-spec emergency(string(), [any()]) -> 'ok'.
52-spec emergency(pid() | [tuple()], string(), [any()]) -> 'ok'.
53-spec none(string()) -> 'ok'.
54-spec none(string(), [any()]) -> 'ok'.
55-spec none(pid() | [tuple()], string(), [any()]) -> 'ok'.
56
57%%----------------------------------------------------------------------------
58
59-spec log(category(), logger:level(), string()) -> 'ok'.
60log(Category, Level, Fmt) -> log(Category, Level, Fmt, []).
61
62-spec log(category(), logger:level(), string(), [any()]) -> 'ok'.
63log(default, Level, Fmt, Args) when is_list(Args) ->
64    logger:log(Level, Fmt, Args, #{domain => ?RMQLOG_DOMAIN_GLOBAL});
65log(Category, Level, Fmt, Args) when is_list(Args) ->
66    logger:log(Level, Fmt, Args, #{domain => ?DEFINE_RMQLOG_DOMAIN(Category)}).
67
68debug(Format) -> debug(Format, []).
69debug(Format, Args) -> debug(self(), Format, Args).
70debug(Pid, Format, Args) ->
71    logger:debug(Format, Args, #{pid => Pid,
72                                 domain => ?RMQLOG_DOMAIN_GLOBAL}).
73
74info(Format) -> info(Format, []).
75info(Format, Args) -> info(self(), Format, Args).
76info(Pid, Format, Args) ->
77    logger:info(Format, Args, #{pid => Pid,
78                                domain => ?RMQLOG_DOMAIN_GLOBAL}).
79
80notice(Format) -> notice(Format, []).
81notice(Format, Args) -> notice(self(), Format, Args).
82notice(Pid, Format, Args) ->
83    logger:notice(Format, Args, #{pid => Pid,
84                                  domain => ?RMQLOG_DOMAIN_GLOBAL}).
85
86warning(Format) -> warning(Format, []).
87warning(Format, Args) -> warning(self(), Format, Args).
88warning(Pid, Format, Args) ->
89    logger:warning(Format, Args, #{pid => Pid,
90                                   domain => ?RMQLOG_DOMAIN_GLOBAL}).
91
92error(Format) -> error(Format, []).
93error(Format, Args) -> error(self(), Format, Args).
94error(Pid, Format, Args) ->
95    logger:error(Format, Args, #{pid => Pid,
96                                 domain => ?RMQLOG_DOMAIN_GLOBAL}).
97
98critical(Format) -> critical(Format, []).
99critical(Format, Args) -> critical(self(), Format, Args).
100critical(Pid, Format, Args) ->
101    logger:critical(Format, Args, #{pid => Pid,
102                                    domain => ?RMQLOG_DOMAIN_GLOBAL}).
103
104alert(Format) -> alert(Format, []).
105alert(Format, Args) -> alert(self(), Format, Args).
106alert(Pid, Format, Args) ->
107    logger:alert(Format, Args, #{pid => Pid,
108                                 domain => ?RMQLOG_DOMAIN_GLOBAL}).
109
110emergency(Format) -> emergency(Format, []).
111emergency(Format, Args) -> emergency(self(), Format, Args).
112emergency(Pid, Format, Args) ->
113    logger:emergency(Format, Args, #{pid => Pid,
114                                     domain => ?RMQLOG_DOMAIN_GLOBAL}).
115
116none(_Format) -> ok.
117none(_Format, _Args) -> ok.
118none(_Pid, _Format, _Args) -> ok.
119