logger_support.h 3.34 KB
Newer Older
1
// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
2 3 4 5 6 7 8 9 10 11 12 13 14
//
// 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.

15 16
#ifndef LOGGER_SUPPORT_H
#define LOGGER_SUPPORT_H
17

Stephen Morris's avatar
Stephen Morris committed
18 19
#include <unistd.h>

20
#include <string>
21
#include <log/logger.h>
22 23
#include <log/logger_unittest_support.h>

24 25 26 27 28 29
/// \file
/// \brief Logging initialization functions
///
/// Contains a set of functions relating to logging initialization that are
/// used by the production code.

30 31 32
namespace isc {
namespace log {

33 34 35 36 37 38 39 40 41 42
/// \brief Is logging initialized?
///
/// As some underlying logging implementations can behave unpredictably if they
/// have not been initialized when a logging function is called, their
/// initialization state is tracked.  The logger functions will check this flag
/// and throw an exception if logging is not initialized at that point.
///
/// \return true if logging has been initialized, false if not
bool isLoggingInitialized();

43
/// \brief Set state of "logging initialized" flag
44 45 46 47 48
///
/// \param state State to set the flag to. (This is expected to be "true" - the
///        default - for all code apart from specific unit tests.)
void setLoggingInitialized(bool state = true);

49
/// \brief Run-time initialization
50
///
51
/// Performs run-time initialization of the logger in particular supplying:
52
///
53 54 55
/// - Name of the root logger
/// - The severity (and if applicable, debug level) for the root logger.
/// - Name of a local message file, containing localisation of message text.
56
///
57 58 59 60
/// This function is likely to change over time as more debugging options are
/// held in the configuration database.
///
/// \param root Name of the root logger
61
/// \param severity Severity at which to log
62
/// \param dbglevel Debug severity (ignored if "severity" is not "DEBUG")
63
/// \param file Name of the local message file.
64 65 66
/// \param buffer If true, all log messages will be buffered until one of
///        the \c process() methods is called. If false, initial logging
///        shall go to the default output (i.e. stdout)
Stephen Morris's avatar
Stephen Morris committed
67 68
void initLogger(const std::string& root,
                isc::log::Severity severity = isc::log::INFO,
69 70
                int dbglevel = 0, const char* file = NULL,
                bool buffer = false);
71

72 73 74 75 76 77 78 79 80 81 82
/// \brief Reset root logger characteristics
///
/// This is a simplified interface into the resetting of the characteristics
/// of the root logger.  It is aimed for use in unit tests and initial
/// phase of bring up before logging configuration is parsed and applied.
/// It uses KEA_LOGGER_DESTINATION environment variable to specify
/// logging destination.
/// @param verbose defines whether logging should be verbose or not
void setDefaultLoggingOutput(bool verbose = true);


83 84 85
} // namespace log
} // namespace isc

86
#endif // LOGGER_SUPPORT_H