Skip to content
This repository
Newer
Older
100644 493 lines (410 sloc) 16.134 kb
b59ef9c6 »
2002-06-19 ""
1 %%----------------------------------------------------------------------
21abc5ba »
2002-02-11 Initial revision
2 %%% File : yaws_log.erl
3 %%% Author : Claes Wikstrom <klacke@hyber.org>
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
4 %%% Purpose :
21abc5ba »
2002-02-11 Initial revision
5 %%% Created : 26 Jan 2002 by Claes Wikstrom <klacke@hyber.org>
6 %%%----------------------------------------------------------------------
7
8 -module(yaws_log).
9 -author('klacke@hyber.org').
89f2f03d »
2002-03-26 ""
10 -include_lib("kernel/include/file.hrl").
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
11 -include_lib("kernel/include/inet.hrl").
f79ee775 »
2002-12-03 ""
12
13
21abc5ba »
2002-02-11 Initial revision
14 -behaviour(gen_server).
15
16 %% External exports
3bdc203f »
2011-08-02 Added possibility to turn off yaws log wrapping. This is useful for a…
17 -export([start_link/0, reopen_logs/0]).
21abc5ba »
2002-02-11 Initial revision
18
19 %% gen_server callbacks
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
20 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
21 code_change/3]).
22
23 %% API
24 -export([accesslog/6,
25 setup/2,
9a74e5aa »
2008-05-12 Major general code cleanup, finally got rid of all the export_all sta…
26 authlog/4,
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
27 rotate/1,
28 add_sconf/1,
29 del_sconf/1]).
30
31 %% yaws_logger callbacks
32 -export([
33 open_log/3,
34 close_log/3,
35 wrap_log/4,
36 write_log/4
37 ]).
9a74e5aa »
2008-05-12 Major general code cleanup, finally got rid of all the export_all sta…
38
3c06a9e9 »
2002-10-10 rearr of includefiles
39
6cf3eceb »
2005-11-20 ""
40 -include("../include/yaws.hrl").
41 -include("../include/yaws_api.hrl").
3c06a9e9 »
2002-10-10 rearr of includefiles
42 -include("yaws_debug.hrl").
43
bea82617 »
2004-11-19 added log_wrap_size, configurable wrap size for all logs, fixed a bug…
44 %% 1 meg log we wrap
45 -define(WRAP_LOG_SIZE, 1000000).
46
3c06a9e9 »
2002-10-10 rearr of includefiles
47
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
48 -record(state, {running,
49 dir,
50 now,
51 log_wrap_size = ?WRAP_LOG_SIZE,
52 copy_errlog,
53 resolve_hostnames = false}).
f56c417e »
2002-12-01 bugs in wrap log
54
21abc5ba »
2002-02-11 Initial revision
55
56 %%%----------------------------------------------------------------------
57 %%% API
58 %%%----------------------------------------------------------------------
59 start_link() ->
60 gen_server:start_link({local, yaws_log}, yaws_log, [], []).
61
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
62 setup(GC, Sconfs) ->
63 gen_server:call(?MODULE, {setup, GC, Sconfs}, infinity).
325dd655 » Bwooce
2003-03-10 Added referrer "referer" and user-agent to complete the "combined" log
64
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
65 add_sconf(SConf) ->
66 gen_server:call(yaws_log, {soft_add_sc, SConf}, infinity).
7502db42 » mbj4668
2004-04-22 added username from authorization header to access log
67
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
68 del_sconf(SConf) ->
69 gen_server:call(yaws_log, {soft_del_sc, SConf}, infinity).
70
71 accesslog(SConf, Ip, Req, InH, OutH, Time) ->
72 catch yaws_logger:accesslog(SConf, Ip, Req, InH, OutH, Time).
73
74 authlog(SConf, IP, Path, Item) ->
75 catch yaws_logger:authlog(SConf, IP, Path, Item).
76
77 rotate(Res) ->
78 gen_server:cast(?MODULE, {yaws_hupped, Res}).
21abc5ba »
2002-02-11 Initial revision
79
3bdc203f »
2011-08-02 Added possibility to turn off yaws log wrapping. This is useful for a…
80 %% Useful for embeddded yaws when we don't want yaws to
81 %% automatically wrap the logs.
82 reopen_logs() ->
83 {ok, _GC, SCs} = yaws_api:getconf(),
84 gen_server:call(?MODULE, {reopen, SCs}).
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
85
86
87 %%%----------------------------------------------------------------------
88 %%% Callback functions from yaws_logger
89 %%%----------------------------------------------------------------------
90 open_log(ServerName, Type, Dir) ->
91 FileName = case os:type() of
92 {win32,_ } ->
93 lists:map(fun($:) -> $.;
94 (C ) -> C
95 end, ServerName);
96 _ ->
97 ServerName
98 end,
99 A = filename:join([Dir, FileName ++ "." ++ atom_to_list(Type)]),
100 case file:open(A, [write, raw, append]) of
101 {ok, Fd} ->
102 {true, {Fd, A}};
103 _Err ->
104 error_logger:format("Cannot open ~p",[A]),
105 false
106 end.
0c9da974 »
2002-11-27 added ability to run as different user than root
107
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
108 close_log(_ServerName, _Type, {Fd, _FileName}) ->
109 file:close(Fd).
dc00e526 »
2004-03-10 postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
110
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
111 wrap_log(_ServerName, _Type, {Fd, FileName}, LogWrapSize) ->
112 case wrap_p(FileName, LogWrapSize) of
113 true ->
114 file:close(Fd),
115 Old = [FileName, ".old"],
116 file:delete(Old),
117 file:rename(FileName, Old),
118 {ok, Fd2} = file:open(FileName, [write, raw]),
119 {Fd2, FileName};
120 false ->
121 {Fd, FileName};
122 enoent ->
123 %% Logfile disappeared,
124 error_logger:format("Logfile ~p disappeared - we reopen it",
125 [FileName]),
126 file:close(Fd),
127 {ok, Fd2} = file:open(FileName, [write, raw]),
128 {Fd2, FileName}
129 end.
dc00e526 »
2004-03-10 postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
130
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
131 write_log(ServerName, Type, {Fd, _FileName}, Infos) ->
132 gen_server:cast(yaws_log, {ServerName, Type, Fd, Infos}).
0c9da974 »
2002-11-27 added ability to run as different user than root
133
21abc5ba »
2002-02-11 Initial revision
134 %%%----------------------------------------------------------------------
135 %%% Callback functions from gen_server
136 %%%----------------------------------------------------------------------
137
138 %%----------------------------------------------------------------------
139 %% Func: init/1
140 %% Returns: {ok, State} |
141 %% {ok, State, Timeout} |
142 %% ignore |
143 %% {stop, Reason}
144 %%----------------------------------------------------------------------
145 init([]) ->
6f0ab17f »
2010-02-19 Anders Dahlin found that yaws log code doesn't delete the gen_event h…
146 process_flag(trap_exit, true),
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
147 ets:new(yaws_log, [named_table, set, protected, {keypos, 2}]),
f79ee775 »
2002-12-03 ""
148 {ok, #state{running = false, now = fmtnow()}}.
21abc5ba »
2002-02-11 Initial revision
149
150 %%----------------------------------------------------------------------
151 %% Func: handle_call/3
152 %% Returns: {reply, Reply, State} |
153 %% {reply, Reply, State, Timeout} |
154 %% {noreply, State} |
155 %% {noreply, State, Timeout} |
156 %% {stop, Reason, Reply, State} | (terminate/2 is called)
157 %% {stop, Reason, State} (terminate/2 is called)
158 %%----------------------------------------------------------------------
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
159 handle_call({setup, GC, Sconfs}, _From, State)
89f2f03d »
2002-03-26 ""
160 when State#state.running == false ->
dc00e526 »
2004-03-10 postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
161 Dir = GC#gconf.logdir,
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
162 ?Debug("setup ~s~n", [Dir]),
dc00e526 »
2004-03-10 postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
163 ElogFile = filename:join([Dir, "report.log"]),
7fd4ad4e »
2004-03-11 backwards incomp cahnge with flags in gc and sc instead of many bools…
164 Copy = if ?gc_has_copy_errlog(GC) ->
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
165 gen_event:add_handler(error_logger, yaws_log_file_h,
0be3c7e8 »
2008-02-14 untabified all of yaws
166 ElogFile),
167 true;
168 true ->
169 false
170 end,
dc00e526 »
2004-03-10 postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
171 SCs = lists:flatten(Sconfs),
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
172 lists:foreach(fun(SC) ->
173 yaws_logger:open_log(SC, auth, Dir),
174 yaws_logger:open_log(SC, access, Dir)
175 end, SCs),
176
b425cce3 »
2002-10-15 log bugs in embedded mode
177 S2 = State#state{running = true,
0be3c7e8 »
2008-02-14 untabified all of yaws
178 dir = Dir,
179 now = fmtnow(),
180 log_wrap_size = GC#gconf.log_wrap_size,
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
181 copy_errlog = Copy,
182 resolve_hostnames = ?gc_log_has_resolve_hostname(GC)},
b425cce3 »
2002-10-15 log bugs in embedded mode
183
184 yaws:ticker(3000, secs3),
3bdc203f »
2011-08-02 Added possibility to turn off yaws log wrapping. This is useful for a…
185
186 if is_integer(GC#gconf.log_wrap_size) ->
187 yaws:ticker(10 * 60 * 1000, minute10);
188 true ->
189 ok
190 end,
b425cce3 »
2002-10-15 log bugs in embedded mode
191
192 {reply, ok, S2};
193
194
195
196 %% We can't ever change logdir, we can however
197 %% change logging opts for various servers
198
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
199 handle_call({setup, GC, Sconfs}, _From, State)
b425cce3 »
2002-10-15 log bugs in embedded mode
200 when State#state.running == true ->
201
202 Dir = State#state.dir,
7fd4ad4e »
2004-03-11 backwards incomp cahnge with flags in gc and sc instead of many bools…
203 ElogFile = filename:join([Dir, "report.log"]),
204 Copy = if ?gc_has_copy_errlog(GC), State#state.copy_errlog == false->
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
205 gen_event:add_handler(error_logger, yaws_log_file_h,
0be3c7e8 »
2008-02-14 untabified all of yaws
206 ElogFile),
207 true;
208 ?gc_has_copy_errlog(GC) ->
209 true;
210 State#state.copy_errlog == true ->
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
211 gen_event:delete_handler(error_logger, yaws_log_file_h,
0be3c7e8 »
2008-02-14 untabified all of yaws
212 normal),
213 false;
214 true ->
215 false
216 end,
217
b425cce3 »
2002-10-15 log bugs in embedded mode
218 %% close all files
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
219 yaws_logger:close_logs(),
0be3c7e8 »
2008-02-14 untabified all of yaws
220
b425cce3 »
2002-10-15 log bugs in embedded mode
221 %% reopen logfiles
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
222 SCs = lists:flatten(Sconfs),
223 lists:foreach(fun(SC) ->
224 yaws_logger:open_log(SC, auth, Dir),
225 yaws_logger:open_log(SC, access, Dir)
226 end, SCs),
227
89f2f03d »
2002-03-26 ""
228 S2 = State#state{running = true,
0be3c7e8 »
2008-02-14 untabified all of yaws
229 dir = Dir,
230 now = fmtnow(),
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
231 log_wrap_size = GC#gconf.log_wrap_size,
232 copy_errlog = Copy,
233 resolve_hostnames = ?gc_log_has_resolve_hostname(GC)},
0be3c7e8 »
2008-02-14 untabified all of yaws
234
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
235 if
236 not is_integer(State#state.log_wrap_size),
237 is_integer(GC#gconf.log_wrap_size) ->
238 yaws:ticker(10 * 60 * 1000, minute10);
239 true ->
240 ok
241 end,
89f2f03d »
2002-03-26 ""
242 {reply, ok, S2};
243
244
9199a36d »
2004-12-15 added support for config changes without stopping the running systems…
245 %% a virt server has been added
246 handle_call({soft_add_sc, SC}, _From, State) ->
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
247 yaws_logger:open_log(SC, auth, State#state.dir),
248 yaws_logger:open_log(SC, access, State#state.dir),
249 {reply, ok, State};
9199a36d »
2004-12-15 added support for config changes without stopping the running systems…
250
251 %% a virt server has been deleted
252 handle_call({soft_del_sc, SC}, _From, State) ->
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
253 yaws_logger:close_log(SC, auth),
254 yaws_logger:close_log(SC, access),
255 {reply, ok, State};
9199a36d »
2004-12-15 added support for config changes without stopping the running systems…
256
257
f0ccdc0a »
2002-11-29 ""
258 handle_call(state, _From, State) ->
3bdc203f »
2011-08-02 Added possibility to turn off yaws log wrapping. This is useful for a…
259 {reply, State, State};
f0ccdc0a »
2002-11-29 ""
260
3bdc203f »
2011-08-02 Added possibility to turn off yaws log wrapping. This is useful for a…
261 handle_call({reopen, Sconfs}, _From, State) ->
262 Dir = State#state.dir,
263 %% close all files
264 yaws_logger:close_logs(),
78112471 » vinoski
2011-10-31 whitespace cleanup
265
3bdc203f »
2011-08-02 Added possibility to turn off yaws log wrapping. This is useful for a…
266 %% reopen logfiles
267 SCs = lists:flatten(Sconfs),
268 lists:foreach(fun(SC) ->
269 yaws_logger:open_log(SC, auth, Dir),
270 yaws_logger:open_log(SC, access, Dir)
271 end, SCs),
272 {reply, ok, State}.
4e18768e »
2002-11-08 added interactive tty trace
273
21abc5ba »
2002-02-11 Initial revision
274 %%----------------------------------------------------------------------
275 %% Func: handle_cast/2
276 %% Returns: {noreply, State} |
277 %% {noreply, State, Timeout} |
278 %% {stop, Reason, State} (terminate/2 is called)
279 %%----------------------------------------------------------------------
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
280 handle_cast({_ServerName, access, Fd, {Ip, Req, InH, OutH, _}}, State) ->
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
281 case State#state.running of
0be3c7e8 »
2008-02-14 untabified all of yaws
282 true ->
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
283 Status = case OutH#outh.status of
284 undefined -> "-";
285 S -> integer_to_list(S)
286 end,
287 Len = case Req#http_request.method of
288 'HEAD' ->
289 "-";
290 _ ->
291 case OutH#outh.contlen of
292 undefined ->
293 case OutH#outh.act_contlen of
294 undefined -> "-";
295 L -> integer_to_list(L)
296 end;
297 L ->
298 integer_to_list(L)
299 end
300 end,
301 Ver = case Req#http_request.version of
302 {1,0} -> "HTTP/1.0";
303 {1,1} -> "HTTP/1.1";
304 {0,9} -> "HTTP/0.9"
305 end,
306
4dc3b76f » capflam
2012-05-03 Remove safe_decode_path/1 from yaws_log and use...
307 Path = yaws_server:safe_decode_path(Req#http_request.path),
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
308 Meth = yaws:to_list(Req#http_request.method),
309 Referer = optional_header(InH#headers.referer),
310 UserAgent = optional_header(InH#headers.user_agent),
311 User = case InH#headers.authorization of
312 {U, _P, _OStr} -> U;
313 _ -> "-"
314 end,
315
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
316 Msg = fmt_access_log(State#state.now, fmt_ip(Ip, State), User,
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
317 [Meth, $\s, Path, $\s, Ver],
318 Status, Len, Referer, UserAgent),
8904c51b » nicad
2012-06-14 make sure to always send proper strings to file:write() while logging
319 file:write(Fd, safe_log_data(Msg)),
0be3c7e8 »
2008-02-14 untabified all of yaws
320 {noreply, State};
321 false ->
322 {noreply, State}
961926f2 »
2002-03-04 ""
323 end;
ddc90318 »
2004-02-11 added an auth log that keeps track of good/bad 401 requests
324
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
325 handle_cast({ServerName, auth, Fd, {Ip, Path, Item}}, State) ->
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
326 case State#state.running of
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
327 true ->
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
328 Host = fmt_ip(Ip, State),
329 Msg = [Host, " ", State#state.now, " ", ServerName, " " ,
330 "\"", Path,"\"",
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
331 case Item of
332 {ok, User} -> [" OK user=", User];
333 403 -> [" 403"];
334 {401, Realm} -> [" 401 realm=", Realm];
335 {401, User, PWD} -> [" 401 user=", User, " badpwd=", PWD]
336 end, "\n"],
8904c51b » nicad
2012-06-14 make sure to always send proper strings to file:write() while logging
337 file:write(Fd, safe_log_data(Msg)),
0be3c7e8 »
2008-02-14 untabified all of yaws
338 {noreply, State};
339 false ->
340 {noreply,State}
ddc90318 »
2004-02-11 added an auth log that keeps track of good/bad 401 requests
341 end;
0be3c7e8 »
2008-02-14 untabified all of yaws
342
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
343 handle_cast({yaws_hupped, _}, State) ->
344 handle_info(minute10, State).
ddc90318 »
2004-02-11 added an auth log that keeps track of good/bad 401 requests
345
21abc5ba »
2002-02-11 Initial revision
346
bf703dc2 »
2007-12-09 The final piece in the puzzle by Richard Bucker, yaws now play nicely…
347 %%----------------------------------------------------------------------
21abc5ba »
2002-02-11 Initial revision
348 %% Func: handle_info/2
349 %% Returns: {noreply, State} |
350 %% {noreply, State, Timeout} |
351 %% {stop, Reason, State} (terminate/2 is called)
352 %%----------------------------------------------------------------------
89f2f03d »
2002-03-26 ""
353 handle_info(secs3, State) ->
354 {noreply, State#state{now = fmtnow()}};
355
12c9f011 » vinoski
2009-06-18 eliminate io_lib:format overhead in yaws_log:fmtnow
356 %% once every 10 minutes, check log sizes
f56c417e »
2002-12-01 bugs in wrap log
357 handle_info(minute10, State) ->
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
358 yaws_logger:rotate(State#state.log_wrap_size),
0be3c7e8 »
2008-02-14 untabified all of yaws
359
317008a4 » garret-smith
2011-12-07 fix log rotation on Windows, where fsync() is required to get the act…
360 case gen_event:call(error_logger, yaws_log_file_h, size, infinity) of
361 {ok, Size} when State#state.log_wrap_size > 0,
2411b2f8 » garret-smith
2011-12-07 rotate log file regardless of copy_errlog parameter
362 Size > State#state.log_wrap_size ->
39a4e1d5 »
2009-01-04 wrap log infinity bug found bt Phanikar.K
363 gen_event:call(error_logger, yaws_log_file_h, wrap, infinity);
317008a4 » garret-smith
2011-12-07 fix log rotation on Windows, where fsync() is required to get the act…
364 {error, enoent} ->
39a4e1d5 »
2009-01-04 wrap log infinity bug found bt Phanikar.K
365 gen_event:call(error_logger, yaws_log_file_h, reopen, infinity);
0be3c7e8 »
2008-02-14 untabified all of yaws
366 _ ->
367 ok
89f2f03d »
2002-03-26 ""
368 end,
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
369 {noreply, State};
6f0ab17f »
2010-02-19 Anders Dahlin found that yaws log code doesn't delete the gen_event h…
370 handle_info({'EXIT', _, _}, State) ->
371 {noreply, State}.
0be3c7e8 »
2008-02-14 untabified all of yaws
372
89f2f03d »
2002-03-26 ""
373
374
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
375 wrap_p(Filename, LogWrapSize) ->
376 case file:read_file_info(Filename) of
377 {ok, FI} when FI#file_info.size > LogWrapSize, LogWrapSize > 0 ->
0be3c7e8 »
2008-02-14 untabified all of yaws
378 true;
379 {ok, _FI} ->
380 false;
381 {error, enoent} ->
382 enoent;
383 _ ->
384 false
ddc90318 »
2004-02-11 added an auth log that keeps track of good/bad 401 requests
385 end.
89f2f03d »
2002-03-26 ""
386
387
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
388
21abc5ba »
2002-02-11 Initial revision
389 %%----------------------------------------------------------------------
390 %% Func: terminate/2
391 %% Purpose: Shutdown the server
392 %% Returns: any (ignored by gen_server)
393 %%----------------------------------------------------------------------
2129adc6 »
2002-05-30 ""
394 terminate(_Reason, _State) ->
6f0ab17f »
2010-02-19 Anders Dahlin found that yaws log code doesn't delete the gen_event h…
395 gen_event:delete_handler(error_logger, yaws_log_file_h, normal),
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
396 yaws_logger:close_logs(),
21abc5ba »
2002-02-11 Initial revision
397 ok.
398
ca1c8b1b » karlsson
2010-07-01 Fixed a number of compiler warnings and html validation errors
399
400 %%----------------------------------------------------------------------
401 %% Func: code_change/3
402 %% Purpose: Handle upgrade
403 %% Returns: new State data
404 %%----------------------------------------------------------------------
405 code_change(_OldVsn, Data, _Extra) ->
406 {ok, Data}.
407
21abc5ba »
2002-02-11 Initial revision
408 %%%----------------------------------------------------------------------
409 %%% Internal functions
410 %%%----------------------------------------------------------------------
d9342f8b » capflam
2011-05-04 server-specific logger_mod and auth_mod (capflam)
411 optional_header(Item) ->
412 case Item of
413 undefined -> "-";
414 Item -> Item
415 end.
416
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
417 fmt_access_log(Time, Host, User, Req, Status, Length, Referrer, UserAgent) ->
418 [Host, " - ", User, [$\s], Time, [$\s, $\"], no_ctl(Req), [$\",$\s],
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
419 Status, [$\s], Length, [$\s,$"], Referrer, [$",$\s,$"], UserAgent,
6e96a140 »
2011-03-03 indendation cleanup
420 [$",$\n]].
21abc5ba »
2002-02-11 Initial revision
421
2ca4bda1 »
2004-12-13 added client IP resolv for access log files
422
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
423 %% Odd security advisory that only affects webservers where users are
9d929cac »
2010-01-05 prepare for 1.87
424 %% somehow allowed to upload files that later can be downloaded.
425
426 no_ctl([H|T]) when H < 32 ->
427 no_ctl(T);
428 no_ctl([H|T]) ->
429 [H|no_ctl(T)];
430 no_ctl([]) ->
431 [].
432
433
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
434 fmt_ip(IP, State) when is_tuple(IP) ->
435 case State#state.resolve_hostnames of
436 true ->
437 case catch inet:gethostbyaddr(IP) of
438 {ok, HE} ->
439 HE#hostent.h_name;
440 _ ->
441 case catch inet_parse:ntoa(IP) of
442 {'EXIT', _} -> "unknownip";
443 Addr -> Addr
444 end
445 end;
446 false ->
447 case catch inet_parse:ntoa(IP) of
448 {'EXIT', _} -> "unknownip";
449 Addr -> Addr
450 end
4dc3b76f » capflam
2012-05-03 Remove safe_decode_path/1 from yaws_log and use...
451 end;
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
452 fmt_ip(unknown, _) ->
453 "unknownip";
454 fmt_ip(undefined, _) ->
2ca4bda1 »
2004-12-13 added client IP resolv for access log files
455 "0.0.0.0";
824e6dbd » capflam
2012-05-03 Move hostname resolution from yaws_server to yaws_log
456 fmt_ip(HostName, _) ->
2ca4bda1 »
2004-12-13 added client IP resolv for access log files
457 HostName.
458
459
21abc5ba »
2002-02-11 Initial revision
460 fmtnow() ->
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
461 {{Year, Month, Day}, {Hour, Min, Sec}} =
8322cec3 »
2009-09-28 timezone format patch by Per Hedeland
462 calendar:now_to_local_time(now()),
9dfb58e7 »
2010-03-10 Erroneous common log format entries, time should be surrounded by bra…
463 ["[",fill_zero(Day,2),"/",yaws:month(Month),"/",integer_to_list(Year),":",
6e96a140 »
2011-03-03 indendation cleanup
464 fill_zero(Hour,2),":",fill_zero(Min,2),":",
465 fill_zero(Sec,2)," ",zone(),"]"].
466
21abc5ba »
2002-02-11 Initial revision
467
468 zone() ->
4803dfcc » Bwooce
2003-03-11 Fixed the TZ determination code, its not perfect or fast yet.
469 Time = erlang:universaltime(),
470 LocalTime = calendar:universal_time_to_local_time(Time),
455578a2 » vinoski
2011-04-19 major trailing whitespace cleanup
471 DiffSecs = calendar:datetime_to_gregorian_seconds(LocalTime) -
0be3c7e8 »
2008-02-14 untabified all of yaws
472 calendar:datetime_to_gregorian_seconds(Time),
8322cec3 »
2009-09-28 timezone format patch by Per Hedeland
473 zone(DiffSecs div 3600, (DiffSecs rem 3600) div 60).
325dd655 » Bwooce
2003-03-10 Added referrer "referer" and user-agent to complete the "combined" log
474
c966d771 »
2009-09-28 re-introduce Steves optimazation of fmtnow()
475
21abc5ba »
2002-02-11 Initial revision
476
8322cec3 »
2009-09-28 timezone format patch by Per Hedeland
477 zone(Hr, Min) when Hr < 0; Min < 0 ->
c966d771 »
2009-09-28 re-introduce Steves optimazation of fmtnow()
478 [$-, fill_zero(abs(Hr), 2), fill_zero(abs(Min), 2)];
8322cec3 »
2009-09-28 timezone format patch by Per Hedeland
479 zone(Hr, Min) when Hr >= 0, Min >= 0 ->
c966d771 »
2009-09-28 re-introduce Steves optimazation of fmtnow()
480 [$+, fill_zero(abs(Hr), 2), fill_zero(abs(Min), 2)].
481
482 fill_zero(N, Width) ->
483 left_fill(N, Width, $0).
12c9f011 » vinoski
2009-06-18 eliminate io_lib:format overhead in yaws_log:fmtnow
484
c966d771 »
2009-09-28 re-introduce Steves optimazation of fmtnow()
485 left_fill(N, Width, Fill) when is_integer(N) ->
486 left_fill(integer_to_list(N), Width, Fill);
487 left_fill(N, Width, _Fill) when length(N) >= Width ->
488 N;
489 left_fill(N, Width, Fill) ->
490 left_fill([Fill|N], Width, Fill).
3bdc203f »
2011-08-02 Added possibility to turn off yaws log wrapping. This is useful for a…
491
8904c51b » nicad
2012-06-14 make sure to always send proper strings to file:write() while logging
492 safe_log_data(Elements) ->
493 [ yaws:to_string(E) || E <- Elements ].
494
78112471 » vinoski
2011-10-31 whitespace cleanup
495
496
Something went wrong with that request. Please try again.