Commit b6d140b6 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

[trac901] Convenience macros

parent eab5008d
......@@ -22,6 +22,7 @@ liblog_la_SOURCES += message_reader.cc message_reader.h
liblog_la_SOURCES += message_types.h
liblog_la_SOURCES += root_logger_name.cc root_logger_name.h
liblog_la_SOURCES += log_formatter.h log_formatter.cc
liblog_la_SOURCES += macros.h
EXTRA_DIST = README
EXTRA_DIST += messagedef.mes
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef __LOG_MACROS_H
#define __LOG_MACROS_H
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE) \
if (!(LOGGER).isDebugEnabled((LEVEL))) { \
} else \
(LOGGER).debug((LEVEL), (MESSAGE))
#define LOG_INFO(LOGGER, MESSAGE) \
if (!(LOGGER).isInfoEnabled()) { \
} else \
(LOGGER).info((MESSAGE))
#define LOG_WARN(LOGGER, MESSAGE) \
if (!(LOGGER).isWarnEnabled()) { \
} else \
(LOGGER).warn((MESSAGE))
#define LOG_ERROR(LOGGER, MESSAGE) \
if (!(LOGGER).isErrorEnabled()) { \
} else \
(LOGGER).error((MESSAGE))
#define LOG_FATAL(LOGGER, MESSAGE) \
if (!(LOGGER).isFatalEnabled()) { \
} else \
(LOGGER).fatal((MESSAGE))
#endif
......@@ -23,6 +23,7 @@
#include <iostream>
#include <log/logger.h>
#include <log/macros.h>
#include <log/logger_support.h>
#include <log/root_logger_name.h>
......@@ -92,13 +93,13 @@ int main(int argc, char** argv) {
initLogger("alpha", severity, dbglevel, localfile);
// Log a few messages
logger_ex.fatal(MSG_MSGWRTERR).arg("test1").arg("42");
logger_ex.error(MSG_UNRECDIR).arg("false");
logger_dlm.warn(MSG_MSGRDERR).arg("a.txt").arg("dummy test");
logger_dlm.info(MSG_OPNMSGIN).arg("example.msg").arg("dummy test");
logger_ex.debug(0, MSG_UNRECDIR).arg("[abc]");
logger_ex.debug(24, MSG_UNRECDIR).arg("[24]");
logger_ex.debug(25, MSG_UNRECDIR).arg("[25]");
logger_ex.debug(26, MSG_UNRECDIR).arg("[26]");
LOG_FATAL(logger_ex, MSG_MSGWRTERR).arg("test1").arg("42");
LOG_ERROR(logger_ex, MSG_UNRECDIR).arg("false");
LOG_WARN(logger_dlm, MSG_MSGRDERR).arg("a.txt").arg("dummy test");
LOG_INFO(logger_dlm, MSG_OPNMSGIN).arg("example.msg").arg("dummy test");
LOG_DEBUG(logger_ex, 0, MSG_UNRECDIR).arg("[abc]");
LOG_DEBUG(logger_ex, 24, MSG_UNRECDIR).arg("[24]");
LOG_DEBUG(logger_ex, 25, MSG_UNRECDIR).arg("[25]");
LOG_DEBUG(logger_ex, 26, MSG_UNRECDIR).arg("[26]");
return (0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment