2016-09-05 12:00:36 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-08-25 17:48:06 -07:00
|
|
|
/* Copyright (c) 2016-2017 FIRST. All Rights Reserved. */
|
2016-09-05 12:00:36 -07:00
|
|
|
/* 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"
|
|
|
|
|
|
2017-09-07 00:16:26 -07:00
|
|
|
#include <llvm/Path.h>
|
|
|
|
|
#include <llvm/SmallString.h>
|
|
|
|
|
#include <llvm/StringRef.h>
|
|
|
|
|
#include <llvm/raw_ostream.h>
|
2016-09-05 12:00:36 -07:00
|
|
|
|
|
|
|
|
using namespace cs;
|
|
|
|
|
|
|
|
|
|
static void def_log_func(unsigned int level, const char* file,
|
|
|
|
|
unsigned int line, const char* msg) {
|
2017-09-07 00:16:26 -07:00
|
|
|
llvm::SmallString<128> buf;
|
|
|
|
|
llvm::raw_svector_ostream oss(buf);
|
2016-09-05 12:00:36 -07:00
|
|
|
if (level == 20) {
|
2017-09-07 00:16:26 -07:00
|
|
|
oss << "CS: " << msg << '\n';
|
|
|
|
|
llvm::errs() << oss.str();
|
2016-09-05 12:00:36 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 00:16:26 -07:00
|
|
|
llvm::StringRef levelmsg;
|
2016-09-05 12:00:36 -07:00
|
|
|
if (level >= 50)
|
2017-09-07 00:16:26 -07:00
|
|
|
levelmsg = "CRITICAL: ";
|
2016-09-05 12:00:36 -07:00
|
|
|
else if (level >= 40)
|
2017-09-07 00:16:26 -07:00
|
|
|
levelmsg = "ERROR: ";
|
2016-09-05 12:00:36 -07:00
|
|
|
else if (level >= 30)
|
2017-09-07 00:16:26 -07:00
|
|
|
levelmsg = "WARNING: ";
|
2016-09-05 12:00:36 -07:00
|
|
|
else
|
|
|
|
|
return;
|
2017-09-07 00:16:26 -07:00
|
|
|
oss << "CS: " << levelmsg << msg << " (" << llvm::sys::path::filename(file)
|
|
|
|
|
<< ':' << line << ")\n";
|
|
|
|
|
llvm::errs() << oss.str();
|
2016-09-05 12:00:36 -07:00
|
|
|
}
|
|
|
|
|
|
2017-02-17 01:12:16 -05:00
|
|
|
Logger::Logger() { SetDefaultLogger(); }
|
2016-09-05 12:00:36 -07:00
|
|
|
|
|
|
|
|
Logger::~Logger() {}
|
2017-02-17 01:12:16 -05:00
|
|
|
|
|
|
|
|
void Logger::SetDefaultLogger() { SetLogger(def_log_func); }
|