mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Switches to the new build system (#87)
* Removes old build system * Removes old gmock * Adds new gmock * Moves source files to new locations * Adds new build system
This commit is contained in:
committed by
Peter Johnson
parent
9d45088127
commit
133540f577
68
src/main/native/cpp/Log.cpp
Normal file
68
src/main/native/cpp/Log.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "Log.h"
|
||||
|
||||
#include <cstdio>
|
||||
#ifdef _WIN32
|
||||
#include <cstdlib>
|
||||
#else
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <libgen.h>
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <libgen.h>
|
||||
#endif
|
||||
|
||||
using namespace cs;
|
||||
|
||||
ATOMIC_STATIC_INIT(Logger)
|
||||
|
||||
static void def_log_func(unsigned int level, const char* file,
|
||||
unsigned int line, const char* msg) {
|
||||
if (level == 20) {
|
||||
std::fprintf(stderr, "CS: %s\n", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
const char* levelmsg;
|
||||
if (level >= 50)
|
||||
levelmsg = "CRITICAL";
|
||||
else if (level >= 40)
|
||||
levelmsg = "ERROR";
|
||||
else if (level >= 30)
|
||||
levelmsg = "WARNING";
|
||||
else
|
||||
return;
|
||||
#ifdef _WIN32
|
||||
char fname[60];
|
||||
char ext[10];
|
||||
_splitpath_s(file, nullptr, 0, nullptr, 0, fname, 60, ext, 10);
|
||||
std::fprintf(stderr, "CS: %s: %s (%s%s:%d)\n", levelmsg, msg, fname, ext,
|
||||
line);
|
||||
#elif __APPLE__
|
||||
int len = strlen(msg) + 1;
|
||||
char* basestr = new char[len + 1];
|
||||
strncpy(basestr, file, len);
|
||||
std::fprintf(stderr, "CS: %s: %s (%s:%d)\n", levelmsg, msg, basename(basestr),
|
||||
line);
|
||||
delete[] basestr;
|
||||
#else
|
||||
std::fprintf(stderr, "CS: %s: %s (%s:%d)\n", levelmsg, msg, basename(file),
|
||||
line);
|
||||
#endif
|
||||
}
|
||||
|
||||
Logger::Logger() { SetDefaultLogger(); }
|
||||
|
||||
Logger::~Logger() {}
|
||||
|
||||
void Logger::SetDefaultLogger() { SetLogger(def_log_func); }
|
||||
Reference in New Issue
Block a user