SubZero Common
Common library components for an FRC CommandRobot
Loading...
Searching...
No Matches
ConsoleLogger.h
Go to the documentation of this file.
1#ifndef CONSOLE_LOGGER_H
2#define CONSOLE_LOGGER_H
3
4#include <iostream>
5#include <string>
6
8
9namespace subzero {
16public:
18 static ConsoleLogger instance;
19
20 return instance;
21 }
22
23 void logVerbose(std::string key, const std::string format, ...) override;
24 void logInfo(std::string key, const std::string format, ...) override;
25 void logWarning(std::string key, const std::string format, ...) override;
26 void logError(std::string key, const std::string format, ...) override;
27 void logFatal(std::string key, const std::string format, ...) override;
28
29 void logInfo(std::string key, int val) override;
30 void logVerbose(std::string key, int val) override;
31 void logWarning(std::string key, int val) override;
32 void logError(std::string key, int val) override;
33 void logFatal(std::string key, int val) override;
34
35 void logInfo(std::string key, double val) override;
36 void logVerbose(std::string key, double val) override;
37 void logWarning(std::string key, double val) override;
38 void logError(std::string key, double val) override;
39 void logFatal(std::string key, double val) override;
40
41 void logInfo(std::string key, bool val) override;
42 void logVerbose(std::string key, bool val) override;
43 void logWarning(std::string key, bool val) override;
44 void logError(std::string key, bool val) override;
45 void logFatal(std::string key, bool val) override;
46
47 void logInfo(std::string key, frc::Pose2d &val) override;
48 void logVerbose(std::string key, frc::Pose2d &val) override;
49 void logWarning(std::string key, frc::Pose2d &val) override;
50 void logError(std::string key, frc::Pose2d &val) override;
51 void logFatal(std::string key, frc::Pose2d &val) override;
52
53 void logInfo(std::string key, wpi::Sendable *val) override;
54 void logVerbose(std::string key, wpi::Sendable *val) override;
55 void logWarning(std::string key, wpi::Sendable *val) override;
56 void logError(std::string key, wpi::Sendable *val) override;
57 void logFatal(std::string key, wpi::Sendable *val) override;
58
59private:
61
62 void log(Logging::Level level, std::string key, std::string fmt, va_list ap) {
63 if (!shouldLog(level))
64 return;
65
66 std::string val = formatString(fmt, ap);
67 std::cout << levelToString(level) << " - " << key << ": " << val
68 << std::endl;
69 }
70};
71} // namespace subzero
72
73#define ConsoleWriter subzero::ConsoleLogger::getInstance()
79#define ConsoleInfo(key, fmt, ...) \
80 frc2::InstantCommand([] { \
81 ConsoleWriter.logInfo(key, fmt, __VA_ARGS__); \
82 }).ToPtr()
88#define ConsoleVerbose(key, fmt, ...) \
89 frc2::InstantCommand([] { \
90 ConsoleWriter.logVerbose(key, fmt, __VA_ARGS__); \
91 }).ToPtr()
92#endif
Outputs formatted strings to stdout.
void logError(std::string key, const std::string format,...) override
void logFatal(std::string key, bool val) override
void logFatal(std::string key, wpi::Sendable *val) override
void logVerbose(std::string key, double val) override
void logInfo(std::string key, const std::string format,...) override
void logVerbose(std::string key, bool val) override
void logVerbose(std::string key, wpi::Sendable *val) override
void logWarning(std::string key, int val) override
void logFatal(std::string key, const std::string format,...) override
void logInfo(std::string key, double val) override
void logWarning(std::string key, wpi::Sendable *val) override
void logInfo(std::string key, frc::Pose2d &val) override
void logFatal(std::string key, double val) override
void logWarning(std::string key, bool val) override
void logError(std::string key, frc::Pose2d &val) override
void logWarning(std::string key, frc::Pose2d &val) override
void logVerbose(std::string key, int val) override
void logVerbose(std::string key, frc::Pose2d &val) override
void logError(std::string key, bool val) override
void logError(std::string key, int val) override
void logWarning(std::string key, const std::string format,...) override
static ConsoleLogger & getInstance()
void logFatal(std::string key, frc::Pose2d &val) override
void logFatal(std::string key, int val) override
void logInfo(std::string key, wpi::Sendable *val) override
void logError(std::string key, wpi::Sendable *val) override
void logInfo(std::string key, bool val) override
void logError(std::string key, double val) override
void logWarning(std::string key, double val) override
void logInfo(std::string key, int val) override
void logVerbose(std::string key, const std::string format,...) override
Logger interface.
Definition ILogger.h:19
bool shouldLog(Logging::Level level)
Definition ILogger.h:97
std::string levelToString(Logging::Level level) const
Definition ILogger.h:64
std::string formatString(const std::string format, va_list ap)
Definition ILogger.h:83
Level
Levels of logging.