Browse Source

Move asset::logPath to logger::path.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
30f814b7ae
5 changed files with 24 additions and 23 deletions
  1. +2
    -3
      include/asset.hpp
  2. +3
    -0
      include/logger.hpp
  3. +0
    -3
      src/asset.cpp
  4. +18
    -16
      src/logger.cpp
  5. +1
    -1
      standalone/main.cpp

+ 2
- 3
include/asset.hpp View File

@@ -37,13 +37,12 @@ std::string plugin(plugin::Plugin* plugin, std::string filename = "");
// Set these before calling init() to override the default paths // Set these before calling init() to override the default paths
extern std::string systemDir; extern std::string systemDir;
extern std::string userDir; extern std::string userDir;
// Only defined on Mac
extern std::string bundlePath;


extern std::string logPath;
extern std::string pluginsPath; extern std::string pluginsPath;
extern std::string settingsPath; extern std::string settingsPath;
extern std::string templatePath; extern std::string templatePath;
// Only defined on Mac
extern std::string bundlePath;




} // namespace asset } // namespace asset


+ 3
- 0
include/logger.hpp View File

@@ -23,6 +23,9 @@ namespace rack {
namespace logger { namespace logger {




extern std::string path;


enum Level { enum Level {
DEBUG_LEVEL, DEBUG_LEVEL,
INFO_LEVEL, INFO_LEVEL,


+ 0
- 3
src/asset.cpp View File

@@ -123,7 +123,6 @@ void init() {
templatePath = system::join(userDir, "template.vcv"); templatePath = system::join(userDir, "template.vcv");
} }
else { else {
logPath = system::join(userDir, "log.txt");
pluginsPath = system::join(userDir, "plugins-v" + ABI_VERSION); pluginsPath = system::join(userDir, "plugins-v" + ABI_VERSION);
settingsPath = system::join(userDir, "settings-v" + ABI_VERSION + ".json"); settingsPath = system::join(userDir, "settings-v" + ABI_VERSION + ".json");
templatePath = system::join(userDir, "template-v" + ABI_VERSION + ".vcv"); templatePath = system::join(userDir, "template-v" + ABI_VERSION + ".vcv");
@@ -150,10 +149,8 @@ std::string plugin(plugin::Plugin* plugin, std::string filename) {
std::string systemDir; std::string systemDir;
std::string userDir; std::string userDir;


std::string logPath;
std::string pluginsPath; std::string pluginsPath;
std::string settingsPath; std::string settingsPath;
std::string autosavePath;
std::string templatePath; std::string templatePath;
std::string bundlePath; std::string bundlePath;




+ 18
- 16
src/logger.cpp View File

@@ -3,6 +3,7 @@
#include <common.hpp> #include <common.hpp>
#include <asset.hpp> #include <asset.hpp>
#include <system.hpp> #include <system.hpp>
#include <settings.hpp>
// #include <unistd.h> // for dup2 // #include <unistd.h> // for dup2




@@ -10,24 +11,26 @@ namespace rack {
namespace logger { namespace logger {




std::string path;
static FILE* outputFile = NULL; static FILE* outputFile = NULL;
static double startTime = 0.0;
static std::mutex logMutex;
static std::mutex mutex;




void init() { void init() {
std::lock_guard<std::mutex> lock(logMutex);
startTime = system::getTime();
assert(!outputFile);
std::lock_guard<std::mutex> lock(mutex);

// Don't open a file in development mode. // Don't open a file in development mode.
if (asset::logPath.empty()) {
if (settings::devMode) {
outputFile = stderr; outputFile = stderr;
return;
} }
else {
path = asset::user("log.txt");


assert(!outputFile);
outputFile = std::fopen(asset::logPath.c_str(), "w");
if (!outputFile) {
std::fprintf(stderr, "Could not open log at %s\n", asset::logPath.c_str());
outputFile = std::fopen(path.c_str(), "w");
if (!outputFile) {
std::fprintf(stderr, "Could not open log at %s\n", path.c_str());
}
} }


// Redirect stdout and stderr to the file // Redirect stdout and stderr to the file
@@ -37,7 +40,7 @@ void init() {
} }


void destroy() { void destroy() {
std::lock_guard<std::mutex> lock(logMutex);
std::lock_guard<std::mutex> lock(mutex);
if (outputFile && outputFile != stderr) { if (outputFile && outputFile != stderr) {
// Print end token so we know if the logger exited cleanly. // Print end token so we know if the logger exited cleanly.
std::fprintf(outputFile, "END"); std::fprintf(outputFile, "END");
@@ -61,15 +64,14 @@ static const int levelColors[] = {
}; };


static void logVa(Level level, const char* filename, int line, const char* func, const char* format, va_list args) { static void logVa(Level level, const char* filename, int line, const char* func, const char* format, va_list args) {
std::lock_guard<std::mutex> lock(logMutex);
std::lock_guard<std::mutex> lock(mutex);
if (!outputFile) if (!outputFile)
return; return;


double nowTime = system::getTime(); double nowTime = system::getTime();
double duration = nowTime - startTime;
if (outputFile == stderr) if (outputFile == stderr)
std::fprintf(outputFile, "\x1B[%dm", levelColors[level]); std::fprintf(outputFile, "\x1B[%dm", levelColors[level]);
std::fprintf(outputFile, "[%.03f %s %s:%d %s] ", duration, levelLabels[level], filename, line, func);
std::fprintf(outputFile, "[%.03f %s %s:%d %s] ", nowTime, levelLabels[level], filename, line, func);
if (outputFile == stderr) if (outputFile == stderr)
std::fprintf(outputFile, "\x1B[0m"); std::fprintf(outputFile, "\x1B[0m");
std::vfprintf(outputFile, format, args); std::vfprintf(outputFile, format, args);
@@ -97,11 +99,11 @@ static bool fileEndsWith(FILE* file, std::string str) {
} }


bool isTruncated() { bool isTruncated() {
if (asset::logPath.empty())
if (path.empty())
return false; return false;


// Open existing log file // Open existing log file
FILE* file = std::fopen(asset::logPath.c_str(), "r");
FILE* file = std::fopen(path.c_str(), "r");
if (!file) if (!file)
return false; return false;
DEFER({std::fclose(file);}); DEFER({std::fclose(file);});


+ 1
- 1
standalone/main.cpp View File

@@ -49,7 +49,7 @@ static void fatalSignalHandler(int sig) {


// This might fail because we might not be in the main thread. // This might fail because we might not be in the main thread.
// But oh well, we're crashing anyway. // But oh well, we're crashing anyway.
std::string text = APP_NAME + " has crashed. See " + asset::logPath + " for details.";
std::string text = APP_NAME + " has crashed. See " + logger::path + " for details.";
osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, text.c_str()); osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, text.c_str());


abort(); abort();


Loading…
Cancel
Save