From 5394a7d3fdbe47b66d22f082ac6e8a496f0928ae Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 7 Jul 2011 18:02:29 -0400 Subject: [PATCH] Add lager.hrl --- include/lager.hrl | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/lager.hrl diff --git a/include/lager.hrl b/include/lager.hrl new file mode 100644 index 0000000..f944b9d --- /dev/null +++ b/include/lager.hrl @@ -0,0 +1,64 @@ +%% Copyright (c) 2011 Basho Technologies, Inc. All Rights Reserved. +%% +%% This file is provided to you under the Apache License, +%% Version 2.0 (the "License"); you may not use this file +%% except in compliance with the License. You may obtain +%% a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. + +-define(LEVELS, + [debug, info, notice, warning, error, critical, alert, emergency]). + +-define(DEBUG, 7). +-define(INFO, 6). +-define(NOTICE, 5). +-define(WARNING, 4). +-define(ERROR, 3). +-define(CRITICAL, 2). +-define(ALERT, 1). +-define(EMERGENCY, 0). + +-define(LEVEL2NUM(Level), + case Level of + debug -> ?DEBUG; + info -> ?INFO; + notice -> ?NOTICE; + warning -> ?WARNING; + error -> ?ERROR; + critical -> ?CRITICAL; + alert -> ?ALERT; + emergency -> ?EMERGENCY + end). + +-define(NUM2LEVEL(Num), + case Num of + ?DEBUG -> debug; + ?INFO -> info; + ?NOTICE -> notice; + ?WARNING -> warning; + ?ERROR -> error; + ?CRITICAL -> critical; + ?ALERT -> alert; + ?EMERGENCY -> emergency + end). + +-define(SHOULD_LOG(Level), + ?LEVEL2NUM(Level) =< lager_mochiglobal:get(loglevel, ?DEBUG)). + +%% internal non-blocking logging call +-define(INT_LOG(Level, Format, Args), + case ?SHOULD_LOG(Level) of + true -> + gen_event:notify(lager_event, {log, lager_util:level_to_num(Level), + lager_util:format_time(), [io_lib:format("[~p] ~p ", [Level, self()]), io_lib:format(Format, Args)]}); + _ -> ok + end). +