Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge github.com:mmzeeman/webzmachine into master

Conflicts:
	src/webmachine_mochiweb.erl
  • Loading branch information...
commit 45b9bc4be12d769d73e1c0a48ff0bf03a9b1b779 2 parents 45df444 + 9f6f845
@kaos kaos authored
View
3  include/webmachine_logger.hrl
@@ -12,5 +12,6 @@
response_code,
response_length,
end_time :: tuple(),
- finish_time :: tuple()}).
+ finish_time :: tuple(),
+ metadata :: dict()}).
View
11 src/webmachine_decision_core.erl
@@ -145,17 +145,18 @@ decision_flow({ErrCode, Reason}, _TestResult, Rs, Rd) when is_integer(ErrCode) -
do_log(LogData) ->
case application:get_env(webzmachine, webmachine_logger_module) of
- {ok, LoggerModule} -> LoggerModule:log_access(LogData);
+ {ok, LoggerModule} -> spawn(LoggerModule, log_access, [LogData]);
_ -> nop
end,
case application:get_env(webzmachine, enable_perf_logger) of
- {ok, true} ->
- webmachine_perf_logger:log(LogData);
- _ ->
- ignore
+ {ok, true} ->
+ spawn(webmachine_perf_logger, log, [LogData]);
+ _ ->
+ ignore
end.
+
%% "Service Available"
decision(v3b13, Rs, Rd) ->
decision_test(controller_call(ping, Rs, Rd), pong, v3b13b, 503);
View
13 src/webmachine_id.erl
@@ -18,11 +18,8 @@
-export([generate/0]).
generate() ->
- NodeId =
- case application:get_env(webzmachine, node_id) of
- undefined -> 9;
- {ok, NodeId_} -> NodeId_
- end,
- {MegaSec, Sec, MicroSec} = now(),
- Id = ((NodeId * 1000000 + MegaSec) * 1000000 + Sec) * 1000000 + MicroSec,
- Id.
+ NodeId = case application:get_env(webzmachine, node_id) of
+ undefined -> undefined;
+ {ok, NodeId_} -> NodeId_
+ end,
+ erlang:phash2({NodeId, make_ref(), os:timestamp()}, 1073741824).
View
8 src/webmachine_logger.erl
@@ -21,7 +21,7 @@
-export([start_link/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
--export([log_access/1, refresh/0]).
+-export([log_access/1, refresh/0, get_metadata/2]).
-include("webmachine_logger.hrl").
-record(state, {hourstamp, filename, handle}).
@@ -97,6 +97,12 @@ maybe_rotate(State, Time) ->
State#state{hourstamp=ThisHour, handle=Handle}
end.
+get_metadata(Key, #wm_log_data{metadata=MetaData}) ->
+ case dict:find(Key, MetaData) of
+ {ok, Value} -> Value;
+ error -> undefined
+ end.
+
format_req(#wm_log_data{req_id=ReqId,
method=Method,
headers=Headers,
View
18 src/webmachine_mochiweb.erl
@@ -71,6 +71,7 @@ init_reqdata(MochiReq) ->
response_length=0},
PeerState#wm_reqdata{log_data=LogData}.
+
loop(MochiReq, LoopOpts) ->
reset_process_dictionary(),
ReqData = init_reqdata(MochiReq),
@@ -93,11 +94,7 @@ loop(MochiReq, LoopOpts) ->
ReqState2 = webmachine_request:append_to_response_body(ErrorHTML, ReqState1),
{ok,ReqState3} = webmachine_request:send_response(404, ReqState2),
LogData = webmachine_request:log_data(ReqState3),
- case application:get_env(webzmachine,webmachine_logger_module) of
- {ok, LogModule} ->
- spawn(LogModule, log_access, [LogData]);
- _ -> nop
- end;
+ webmachine_decision_core:do_log(LogData);
{Mod, ModOpts, HostTokens, Port, PathTokens, Bindings, AppRoot, StringPath} ->
{ok, Resource} = webmachine_controller:init(ReqData, Mod, ModOpts),
{ok,RD1} = webmachine_request:load_dispatch_data(Bindings,HostTokens,Port,PathTokens,AppRoot,StringPath,ReqDispatch),
@@ -109,9 +106,7 @@ loop(MochiReq, LoopOpts) ->
{_, RdResp} = webmachine_request:send_response(RdFin),
webmachine_controller:stop(RsFin, RdResp),
LogData0 = webmachine_request:log_data(RdResp),
- spawn(fun() ->
- webmachine_decision_core:do_log(LogData0#wm_log_data{controller_module=Mod, end_time=EndTime})
- end),
+ webmachine_decision_core:do_log(LogData0#wm_log_data{controller_module=Mod, end_time=EndTime}),
ok;
{upgrade, UpgradeFun, RsFin, RdFin} ->
%%TODO: wmtracing 4xx result codes should ignore protocol upgrades? (because the code is 404 by default...)
@@ -124,12 +119,7 @@ loop(MochiReq, LoopOpts) ->
?WM_DBG({error, Error, erlang:get_stacktrace()}),
{ok,RD3} = webmachine_request:send_response(500, RD2),
webmachine_controller:stop(Resource, RD3),
- case application:get_env(webzmachine, webmachine_logger_module) of
- {ok, LogModule} ->
- spawn(LogModule, log_access, [webmachine_request:log_data(RD3)]);
- _ ->
- nop
- end
+ webmachine_decision_core:do_log(RD3)
end;
handled ->
nop
View
4 src/webmachine_request.erl
@@ -715,5 +715,5 @@ load_dispatch_data(Bindings, HostTokens, Port, PathTokens, AppRoot, DispPath, Re
{ok, RD1}.
-log_data(ReqData) ->
- ReqData#wm_reqdata.log_data.
+log_data(#wm_reqdata{log_data=LogData, metadata=MetaData}) ->
+ LogData#wm_log_data{metadata=MetaData}.
Please sign in to comment.
Something went wrong with that request. Please try again.