Files
XPlaneConnectCSP/xpcPlugin/Log.h
Jason Watkins a2c1f83629 Refactored logging.
- Logging levels are now named preprocessor defines
 - Logging level is now a parameter for WriteLine/FormatLine
2015-05-11 14:51:47 -07:00

66 lines
2.2 KiB
C++

//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
//National Aeronautics and Space Administration. All Rights Reserved.
#ifndef XPCPLUGIN_LOG_H_
#define XPCPLUGIN_LOG_H_
#include <string>
// LOG_VERBOSITY determines the level of logging throughout the plugin.
// OFF: No logging at all will be performed.
// FATAL: Critical errors that would normally resulti in termination of the program. Because XPC
// operates in the X-Plane process, we try to never actually crash. As a result, we this
// level of logging may be the only indication of a problem.
// ERROR: All errors not covered by FATAL
// WARN: Potentially, but not definitely, incorrect behavior
// INFO: Information about normal actions taken by the plugin.
// DEBUG: More verbose information usefull for debugging.
// TRACE: Log all the things!
#define LOG_OFF 0
#define LOG_FATAL 1
#define LOG_ERROR 2
#define LOG_WARN 3
#define LOG_INFO 4
#define LOG_DEBUG 5
#define LOG_TRACE 6
#ifndef LOG_LEVEL
#define LOG_LEVEL LOG_ERROR
#endif
namespace XPC
{
/// Handles logging for the plugin.
///
/// \details Provides functions to write lines to the XPC log file.
/// \author Jason Watkins
/// \version 1.0
/// \since 1.0
/// \date Intial Version: 2015-04-09
/// \date Last Updated: 2015-04-09
class Log
{
public:
/// Initializes the logging component by deleting old log files,
/// writing header information to the log file.
static void Initialize(const std::string& header);
/// Closes the log file.
static void Close();
/// Writes the string pointed to by format, followed by a line
/// terminator to the XPC log file. If format contains format
/// specifiers, additional arguments following format will be formatted
/// and inserted in the resulting string, replacing their respective
/// specifiers.
///
/// \param format The format string appropriate for consumption by sprintf.
static void FormatLine(int level, const std::string& tag, const std::string& format, ...);
/// Writes the specified string value, followed by a line terminator
/// to the XPC log file.
///
/// \param value The value to write.
static void WriteLine(int level, const std::string& tag, const std::string& value);
};
}
#endif