2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
4
5/*
6 Contains functions / classes useful for logging runtime information
7*/
8
9#pragma once
10
11#include <cstdarg>
12#include <iostream>
13#include <string>
14
15#include "units/base.h"
16
17namespace argos_lib {
19 enum LogLevel { INFO, ERR };
20
23 public:
24 ArgosLogger() = delete;
25 explicit ArgosLogger(std::string tag) : m_tag{tag} {}
26
27 void Log(LogLevel level, const char* fmt, ...) const {
28 va_list lst;
29 va_start(lst, fmt);
30 switch (level) {
31 case LogLevel::INFO:
32 std::fprintf(stdout, "[%s]", m_tag.c_str());
33 std::vfprintf(stdout, fmt, lst);
34 break;
35
36 case LogLevel::ERR:
37 std::fprintf(stderr, "[%s_ERROR]", m_tag.c_str());
38 std::vfprintf(stderr, fmt, lst);
39 break;
40
41 default:
42 std::fprintf(stdout, "[%s]", m_tag.c_str());
43 std::vfprintf(stdout, fmt, lst);
44 break;
45 }
46 std::fprintf(stdout, "\n");
47 }
48
49 private:
50 std::string m_tag;
51 };
52} // namespace argos_lib
Log to the console in a clean, repeatable manner.
Definition log.h:22
std::string m_tag
Definition log.h:50
void Log(LogLevel level, const char *fmt,...) const
Definition log.h:27
ArgosLogger(std::string tag)
Definition log.h:25
Definition swap_controllers_command.h:12
LogLevel
Represents a log level of either information, or error.
Definition log.h:19
@ ERR
Definition log.h:19
@ INFO
Definition log.h:19