Skip to content

Commit 8fed766

Browse files
committed
Re-introduce rabbit_log for backwards compatibility
Some community plugins use rabbit_log. To simplify the transition, we can keep this module as a simple wrapper on logger macros.
1 parent 108a39f commit 8fed766

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

deps/rabbit_common/src/rabbit_log.erl

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 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+
-include_lib("kernel/include/logger.hrl").
23+
24+
-compile({no_auto_import, [error/2, error/3]}).
25+
26+
%%----------------------------------------------------------------------------
27+
%% This module is deprecated and only here for backwards compatibility.
28+
%% New code should use Erlang logger directly, usually through ?LOG_* macros.
29+
%%----------------------------------------------------------------------------
30+
31+
-deprecated({log, 3, "Use logger:log/3 instead"}).
32+
-deprecated({log, 4, "Use logger:log/4 instead"}).
33+
34+
-deprecated({debug, 1, "Use ?LOG_DEBUG instead"}).
35+
-deprecated({debug, 2, "Use ?LOG_DEBUG instead"}).
36+
-deprecated({debug, 3, "Use ?LOG_DEBUG instead"}).
37+
38+
-deprecated({info, 1, "Use ?LOG_INFO instead"}).
39+
-deprecated({info, 2, "Use ?LOG_INFO instead"}).
40+
-deprecated({info, 3, "Use ?LOG_INFO instead"}).
41+
42+
-deprecated({notice, 1, "Use ?LOG_NOTICE instead"}).
43+
-deprecated({notice, 2, "Use ?LOG_NOTICE instead"}).
44+
-deprecated({notice, 3, "Use ?LOG_NOTICE instead"}).
45+
46+
-deprecated({warning, 1, "Use ?LOG_WARNING instead"}).
47+
-deprecated({warning, 2, "Use ?LOG_WARNING instead"}).
48+
-deprecated({warning, 3, "Use ?LOG_WARNING instead"}).
49+
50+
-deprecated({error, 1, "Use ?LOG_ERROR instead"}).
51+
-deprecated({error, 2, "Use ?LOG_ERROR instead"}).
52+
-deprecated({error, 3, "Use ?LOG_ERROR instead"}).
53+
54+
-deprecated({critical, 1, "Use ?LOG_CRITICAL instead"}).
55+
-deprecated({critical, 2, "Use ?LOG_CRITICAL instead"}).
56+
-deprecated({critical, 3, "Use ?LOG_CRITICAL instead"}).
57+
58+
-deprecated({emergency, 1, "Use ?LOG_EMERGENCY instead"}).
59+
-deprecated({emergency, 2, "Use ?LOG_EMERGENCY instead"}).
60+
-deprecated({emergency, 3, "Use ?LOG_EMERGENCY instead"}).
61+
62+
-deprecated({none, 1, "Deprecated"}).
63+
-deprecated({none, 2, "Deprecated"}).
64+
-deprecated({none, 3, "Deprecated"}).
65+
66+
%%----------------------------------------------------------------------------
67+
68+
-type category() :: atom().
69+
70+
-spec debug(string()) -> 'ok'.
71+
-spec debug(string(), [any()]) -> 'ok'.
72+
-spec debug(pid() | [tuple()], string(), [any()]) -> 'ok'.
73+
-spec info(string()) -> 'ok'.
74+
-spec info(string(), [any()]) -> 'ok'.
75+
-spec info(pid() | [tuple()], string(), [any()]) -> 'ok'.
76+
-spec notice(string()) -> 'ok'.
77+
-spec notice(string(), [any()]) -> 'ok'.
78+
-spec notice(pid() | [tuple()], string(), [any()]) -> 'ok'.
79+
-spec warning(string()) -> 'ok'.
80+
-spec warning(string(), [any()]) -> 'ok'.
81+
-spec warning(pid() | [tuple()], string(), [any()]) -> 'ok'.
82+
-spec error(string()) -> 'ok'.
83+
-spec error(string(), [any()]) -> 'ok'.
84+
-spec error(pid() | [tuple()], string(), [any()]) -> 'ok'.
85+
-spec critical(string()) -> 'ok'.
86+
-spec critical(string(), [any()]) -> 'ok'.
87+
-spec critical(pid() | [tuple()], string(), [any()]) -> 'ok'.
88+
-spec alert(string()) -> 'ok'.
89+
-spec alert(string(), [any()]) -> 'ok'.
90+
-spec alert(pid() | [tuple()], string(), [any()]) -> 'ok'.
91+
-spec emergency(string()) -> 'ok'.
92+
-spec emergency(string(), [any()]) -> 'ok'.
93+
-spec emergency(pid() | [tuple()], string(), [any()]) -> 'ok'.
94+
-spec none(string()) -> 'ok'.
95+
-spec none(string(), [any()]) -> 'ok'.
96+
-spec none(pid() | [tuple()], string(), [any()]) -> 'ok'.
97+
98+
%%----------------------------------------------------------------------------
99+
100+
-spec log(category(), logger:level(), string()) -> 'ok'.
101+
log(Category, Level, Fmt) -> log(Category, Level, Fmt, []).
102+
103+
-spec log(category(), logger:level(), string(), [any()]) -> 'ok'.
104+
log(default, Level, Fmt, Args) when is_list(Args) ->
105+
logger:log(Level, Fmt, Args, #{domain => ?RMQLOG_DOMAIN_GLOBAL});
106+
log(Category, Level, Fmt, Args) when is_list(Args) ->
107+
logger:log(Level, Fmt, Args, #{domain => ?DEFINE_RMQLOG_DOMAIN(Category)}).
108+
109+
debug(Format) -> debug(Format, []).
110+
debug(Format, Args) -> debug(self(), Format, Args).
111+
debug(Pid, Format, Args) ->
112+
?LOG_DEBUG(Format, Args, #{pid => Pid,
113+
domain => ?RMQLOG_DOMAIN_GLOBAL}).
114+
115+
info(Format) -> info(Format, []).
116+
info(Format, Args) -> info(self(), Format, Args).
117+
info(Pid, Format, Args) ->
118+
?LOG_INFO(Format, Args, #{pid => Pid,
119+
domain => ?RMQLOG_DOMAIN_GLOBAL}).
120+
121+
notice(Format) -> notice(Format, []).
122+
notice(Format, Args) -> notice(self(), Format, Args).
123+
notice(Pid, Format, Args) ->
124+
?LOG_NOTICE(Format, Args, #{pid => Pid,
125+
domain => ?RMQLOG_DOMAIN_GLOBAL}).
126+
127+
warning(Format) -> warning(Format, []).
128+
warning(Format, Args) -> warning(self(), Format, Args).
129+
warning(Pid, Format, Args) ->
130+
?LOG_WARNING(Format, Args, #{pid => Pid,
131+
domain => ?RMQLOG_DOMAIN_GLOBAL}).
132+
133+
error(Format) -> error(Format, []).
134+
error(Format, Args) -> error(self(), Format, Args).
135+
error(Pid, Format, Args) ->
136+
?LOG_ERROR(Format, Args, #{pid => Pid,
137+
domain => ?RMQLOG_DOMAIN_GLOBAL}).
138+
139+
critical(Format) -> critical(Format, []).
140+
critical(Format, Args) -> critical(self(), Format, Args).
141+
critical(Pid, Format, Args) ->
142+
?LOG_CRITICAL(Format, Args, #{pid => Pid,
143+
domain => ?RMQLOG_DOMAIN_GLOBAL}).
144+
145+
alert(Format) -> alert(Format, []).
146+
alert(Format, Args) -> alert(self(), Format, Args).
147+
alert(Pid, Format, Args) ->
148+
?LOG_ALERT(Format, Args, #{pid => Pid,
149+
domain => ?RMQLOG_DOMAIN_GLOBAL}).
150+
151+
emergency(Format) -> emergency(Format, []).
152+
emergency(Format, Args) -> emergency(self(), Format, Args).
153+
emergency(Pid, Format, Args) ->
154+
?LOG_EMERGENCY(Format, Args, #{pid => Pid,
155+
domain => ?RMQLOG_DOMAIN_GLOBAL}).
156+
157+
none(_Format) -> ok.
158+
none(_Format, _Args) -> ok.
159+
none(_Pid, _Format, _Args) -> ok.

0 commit comments

Comments
 (0)