1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
%% AB. All Rights Reserved.''
16
%% $Id: httpd_verbosity.erl,v 1.1 2008/12/17 09:53:34 mikpe Exp $
18
-module(httpd_verbosity).
20
-include_lib("stdlib/include/erl_compile.hrl").
22
-export([print/4,print/5,printc/4,validate/1]).
24
print(silence,_Severity,_Format,_Arguments) ->
26
print(Verbosity,Severity,Format,Arguments) ->
27
print1(printable(Verbosity,Severity),Format,Arguments).
30
print(silence,_Severity,_Module,_Format,_Arguments) ->
32
print(Verbosity,Severity,Module,Format,Arguments) ->
33
print1(printable(Verbosity,Severity),Module,Format,Arguments).
36
printc(silence,Severity,Format,Arguments) ->
38
printc(Verbosity,Severity,Format,Arguments) ->
39
print2(printable(Verbosity,Severity),Format,Arguments).
42
print1(false,_Format,_Arguments) -> ok;
43
print1(Verbosity,Format,Arguments) ->
44
V = image_of_verbosity(Verbosity),
45
S = image_of_sname(get(sname)),
46
io:format("** HTTPD ~s ~s: " ++ Format ++ "~n",[S,V]++Arguments).
48
print1(false,_Module,_Format,_Arguments) -> ok;
49
print1(Verbosity,Module,Format,Arguments) ->
50
V = image_of_verbosity(Verbosity),
51
S = image_of_sname(get(sname)),
52
io:format("** HTTPD ~s ~s ~s: " ++ Format ++ "~n",[S,Module,V]++Arguments).
55
print2(false,_Format,_Arguments) -> ok;
56
print2(_Verbosity,Format,Arguments) ->
57
io:format(Format ++ "~n",Arguments).
60
%% printable(Verbosity,Severity)
61
printable(info,info) -> info;
62
printable(log,info) -> info;
63
printable(log,log) -> log;
64
printable(debug,info) -> info;
65
printable(debug,log) -> log;
66
printable(debug,debug) -> debug;
67
printable(trace,V) -> V;
68
printable(_Verb,_Sev) -> false.
71
image_of_verbosity(info) -> "INFO";
72
image_of_verbosity(log) -> "LOG";
73
image_of_verbosity(debug) -> "DEBUG";
74
image_of_verbosity(trace) -> "TRACE";
75
image_of_verbosity(_) -> "".
78
image_of_sname(acc) -> "ACCEPTOR";
79
image_of_sname(acc_sup) -> "ACCEPTOR_SUP";
80
image_of_sname(auth) -> "AUTH";
81
image_of_sname(man) -> "MANAGER";
82
image_of_sname(misc_sup) -> "MISC_SUP";
83
image_of_sname(sec) -> "SECURITY";
84
image_of_sname(P) when pid(P) -> io_lib:format("REQUEST_HANDLER(~p)",[P]);
85
image_of_sname(undefined) -> "";
86
image_of_sname(V) -> io_lib:format("~p",[V]).
89
validate(info) -> info;
91
validate(debug) -> debug;
92
validate(trace) -> trace;
93
validate(_) -> silence.