Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
Created July 26, 2011 14:23
Show Gist options
  • Select an option

  • Save leandrosilva/1106877 to your computer and use it in GitHub Desktop.

Select an option

Save leandrosilva/1106877 to your computer and use it in GitHub Desktop.
erlang_syslog configuration based on log level
%%
%% erlang_syslog
%% https://github.com/JacobVorreuter/erlang_syslog
%%
%% erlc -D log_info awesome_module.erl
%%
-ifdef(log_debug).
-define(DEBUG(Msg), erlang:apply(syslog, debug, [cameron_syslog, Msg])).
-define(DEBUG(Msg, Args), erlang:apply(syslog, debug, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(INFO(Msg), erlang:apply(syslog, info, [cameron_syslog, Msg])).
-define(INFO(Msg, Args), erlang:apply(syslog, info, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(NOTICE(Msg), erlang:apply(syslog, notice, [cameron_syslog, Msg])).
-define(NOTICE(Msg, Args), erlang:apply(syslog, notice, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(WARNING(Msg), erlang:apply(syslog, warning, [cameron_syslog, Msg])).
-define(WARNING(Msg, Args), erlang:apply(syslog, warning, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ERROR(Msg), erlang:apply(syslog, error, [cameron_syslog, Msg])).
-define(ERROR(Msg, Args), erlang:apply(syslog, error, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(CRITICAL(Msg), erlang:apply(syslog, critical, [cameron_syslog, Msg])).
-define(CRITICAL(Msg, Args), erlang:apply(syslog, critical, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ALERT(Msg), erlang:apply(syslog, alert, [cameron_syslog, Msg])).
-define(ALERT(Msg, Args), erlang:apply(syslog, alert, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(EMERGENCY(Msg), erlang:apply(syslog, emergency, [cameron_syslog, Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(syslog, emergency, [cameron_syslog, io_lib:format(Msg, Args)])).
-else.
-ifdef(log_info).
-define(DEBUG(Msg), ok).
-define(DEBUG(Msg, Args), ok).
-define(INFO(Msg), erlang:apply(syslog, info, [cameron_syslog, Msg])).
-define(INFO(Msg, Args), erlang:apply(syslog, info, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(NOTICE(Msg), erlang:apply(syslog, notice, [cameron_syslog, Msg])).
-define(NOTICE(Msg, Args), erlang:apply(syslog, notice, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(WARNING(Msg), erlang:apply(syslog, warning, [cameron_syslog, Msg])).
-define(WARNING(Msg, Args), erlang:apply(syslog, warning, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ERROR(Msg), erlang:apply(syslog, error, [cameron_syslog, Msg])).
-define(ERROR(Msg, Args), erlang:apply(syslog, error, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(CRITICAL(Msg), erlang:apply(syslog, critical, [cameron_syslog, Msg])).
-define(CRITICAL(Msg, Args), erlang:apply(syslog, critical, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ALERT(Msg), erlang:apply(syslog, alert, [cameron_syslog, Msg])).
-define(ALERT(Msg, Args), erlang:apply(syslog, alert, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(EMERGENCY(Msg), erlang:apply(syslog, emergency, [cameron_syslog, Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(syslog, emergency, [cameron_syslog, io_lib:format(Msg, Args)])).
-else.
-ifdef(log_notice).
-define(DEBUG(Msg), ok).
-define(DEBUG(Msg, Args), ok).
-define(INFO(Msg), ok).
-define(INFO(Msg, Args), ok).
-define(NOTICE(Msg), erlang:apply(syslog, notice, [cameron_syslog, Msg])).
-define(NOTICE(Msg, Args), erlang:apply(syslog, notice, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(WARNING(Msg), erlang:apply(syslog, warning, [cameron_syslog, Msg])).
-define(WARNING(Msg, Args), erlang:apply(syslog, warning, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ERROR(Msg), erlang:apply(syslog, error, [cameron_syslog, Msg])).
-define(ERROR(Msg, Args), erlang:apply(syslog, error, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(CRITICAL(Msg), erlang:apply(syslog, critical, [cameron_syslog, Msg])).
-define(CRITICAL(Msg, Args), erlang:apply(syslog, critical, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ALERT(Msg), erlang:apply(syslog, alert, [cameron_syslog, Msg])).
-define(ALERT(Msg, Args), erlang:apply(syslog, alert, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(EMERGENCY(Msg), erlang:apply(syslog, emergency, [cameron_syslog, Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(syslog, emergency, [cameron_syslog, io_lib:format(Msg, Args)])).
-else.
-ifdef(log_warning).
-define(DEBUG(Msg), ok).
-define(DEBUG(Msg, Args), ok).
-define(INFO(Msg), ok).
-define(INFO(Msg, Args), ok).
-define(NOTICE(Msg), ok).
-define(NOTICE(Msg, Args), ok).
-define(WARNING(Msg), erlang:apply(syslog, warning, [cameron_syslog, Msg])).
-define(WARNING(Msg, Args), erlang:apply(syslog, warning, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ERROR(Msg), erlang:apply(syslog, error, [cameron_syslog, Msg])).
-define(ERROR(Msg, Args), erlang:apply(syslog, error, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(CRITICAL(Msg), erlang:apply(syslog, critical, [cameron_syslog, Msg])).
-define(CRITICAL(Msg, Args), erlang:apply(syslog, critical, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ALERT(Msg), erlang:apply(syslog, alert, [cameron_syslog, Msg])).
-define(ALERT(Msg, Args), erlang:apply(syslog, alert, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(EMERGENCY(Msg), erlang:apply(syslog, emergency, [cameron_syslog, Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(syslog, emergency, [cameron_syslog, io_lib:format(Msg, Args)])).
-else.
-ifdef(log_error).
-define(DEBUG(Msg), ok).
-define(DEBUG(Msg, Args), ok).
-define(INFO(Msg), ok).
-define(INFO(Msg, Args), ok).
-define(NOTICE(Msg), ok).
-define(NOTICE(Msg, Args), ok).
-define(WARNING(Msg), ok).
-define(WARNING(Msg, Args), ok).
-define(ERROR(Msg), erlang:apply(syslog, error, [cameron_syslog, Msg])).
-define(ERROR(Msg, Args), erlang:apply(syslog, error, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(CRITICAL(Msg), erlang:apply(syslog, critical, [cameron_syslog, Msg])).
-define(CRITICAL(Msg, Args), erlang:apply(syslog, critical, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ALERT(Msg), erlang:apply(syslog, alert, [cameron_syslog, Msg])).
-define(ALERT(Msg, Args), erlang:apply(syslog, alert, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(EMERGENCY(Msg), erlang:apply(syslog, emergency, [cameron_syslog, Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(syslog, emergency, [cameron_syslog, io_lib:format(Msg, Args)])).
-else.
-ifdef(log_critical).
-define(DEBUG(Msg), ok).
-define(DEBUG(Msg, Args), ok).
-define(INFO(Msg), ok).
-define(INFO(Msg, Args), ok).
-define(NOTICE(Msg), ok).
-define(NOTICE(Msg, Args), ok).
-define(WARNING(Msg), ok).
-define(WARNING(Msg, Args), ok).
-define(ERROR(Msg), ok).
-define(ERROR(Msg, Args), ok).
-define(CRITICAL(Msg), erlang:apply(syslog, critical, [cameron_syslog, Msg])).
-define(CRITICAL(Msg, Args), erlang:apply(syslog, critical, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ALERT(Msg), erlang:apply(syslog, alert, [cameron_syslog, Msg])).
-define(ALERT(Msg, Args), erlang:apply(syslog, alert, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(EMERGENCY(Msg), erlang:apply(syslog, emergency, [cameron_syslog, Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(syslog, emergency, [cameron_syslog, io_lib:format(Msg, Args)])).
-else.
-ifdef(log_alert).
-define(DEBUG(Msg), ok).
-define(DEBUG(Msg, Args), ok).
-define(INFO(Msg), ok).
-define(INFO(Msg, Args), ok).
-define(NOTICE(Msg), ok).
-define(NOTICE(Msg, Args), ok).
-define(WARNING(Msg), ok).
-define(WARNING(Msg, Args), ok).
-define(ERROR(Msg), ok).
-define(ERROR(Msg, Args), ok).
-define(CRITICAL(Msg), ok).
-define(CRITICAL(Msg, Args), ok).
-define(ALERT(Msg), erlang:apply(syslog, alert, [cameron_syslog, Msg])).
-define(ALERT(Msg, Args), erlang:apply(syslog, alert, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(EMERGENCY(Msg), erlang:apply(syslog, emergency, [cameron_syslog, Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(syslog, emergency, [cameron_syslog, io_lib:format(Msg, Args)])).
-else.
-ifdef(log_emergency).
-define(DEBUG(Msg), ok).
-define(DEBUG(Msg, Args), ok).
-define(INFO(Msg), ok).
-define(INFO(Msg, Args), ok).
-define(NOTICE(Msg), ok).
-define(NOTICE(Msg, Args), ok).
-define(WARNING(Msg), ok).
-define(WARNING(Msg, Args), ok).
-define(ERROR(Msg), ok).
-define(ERROR(Msg, Args), ok).
-define(CRITICAL(Msg), ok).
-define(CRITICAL(Msg, Args), ok).
-define(ALERT(Msg), ok).
-define(ALERT(Msg, Args), ok).
-define(EMERGENCY(Msg), erlang:apply(syslog, emergency, [cameron_syslog, Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(syslog, emergency, [cameron_syslog, io_lib:format(Msg, Args)])).
-else.
-define(DEBUG(Msg), ok).
-define(DEBUG(Msg, Args), ok).
-define(INFO(Msg), ok).
-define(INFO(Msg, Args), ok).
-define(NOTICE(Msg), ok).
-define(NOTICE(Msg, Args), ok).
-define(WARNING(Msg), ok).
-define(WARNING(Msg, Args), ok).
-define(ERROR(Msg), erlang:apply(syslog, error, [cameron_syslog, Msg])).
-define(ERROR(Msg, Args), erlang:apply(syslog, error, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(CRITICAL(Msg), erlang:apply(syslog, critical, [cameron_syslog, Msg])).
-define(CRITICAL(Msg, Args), erlang:apply(syslog, critical, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ALERT(Msg), erlang:apply(syslog, alert, [cameron_syslog, Msg])).
-define(ALERT(Msg, Args), erlang:apply(syslog, alert, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(EMERGENCY(Msg), erlang:apply(syslog, emergency, [cameron_syslog, Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(syslog, emergency, [cameron_syslog, io_lib:format(Msg, Args)])).
-endif.
-endif.
-endif.
-endif.
-endif.
-endif.
-endif.
-endif.
%%
%% erlang_syslog
%% https://github.com/JacobVorreuter/erlang_syslog
%%
%% erlc -D use_syslog awesome_module.erl
%%
-ifdef(use_syslog).
-define(DEBUG(Msg), erlang:apply(syslog, debug, [cameron_syslog, Msg])).
-define(DEBUG(Msg, Args), erlang:apply(syslog, debug, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(INFO(Msg), erlang:apply(syslog, info, [cameron_syslog, Msg])).
-define(INFO(Msg, Args), erlang:apply(syslog, info, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(NOTICE(Msg), erlang:apply(syslog, notice, [cameron_syslog, Msg])).
-define(NOTICE(Msg, Args), erlang:apply(syslog, notice, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(WARNING(Msg), erlang:apply(syslog, warning, [cameron_syslog, Msg])).
-define(WARNING(Msg, Args), erlang:apply(syslog, warning, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ERROR(Msg), erlang:apply(syslog, error, [cameron_syslog, Msg])).
-define(ERROR(Msg, Args), erlang:apply(syslog, error, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(CRITICAL(Msg), erlang:apply(syslog, critical, [cameron_syslog, Msg])).
-define(CRITICAL(Msg, Args), erlang:apply(syslog, critical, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(ALERT(Msg), erlang:apply(syslog, alert, [cameron_syslog, Msg])).
-define(ALERT(Msg, Args), erlang:apply(syslog, alert, [cameron_syslog, io_lib:format(Msg, Args)])).
-define(EMERGENCY(Msg), erlang:apply(syslog, emergency, [cameron_syslog, Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(syslog, emergency, [cameron_syslog, io_lib:format(Msg, Args)])).
-else.
-define(DEBUG(Msg), erlang:apply(io, format, ["[DEBUG] " ++ Msg])).
-define(DEBUG(Msg, Args), erlang:apply(io, format, ["[DEBUG] " ++ Msg, Args])).
-define(INFO(Msg), erlang:apply(io, format, ["[INFO] " ++ Msg])).
-define(INFO(Msg, Args), erlang:apply(io, format, ["[INFO] " ++ Msg, Args])).
-define(NOTICE(Msg), erlang:apply(io, format, ["[NOTICE] " ++ Msg])).
-define(NOTICE(Msg, Args), erlang:apply(io, format, ["[NOTICE] " ++ Msg, Args])).
-define(WARNING(Msg), erlang:apply(io, format, ["[WARNING] " ++ Msg])).
-define(WARNING(Msg, Args), erlang:apply(io, format, ["[WARNING] " ++ Msg, Args])).
-define(ERROR(Msg), erlang:apply(io, format, ["[ERROR] " ++ Msg])).
-define(ERROR(Msg, Args), erlang:apply(io, format, ["[ERROR] " ++ Msg, Args])).
-define(CRITICAL(Msg), erlang:apply(io, format, ["[CRITICAL] " ++ Msg])).
-define(CRITICAL(Msg, Args), erlang:apply(io, format, ["[CRITICAL] " ++ Msg, Args])).
-define(ALERT(Msg), erlang:apply(io, format, ["[ALERT] " ++ Msg])).
-define(ALERT(Msg, Args), erlang:apply(io, format, ["[ALERT] " ++ Msg, Args])).
-define(EMERGENCY(Msg), erlang:apply(io, format, ["[EMERGENCY] " ++ Msg])).
-define(EMERGENCY(Msg, Args), erlang:apply(io, format, ["[EMERGENCY] " ++ Msg, Args])).
-endif.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment