Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rename LOG_ macros to PWS_LOG_ macros to avoid redefined macros

  • Loading branch information...
commit 4e35f593a77ffff5e917f106e3fd58fe923884bd 1 parent e2550a2
@gleber authored
View
2  examples/ws_loop.erl
@@ -71,7 +71,7 @@ loop(Socket, State) ->
%% Connect and handshake with Websocket.
-spec connect(ServerRef::pid(), Req::#req{}, Ws::#ws{}, WsLoop::function()) -> true.
connect(ServerRef, #req{headers = Headers} = Req, #ws{vsn = Vsn, socket = Socket, socket_mode = SocketMode, path = Path} = Ws, WsLoop) ->
- ?LOG_DEBUG("building handshake response", []),
+ ?PWS_LOG_DEBUG("building handshake response", []),
%% get data
Origin = proto_ws_utility:header_get_value('Origin', Headers),
Host = proto_ws_utility:header_get_value('Host', Headers),
View
32 include/proto_ws.hrl
@@ -29,28 +29,28 @@
%% ============================ \/ LOG ======================================================================
-ifdef(log_debug).
--define(LOG_DEBUG(Str, Args), erlang:apply(error_logger, info_msg, [lists:concat(["[DEBUG] pid: ", pid_to_list(self()), "~n module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
--define(LOG_INFO(Str, Args), erlang:apply(error_logger, info_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
--define(LOG_WARNING(Str, Args), erlang:apply(error_logger, warning_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
--define(LOG_ERROR(Str, Args), erlang:apply(error_logger, error_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
+-define(PWS_LOG_DEBUG(Str, Args), erlang:apply(error_logger, info_msg, [lists:concat(["[DEBUG] pid: ", pid_to_list(self()), "~n module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
+-define(PWS_LOG_INFO(Str, Args), erlang:apply(error_logger, info_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
+-define(PWS_LOG_WARNING(Str, Args), erlang:apply(error_logger, warning_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
+-define(PWS_LOG_ERROR(Str, Args), erlang:apply(error_logger, error_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
-else.
-ifdef(log_info).
--define(LOG_DEBUG(Str, Args), ok).
--define(LOG_INFO(Str, Args), erlang:apply(error_logger, info_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
--define(LOG_WARNING(Str, Args), erlang:apply(error_logger, warning_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
--define(LOG_ERROR(Str, Args), erlang:apply(error_logger, error_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
+-define(PWS_LOG_DEBUG(Str, Args), ok).
+-define(PWS_LOG_INFO(Str, Args), erlang:apply(error_logger, info_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
+-define(PWS_LOG_WARNING(Str, Args), erlang:apply(error_logger, warning_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
+-define(PWS_LOG_ERROR(Str, Args), erlang:apply(error_logger, error_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
-else.
-ifdef(log_error).
--define(LOG_DEBUG(Str, Args), ok).
--define(LOG_INFO(Str, Args), ok).
--define(LOG_WARNING(Str, Args), ok).
--define(LOG_ERROR(Str, Args), erlang:apply(error_logger, error_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
+-define(PWS_LOG_DEBUG(Str, Args), ok).
+-define(PWS_LOG_INFO(Str, Args), ok).
+-define(PWS_LOG_WARNING(Str, Args), ok).
+-define(PWS_LOG_ERROR(Str, Args), erlang:apply(error_logger, error_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
-else.
%% default to warning level
--define(LOG_DEBUG(Str, Args), ok).
--define(LOG_INFO(Str, Args), ok).
--define(LOG_WARNING(Str, Args), erlang:apply(error_logger, warning_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
--define(LOG_ERROR(Str, Args), erlang:apply(error_logger, error_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
+-define(PWS_LOG_DEBUG(Str, Args), ok).
+-define(PWS_LOG_INFO(Str, Args), ok).
+-define(PWS_LOG_WARNING(Str, Args), erlang:apply(error_logger, warning_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
+-define(PWS_LOG_ERROR(Str, Args), erlang:apply(error_logger, error_msg, [lists:concat([" module: ", ?MODULE, "~n line: ", ?LINE, "~n", Str, "~n"]), Args])).
-endif.
-endif.
-endif.
View
2  src/proto_ws.erl
@@ -167,7 +167,7 @@ check_headers(Headers, RequiredHeaders) ->
-spec check_websockets(VsnSupported::[websocket_version()], Headers::http_headers()) -> false | {true, Vsn::websocket_version()}.
check_websockets([], _Headers) -> false;
check_websockets([Vsn|T], Headers) ->
- ?LOG_DEBUG("testing for websocket protocol ~p", [Vsn]),
+ ?PWS_LOG_DEBUG("testing for websocket protocol ~p", [Vsn]),
VsnMod = get_module_name_from_vsn(Vsn),
case check_headers(Headers, VsnMod:required_headers()) of
true -> {true, Vsn, VsnMod};
View
20 src/proto_ws_draft-hybi-10_17.erl
@@ -235,18 +235,18 @@ take_frame(Data) when is_binary(Data), size(Data) >= ?MAX_UNPARSED_BUFFER_SIZE -
i_handle_data(#wstate{buffer=ToParse} = State, Acc0, WsCallback) ->
case take_frame(ToParse) of
{error, max_size_reached} ->
- ?LOG_DEBUG("reached max unparsed buffer size, aborting connection", []),
+ ?PWS_LOG_DEBUG("reached max unparsed buffer size, aborting connection", []),
{Acc0, websocket_close, websocket_close_data()};
{undefined, Rest} ->
- ?LOG_DEBUG("no frame to take, add to buffer: ~p", [Rest]),
+ ?PWS_LOG_DEBUG("no frame to take, add to buffer: ~p", [Rest]),
%% no full frame to be had yet
{Acc0, continue, State#wstate{buffer = Rest}};
{Frame=#frame{}, Rest} ->
- ?LOG_DEBUG("parsed frame ~p, remaining buffer is: ~p", [Frame,Rest]),
+ ?PWS_LOG_DEBUG("parsed frame ~p, remaining buffer is: ~p", [Frame,Rest]),
%% sanity check, in case client is broken
case sanity_check(Frame) of
true ->
- ?LOG_DEBUG("sanity checks successfully performed",[]),
+ ?PWS_LOG_DEBUG("sanity checks successfully performed",[]),
case handle_frame(Frame,
State#wstate{buffer = Rest},
Acc0, WsCallback) of
@@ -257,7 +257,7 @@ i_handle_data(#wstate{buffer=ToParse} = State, Acc0, WsCallback) ->
Other
end;
false -> % protocol error
- ?LOG_DEBUG("sanity checks errors encountered, closing websocket",[]),
+ ?PWS_LOG_DEBUG("sanity checks errors encountered, closing websocket",[]),
{Acc0, websocket_close, websocket_close_data()}
end
end.
@@ -286,12 +286,12 @@ sanity_check(Frame) ->
handle_frame(#frame{fin = 0, opcode = Opcode}, %% first fragment
State = #wstate{internal = []} = Frame,
Acc0, _) when Opcode =/= ?OP_CONT ->
- ?LOG_DEBUG("first fragment: ~p", [Frame]),
+ ?PWS_LOG_DEBUG("first fragment: ~p", [Frame]),
{Acc0, continue, State#wstate{internal = [Frame]}};
handle_frame(#frame{fin = 0, opcode = ?OP_CONT}, %% subsequent fragments
State = #wstate{internal = Frags} = Frame,
Acc0, _) when Frags =/= [] ->
- ?LOG_DEBUG("next fragment: ~p", [Frame]),
+ ?PWS_LOG_DEBUG("next fragment: ~p", [Frame]),
{Acc0, continue, State#wstate{internal = [Frame | Frags]}};
%% Last frame in a fragmented message.
@@ -308,7 +308,7 @@ handle_frame(#frame{fin = 1, opcode = ?OP_CONT } = F,
Frame1#frame{fin=1},
Frames
),
- ?LOG_DEBUG("final fragment, assembled: ~p",[Frame]),
+ ?PWS_LOG_DEBUG("final fragment, assembled: ~p",[Frame]),
%% now process this new combined message as if we got it all at once:
handle_frame(Frame, State#wstate{internal = []}, Acc0, WsCallback);
@@ -332,10 +332,10 @@ handle_frame(#frame{fin=1, opcode=Opcode, data=Data},
?OP_PING ->
{Acc0, continue, format_send(Data, ?OP_PONG, State), State};
?OP_CLOSE ->
- ?LOG_DEBUG("received a websocket close request",[]),
+ ?PWS_LOG_DEBUG("received a websocket close request",[]),
{Acc0, websocket_close};
_OpOther ->
- ?LOG_DEBUG("received segment with the unknown control OpCode ~p, closing websocket", [_OpOther]),
+ ?PWS_LOG_DEBUG("received segment with the unknown control OpCode ~p, closing websocket", [_OpOther]),
{Acc0, websocket_close, websocket_close_data()}
end;
Please sign in to comment.
Something went wrong with that request. Please try again.