1% Licensed under the Apache License, Version 2.0 (the "License"); you may not 2% use this file except in compliance with the License. You may obtain a copy of 3% 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, WITHOUT 9% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10% License for the specific language governing permissions and limitations under 11% the License. 12 13-module(couch_log). 14 15 16-export([ 17 debug/2, 18 info/2, 19 notice/2, 20 warning/2, 21 error/2, 22 critical/2, 23 alert/2, 24 emergency/2, 25 26 set_level/1 27]). 28 29 30-spec debug(string(), list()) -> ok. 31debug(Fmt, Args) -> log(debug, Fmt, Args). 32 33 34-spec info(string(), list()) -> ok. 35info(Fmt, Args) -> log(info, Fmt, Args). 36 37 38-spec notice(string(), list()) -> ok. 39notice(Fmt, Args) -> log(notice, Fmt, Args). 40 41 42-spec warning(string(), list()) -> ok. 43warning(Fmt, Args) -> log(warning, Fmt, Args). 44 45 46-spec error(string(), list()) -> ok. 47error(Fmt, Args) -> log(error, Fmt, Args). 48 49 50-spec critical(string(), list()) -> ok. 51critical(Fmt, Args) -> log(critical, Fmt, Args). 52 53 54-spec alert(string(), list()) -> ok. 55alert(Fmt, Args) -> log(alert, Fmt, Args). 56 57 58-spec emergency(string(), list()) -> ok. 59emergency(Fmt, Args) -> log(emergency, Fmt, Args). 60 61 62-spec set_level(atom() | string() | integer()) -> true. 63set_level(Level) -> 64 config:set("log", "level", couch_log_util:level_to_string(Level)). 65 66 67-spec log(atom(), string(), list()) -> ok. 68log(Level, Fmt, Args) -> 69 case couch_log_util:should_log(Level) of 70 true -> 71 couch_stats:increment_counter([couch_log, level, Level]), 72 Entry = couch_log_formatter:format(Level, self(), Fmt, Args), 73 ok = couch_log_server:log(Entry); 74 false -> 75 ok 76 end. 77