1%% ``Licensed under the Apache License, Version 2.0 (the "License"); 2%% you may not use this file except in compliance with the License. 3%% You may obtain a copy of the License at 4%% 5%% http://www.apache.org/licenses/LICENSE-2.0 6%% 7%% Unless required by applicable law or agreed to in writing, software 8%% distributed under the License is distributed on an "AS IS" BASIS, 9%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10%% See the License for the specific language governing permissions and 11%% limitations under the License. 12%% 13%% The Initial Developer of the Original Code is Ericsson Utvecklings AB. 14%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings 15%% AB. All Rights Reserved.'' 16%% 17%% $Id: httpd_verbosity.erl,v 1.1 2008/12/17 09:53:34 mikpe Exp $ 18%% 19-module(httpd_verbosity). 20 21-include_lib("stdlib/include/erl_compile.hrl"). 22 23-export([print/4,print/5,printc/4,validate/1]). 24 25print(silence,_Severity,_Format,_Arguments) -> 26 ok; 27print(Verbosity,Severity,Format,Arguments) -> 28 print1(printable(Verbosity,Severity),Format,Arguments). 29 30 31print(silence,_Severity,_Module,_Format,_Arguments) -> 32 ok; 33print(Verbosity,Severity,Module,Format,Arguments) -> 34 print1(printable(Verbosity,Severity),Module,Format,Arguments). 35 36 37printc(silence,Severity,Format,Arguments) -> 38 ok; 39printc(Verbosity,Severity,Format,Arguments) -> 40 print2(printable(Verbosity,Severity),Format,Arguments). 41 42 43print1(false,_Format,_Arguments) -> ok; 44print1(Verbosity,Format,Arguments) -> 45 V = image_of_verbosity(Verbosity), 46 S = image_of_sname(get(sname)), 47 io:format("** HTTPD ~s ~s: " ++ Format ++ "~n",[S,V]++Arguments). 48 49print1(false,_Module,_Format,_Arguments) -> ok; 50print1(Verbosity,Module,Format,Arguments) -> 51 V = image_of_verbosity(Verbosity), 52 S = image_of_sname(get(sname)), 53 io:format("** HTTPD ~s ~s ~s: " ++ Format ++ "~n",[S,Module,V]++Arguments). 54 55 56print2(false,_Format,_Arguments) -> ok; 57print2(_Verbosity,Format,Arguments) -> 58 io:format(Format ++ "~n",Arguments). 59 60 61%% printable(Verbosity,Severity) 62printable(info,info) -> info; 63printable(log,info) -> info; 64printable(log,log) -> log; 65printable(debug,info) -> info; 66printable(debug,log) -> log; 67printable(debug,debug) -> debug; 68printable(trace,V) -> V; 69printable(_Verb,_Sev) -> false. 70 71 72image_of_verbosity(info) -> "INFO"; 73image_of_verbosity(log) -> "LOG"; 74image_of_verbosity(debug) -> "DEBUG"; 75image_of_verbosity(trace) -> "TRACE"; 76image_of_verbosity(_) -> "". 77 78%% ShortName 79image_of_sname(acc) -> "ACCEPTOR"; 80image_of_sname(acc_sup) -> "ACCEPTOR_SUP"; 81image_of_sname(auth) -> "AUTH"; 82image_of_sname(man) -> "MANAGER"; 83image_of_sname(misc_sup) -> "MISC_SUP"; 84image_of_sname(sec) -> "SECURITY"; 85image_of_sname(P) when pid(P) -> io_lib:format("REQUEST_HANDLER(~p)",[P]); 86image_of_sname(undefined) -> ""; 87image_of_sname(V) -> io_lib:format("~p",[V]). 88 89 90validate(info) -> info; 91validate(log) -> log; 92validate(debug) -> debug; 93validate(trace) -> trace; 94validate(_) -> silence. 95