Browse Source

now macroses ?INFO and ?DBG disable by default for server app
for enable their you must add to make command line SV=1 for enable ?INFO or SD=1 for both ?INFO and ?DBG
if you want to use rebar, you must add -DSERVER_LOG_VERBOSE or -DSERVER_LOG_DEBUG respectively

Roman Dayneko 11 years ago
parent
commit
7453f2b7e9
3 changed files with 34 additions and 1 deletions
  1. 9 0
      Makefile
  2. 24 0
      apps/server/include/log.hrl
  3. 1 1
      otp.mk

+ 9 - 0
Makefile

@@ -11,6 +11,15 @@ LOG_DIR ?= rels/web/devbox/logs
 N2O     := deps/n2o/priv/static
 APP     := apps/face/priv/static/nitrogen
 
+ifeq "$(SV)" "1"
+REBAR_D = -DLOG_VERBOSE=1
+endif
+
+ifeq "$(SD)" "1"
+REBAR_D = -DSERVER_LOG_VERBOSE=1 -DSERVER_LOG_DEBUG=1
+endif
+
+
 default: get-deps compile static-link
 static-link:
 	rm -rf $(N2O)

+ 24 - 0
apps/server/include/log.hrl

@@ -1,13 +1,37 @@
 -define(LOG(Format, Args, Level, Tags), error_logger:info_msg("~p:~p " ++ Format,[?MODULE,?LINE] ++ Args)).
 
+-define(LOGGER_STUB_3, fun(_,_,_) -> true end).
+-define(LOGGER_STUB_2, fun(_,_) -> true end).
+-define(LOGGER_STUB_1, fun(_) -> true end).
+
+
+-ifdef(SERVER_LOG_VERBOSE).
+-ifdef(SERVER_LOG_DEBUG).
+
 -define(DBG(Format, Args, Tag), ?LOG(Format, Args, ?debug, Tag)).
 -define(DBG(Format, Args),      ?DBG(Format, Args, [])).
 -define(DBG(Format),            ?DBG(Format, [])).
 
+-else. %% LOG_DEBUG
+
+-define(DBG(Format, Args, Tag), ?LOGGER_STUB_3(Format, Args, Tag)).
+-define(DBG(Format, Args),      ?LOGGER_STUB_2(Format, Args)).
+-define(DBG(Format),            ?LOGGER_STUB_1(Format)).
+
+-endif. %% LOG_DEBUG
+
 -define(INFO(Format, Args, Tag), ?LOG(Format, Args, ?info, Tag)).
 -define(INFO(Format, Args),      ?INFO(Format, Args, [])).
 -define(INFO(Format),            ?INFO(Format, [])).
 
+-else. %% LOG_VERBOSE
+
+-define(INFO(Format, Args, Tag), ?LOGGER_STUB_3(Format, Args, Tag)).
+-define(INFO(Format, Args),      ?LOGGER_STUB_2(Format, Args)).
+-define(INFO(Format),            ?LOGGER_STUB_1(Format)).
+
+-endif. %% LOG_VERBOSE
+
 -define(NOTICE(Format, Args, Tag), ?LOG(Format, Args, ?notice, Tag)).
 -define(NOTICE(Format, Args),      ?NOTICE(Format, Args, [])).
 -define(NOTICE(Format),            ?NOTICE(Format, [])).

+ 1 - 1
otp.mk

@@ -12,7 +12,7 @@ relx  := "{release,{$(RELEASE),\"$(VER)\"},[$(subst $(space),$(comma),$(APPS))]}
 test: eunit ct
 compile: get-deps static-link
 delete-deps get-deps compile clean update-deps:
-	rebar $@ skip_deps=true
+	rebar $(REBAR_D) $@ skip_deps=true
 .applist:
 	./depman.erl $(APPS) > $@
 $(RUN_DIR) $(LOG_DIR):