-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #566 from mkilgore/logging-changes-2
Add built-in logging support and other fixes
- Loading branch information
Showing
40 changed files
with
1,913 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
#include "qbs.h" | ||
|
||
enum class loglevel { | ||
Trace, | ||
Information, | ||
Warning, | ||
Error, | ||
}; | ||
|
||
enum class logscope { | ||
Runtime, | ||
QB64, | ||
Libqb, | ||
Audio, | ||
Image, | ||
|
||
Count, | ||
}; | ||
|
||
void libqb_log_init(); | ||
void libqb_log(loglevel lvl, logscope scope, const char *file, const char *func, int line, const char *fmt, ...); | ||
void libqb_log_qb64(loglevel lvl, logscope scope, const char *file, const char *func, int line, const char *fmt, ...); | ||
void libqb_log_qbs(loglevel lvl, logscope scope, const char *file, const char *func, int line, qbs *str); | ||
|
||
// Returns 1 to 4, indicating a min level of Trace to Error | ||
uint32_t func__logminlevel(); | ||
|
||
|
||
#define libqb_log_with_scope_trace(scope, fmt, ...) \ | ||
libqb_log(loglevel::Trace, (scope), __FILE__, __func__, __LINE__, fmt, ## __VA_ARGS__) | ||
|
||
#define libqb_log_with_scope_info(scope, fmt, ...) \ | ||
libqb_log(loglevel::Information, (scope), __FILE__, __func__, __LINE__, fmt, ## __VA_ARGS__) | ||
|
||
#define libqb_log_with_scope_warn(scope, fmt, ...) \ | ||
libqb_log(loglevel::Warning, (scope), __FILE__, __func__, __LINE__, fmt, ## __VA_ARGS__) | ||
|
||
#define libqb_log_with_scope_error(scope, fmt, ...) \ | ||
libqb_log(loglevel::Error, (scope), __FILE__, __func__, __LINE__, fmt, ## __VA_ARGS__) | ||
|
||
|
||
#define libqb_log_trace(...) \ | ||
libqb_log_with_scope_trace(logscope::Libqb, __VA_ARGS__) | ||
|
||
#define libqb_log_info(...) \ | ||
libqb_log_with_scope_info(logscope::Libqb, __VA_ARGS__) | ||
|
||
#define libqb_log_warn(...) \ | ||
libqb_log_with_scope_warn(logscope::Libqb, __VA_ARGS__) | ||
|
||
#define libqb_log_error(...) \ | ||
libqb_log_with_scope_error(logscope::Libqb, __VA_ARGS__) | ||
|
||
|
||
#define sub__logtrace(file, func, line, qbs) \ | ||
libqb_log_qbs(loglevel::Trace, logscope::QB64, file, func, line, (qbs)) | ||
|
||
#define sub__loginfo(file, func, line, qbs) \ | ||
libqb_log_qbs(loglevel::Information, logscope::QB64, file, func, line, (qbs)) | ||
|
||
#define sub__logwarn(file, func, line, qbs) \ | ||
libqb_log_qbs(loglevel::Warning, logscope::QB64, file, func, line, (qbs)) | ||
|
||
#define sub__logerror(file, func, line, qbs) \ | ||
libqb_log_qbs(loglevel::Error, logscope::QB64, file, func, line, (qbs)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
#include "libqb-common.h" | ||
|
||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <string> | ||
#include <cstring> | ||
#include <stdio.h> | ||
|
||
#include "logging.h" | ||
#include "../logging_private.h" | ||
|
||
void fp_log_writer::write(struct log_entry *entry) { | ||
if (!fp) | ||
return; | ||
|
||
const char *scope = logScopeName(entry->scope); | ||
|
||
// The main code may not have a file associated with it when compiled from | ||
// the IDE | ||
if (entry->file && *entry->file) | ||
fprintf(fp, "[%0.5lf] %s %s %s: %s: %d: %s\n", | ||
entry->timestamp, | ||
logLevelName(entry->level), | ||
scope? scope: "", | ||
entry->file, | ||
entry->func.c_str(), | ||
entry->line, | ||
entry->message.c_str()); | ||
else | ||
fprintf(fp, "[%0.5lf] %s %s %s: %d: %s\n", | ||
entry->timestamp, | ||
logLevelName(entry->level), | ||
scope? scope: "", | ||
entry->func.c_str(), | ||
entry->line, | ||
entry->message.c_str()); | ||
|
||
if (entry->stacktrace != "") | ||
fprintf(fp, "%s", entry->stacktrace.c_str()); | ||
} | ||
|
||
console_log_handler::console_log_handler() { | ||
fp = stderr; | ||
} | ||
|
||
file_log_handler::file_log_handler() { | ||
const char *filepath = getenv("QB64PE_LOG_FILE_PATH"); | ||
|
||
fp = fopen(filepath, "a"); | ||
if (!fp) | ||
fprintf(stderr, "Unable to open file '%s' for logging!", filepath); | ||
} |
Oops, something went wrong.