Files
XPlaneConnectCSP/xpcPlugin/Log.h
Jason Watkins d735e0f3ad Updated plugin logging.
- The plugin now keeps the log file open for the duration of its lifetime.
 - This greatly improves the performace of the logging component, which was previously a significant bottleneck even at low logging verbosity.
 - The log now prints timestamps to the millisecond.
2015-04-30 16:24:18 -07:00

63 lines
2.3 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 XPC_LOG_H
#define XPC_LOG_H
#include <string>
// LOG_VERBOSITY determines the level of logging throughout the plugin.
// 0: Minimum logging. Only plugin manager events will be logged.
// 1: Critical errors. When an error that prevents correct operation of the
// plugin, attempt to write useful information to the log. Note that since
// XPC runs inside the X-Plane executable, we try very hard no to crash.
// As a result, these log messages may be the only indication of failure.
// 2: All errors. Any time something unexpected happens, log it.
// 3: Significant actions. Any time something happens outside of normal
// command processing, log it.
// 5: Everything. Log nearly every single action the plugin takes. This may
// have a detrimental impact on X-Plane performance.
#define LOG_VERBOSITY 2
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(std::string header);
/// Closes the log file.
static void Close();
/// Writes the C 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(const char* 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(const std::string& value);
/// Writes the specified C string value, followed by a line terminator
/// to the XPC log file.
///
/// \param value The value to write.
static void WriteLine(const char* value);
};
}
#endif