Add versioning to logs; add backtrace on crash; add automatic logging to a logfile every run
This commit is contained in:
parent
012f1cc1fc
commit
5946a08a79
26
Makefile
26
Makefile
|
@ -56,7 +56,12 @@ COMPINCLUDE = $(edirs)
|
||||||
|
|
||||||
WARNING_FLAGS = -Wno-everything #-Wno-incompatible-function-pointer-types -Wall -Wwrite-strings -Wunsupported -Wall -Wextra -Wwrite-strings -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -Wno-incompatible-function-pointer-types -Wno-gnu-statement-expression -Wno-complex-component-init -pedantic
|
WARNING_FLAGS = -Wno-everything #-Wno-incompatible-function-pointer-types -Wall -Wwrite-strings -Wunsupported -Wall -Wextra -Wwrite-strings -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -Wno-incompatible-function-pointer-types -Wno-gnu-statement-expression -Wno-complex-component-init -pedantic
|
||||||
|
|
||||||
COMPILER_FLAGS = $(includeflag) -I/usr/local/include -g -O0 -MD $(WARNING_FLAGS) -c $< -o $@
|
|
||||||
|
SEM = 0.0.1
|
||||||
|
COM != git rev-parse --short HEAD
|
||||||
|
VER = $(SEM)-$(COM)
|
||||||
|
|
||||||
|
COMPILER_FLAGS = $(includeflag) -I/usr/local/include -g -rdynamic -O0 -MD $(WARNING_FLAGS) -DDBG=1 -DVER=\"$(VER)\" -c $< -o $@
|
||||||
|
|
||||||
LIBPATH = -L./bin -L/usr/local/lib
|
LIBPATH = -L./bin -L/usr/local/lib
|
||||||
|
|
||||||
|
@ -69,7 +74,7 @@ ifeq ($(UNAME), Windows_NT)
|
||||||
CLIBS = glew32
|
CLIBS = glew32
|
||||||
EXT = .exe
|
EXT = .exe
|
||||||
else
|
else
|
||||||
LINKER_FLAGS = -g
|
LINKER_FLAGS = -g -rdynamic
|
||||||
ELIBS = engine pthread yughc mruby c m dl
|
ELIBS = engine pthread yughc mruby c m dl
|
||||||
CLIBS =
|
CLIBS =
|
||||||
EXT =
|
EXT =
|
||||||
|
@ -91,6 +96,9 @@ INCLUDE = $(BIN)include
|
||||||
|
|
||||||
LINK = $(LIBPATH) $(LINKER_FLAGS) $(LELIBS)
|
LINK = $(LIBPATH) $(LINKER_FLAGS) $(LELIBS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: yugine
|
.PHONY: yugine
|
||||||
|
|
||||||
yugine: $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE) $(BIN)libportaudio.a $(BIN)libglfw3.a
|
yugine: $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE) $(BIN)libportaudio.a $(BIN)libglfw3.a
|
||||||
|
@ -98,17 +106,17 @@ yugine: $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE) $(BIN)libportaudio.a $(BIN)lib
|
||||||
$(CC) $< $(LINK) -o yugine
|
$(CC) $< $(LINK) -o yugine
|
||||||
@echo Finished build
|
@echo Finished build
|
||||||
|
|
||||||
|
dist: yugine
|
||||||
|
mkdir -p bin/dist
|
||||||
|
cp yugine bin/dist
|
||||||
|
cp -rf assets/fonts bin/dist
|
||||||
|
cp -rf source/scripts bin/dist
|
||||||
|
cp -rf source/shaders bin/dist
|
||||||
|
tar -czf yugine-$(VER).tar.gz --directory bin/dist .
|
||||||
|
|
||||||
install: yugine
|
install: yugine
|
||||||
cp yugine ~/.local/bin
|
cp yugine ~/.local/bin
|
||||||
|
|
||||||
pin: yugine
|
|
||||||
cp yugine pinball
|
|
||||||
mkdir -p pinball/fonts pinball/scripts pinball/shaders
|
|
||||||
cp -f assets/fonts/* pinball/fonts
|
|
||||||
cp -f source/scripts/* pinball/scripts
|
|
||||||
cp -rf source/shaders/* pinball/shaders
|
|
||||||
|
|
||||||
$(ENGINE): $(eobjects)
|
$(ENGINE): $(eobjects)
|
||||||
@echo Making library engine.a
|
@echo Making library engine.a
|
||||||
@ar r $(ENGINE) $(eobjects)
|
@ar r $(ENGINE) $(eobjects)
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define logLevel 0
|
#define logLevel 0
|
||||||
|
|
||||||
|
@ -13,6 +12,8 @@
|
||||||
char *logstr[] = { "INFO", "WARN", "ERROR", "CRITICAL" };
|
char *logstr[] = { "INFO", "WARN", "ERROR", "CRITICAL" };
|
||||||
char *catstr[] = {"ENGINE"};
|
char *catstr[] = {"ENGINE"};
|
||||||
|
|
||||||
|
FILE *fout = NULL;
|
||||||
|
|
||||||
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
||||||
{
|
{
|
||||||
if (priority >= logLevel) {
|
if (priority >= logLevel) {
|
||||||
|
@ -31,6 +32,25 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
||||||
|
|
||||||
printf("%s", buffer);
|
printf("%s", buffer);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
|
if (fout) {
|
||||||
|
fprintf(fout, "%s", buffer);
|
||||||
|
fflush(fout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_setfile(char *file) {
|
||||||
|
YughInfo("Opening output log %s.", file);
|
||||||
|
fout = fopen(file, "w");
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_cat(FILE *f) {
|
||||||
|
char out[1024];
|
||||||
|
|
||||||
|
while (fgets(out, sizeof(out), f)) {
|
||||||
|
out[strcspn(out, "\n")] = '\0';
|
||||||
|
YughInfo(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef LOG_H
|
#ifndef LOG_H
|
||||||
#define LOG_H
|
#define LOG_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define ERROR_BUFFER 2048
|
#define ERROR_BUFFER 2048
|
||||||
|
|
||||||
#define LOG_INFO 0
|
#define LOG_INFO 0
|
||||||
|
@ -20,4 +22,7 @@ void FlushGLErrors();
|
||||||
|
|
||||||
int TestSDLError(int sdlErr);
|
int TestSDLError(int sdlErr);
|
||||||
|
|
||||||
|
void log_setfile(char *file);
|
||||||
|
void log_cat(FILE *f);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,6 +7,12 @@
|
||||||
#include "script.h"
|
#include "script.h"
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <execinfo.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
|
@ -22,19 +28,78 @@ double updateMS = 1/60.f;
|
||||||
|
|
||||||
static int ed = 1;
|
static int ed = 1;
|
||||||
|
|
||||||
|
void seghandle(int sig) {
|
||||||
|
void *ents[512];
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
size = backtrace(ents, 512);
|
||||||
|
if (strsignal(sig)) {
|
||||||
|
YughCritical("CRASH! Signal: %s.", strsignal(sig));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
YughCritical("CRASH! Signal: %d.", sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
YughCritical("====================BACKTRACE====================");
|
||||||
|
char **stackstr = backtrace_symbols(ents, size);
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
YughCritical(stackstr[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **args) {
|
int main(int argc, char **args) {
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (args[i][0] == '-') {
|
if (args[i][0] == '-') {
|
||||||
if (strncmp(&args[i][1], "play", 4) == 0) {
|
switch(args[i][1]) {
|
||||||
|
case 'p':
|
||||||
|
if (strncmp(&args[i][2], "lay", 3))
|
||||||
|
continue;
|
||||||
|
|
||||||
ed = 0;
|
ed = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
if (i+1 < argc && args[i+1][0] != '-') {
|
||||||
|
log_setfile(args[i+1]);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
YughError("Expected a file for command line arg '-l'.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DBG) {
|
||||||
|
time_t now = time(NULL);
|
||||||
|
char fname[100];
|
||||||
|
snprintf(fname, 100, "yugine-%d.log", now);
|
||||||
|
log_setfile(fname);
|
||||||
|
}
|
||||||
|
|
||||||
|
YughInfo("Starting yugine version %s.", VER);
|
||||||
|
|
||||||
|
signal(SIGSEGV, seghandle);
|
||||||
|
|
||||||
|
FILE *sysinfo = NULL;
|
||||||
|
sysinfo = popen("uname -a", "r");
|
||||||
|
if (!sysinfo) {
|
||||||
|
YughWarn("Failed to get sys info.");
|
||||||
|
} else {
|
||||||
|
log_cat(sysinfo);
|
||||||
|
pclose(sysinfo);
|
||||||
|
}
|
||||||
|
|
||||||
engine_init();
|
engine_init();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const GLFWvidmode *vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
const GLFWvidmode *vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
YughInfo("Refresh rate is %d", vidmode->refreshRate);
|
YughInfo("Refresh rate is %d", vidmode->refreshRate);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue