debug logging with color, small logging
This commit is contained in:
parent
48b0a4b7d9
commit
90e2de5ed9
|
@ -30,6 +30,7 @@ public:
|
||||||
virtual std::map<std::string, eventfptr> getEvents();
|
virtual std::map<std::string, eventfptr> getEvents();
|
||||||
virtual ~CppPlugin();
|
virtual ~CppPlugin();
|
||||||
void printStacktrace();
|
void printStacktrace();
|
||||||
|
void log(std::string msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool registerCmd(JNIEnv* env, CppPlugin* plugin, std::string& cname, cmdfptr function);
|
bool registerCmd(JNIEnv* env, CppPlugin* plugin, std::string& cname, cmdfptr function);
|
||||||
|
|
|
@ -59,7 +59,7 @@ void Event::reapply(JNIEnv* env, jobject jevent) {
|
||||||
env->CallObjectMethod(map, MAPCLEAR);
|
env->CallObjectMethod(map, MAPCLEAR);
|
||||||
|
|
||||||
for(auto it : data) {
|
for(auto it : data) {
|
||||||
std::cout << "write back to java: " << it.first << " Value: " << it.second << std::endl;
|
DEB(CYELLOW << "write back to java: " << it.first << " Value: " << CGREEN<< it.second);
|
||||||
jstring key = env->NewStringUTF(it.first.c_str());
|
jstring key = env->NewStringUTF(it.first.c_str());
|
||||||
|
|
||||||
env->CallObjectMethod(map, MAPPUT, key, it.second);
|
env->CallObjectMethod(map, MAPPUT, key, it.second);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <execinfo.h> //backtrace
|
#include <execinfo.h> //backtrace
|
||||||
|
#include <time.h> //time logging
|
||||||
|
#include <stdio.h> //snprintf for time logging
|
||||||
|
|
||||||
#define STACKTRACEBUFFER 100
|
#define STACKTRACEBUFFER 100
|
||||||
|
|
||||||
|
@ -51,4 +53,18 @@ void CppPlugin::printStacktrace() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppPlugin::log(std::string msg) {
|
||||||
|
//create time stamp
|
||||||
|
time_t rawt;
|
||||||
|
struct tm *timeinfo;
|
||||||
|
time(&rawt); //get time
|
||||||
|
timeinfo = localtime(&rawt);
|
||||||
|
size_t length = name.length() + 22;
|
||||||
|
char *timebuf = new char[length];
|
||||||
|
snprintf(timebuf, length, "\r[%02d:%02d:%02d INFO]: [%s] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, name.c_str());
|
||||||
|
std::cout << timebuf << msg << std::endl;
|
||||||
|
|
||||||
|
free(timebuf);
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace
|
} //namespace
|
||||||
|
|
|
@ -17,15 +17,15 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
void SimplePlugin::onLoad(JNIEnv*) {
|
void SimplePlugin::onLoad(JNIEnv*) {
|
||||||
std::cout << "SimplePLugin::onLoad();" << std::endl;
|
log("SimplePLugin::onLoad();");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimplePlugin::onEnable(JNIEnv*) {
|
void SimplePlugin::onEnable(JNIEnv*) {
|
||||||
std::cout << "SimplePLugin::onEnable();" << std::endl;
|
log("SimplePLugin::onEnable();");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimplePlugin::onDisable(JNIEnv*) {
|
void SimplePlugin::onDisable(JNIEnv*) {
|
||||||
std::cout << "SimplePLugin::onDisable();" << std::endl;
|
log("SimplePLugin::onDisable();");
|
||||||
}
|
}
|
||||||
|
|
||||||
CppPlugin* init() {
|
CppPlugin* init() {
|
||||||
|
|
|
@ -17,15 +17,15 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
void EventsPlugin::onLoad(JNIEnv*) {
|
void EventsPlugin::onLoad(JNIEnv*) {
|
||||||
std::cout << "Events::onLoad();" << std::endl;
|
log("Events::onLoad();");
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventsPlugin::onEnable(JNIEnv*) {
|
void EventsPlugin::onEnable(JNIEnv*) {
|
||||||
std::cout << "Events::onEnable();" << std::endl;
|
log("Events::onEnable();");
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventsPlugin::onDisable(JNIEnv*) {
|
void EventsPlugin::onDisable(JNIEnv*) {
|
||||||
std::cout << "Events::onDisable();" << std::endl;
|
log("Events::onDisable();");
|
||||||
}
|
}
|
||||||
|
|
||||||
CppPlugin* init() {
|
CppPlugin* init() {
|
||||||
|
@ -35,17 +35,17 @@ CppPlugin* init() {
|
||||||
void eventJoin(JNIEnv* env, CppPlugin* pl, Event* e) {
|
void eventJoin(JNIEnv* env, CppPlugin* pl, Event* e) {
|
||||||
jstring msg = (jstring) e->getData(env, "joinMessage");
|
jstring msg = (jstring) e->getData(env, "joinMessage");
|
||||||
std::string jmsg(env->GetStringUTFChars(msg, 0));
|
std::string jmsg(env->GetStringUTFChars(msg, 0));
|
||||||
std::cout << "join " << e->getName() << " old join message: " << jmsg << std::endl;
|
pl->log("join " + e->getName() + " old join message: " + jmsg);
|
||||||
jstring newmsg = env->NewStringUTF("Ein Spieler ist dem Spiel beigetreten!");
|
jstring newmsg = env->NewStringUTF("Ein Spieler ist dem Spiel beigetreten!");
|
||||||
e->setData("joinMessage", newmsg);
|
e->setData("joinMessage", newmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void eventQuit(JNIEnv* env, CppPlugin* pl, Event* e) {
|
void eventQuit(JNIEnv* env, CppPlugin* pl, Event* e) {
|
||||||
std::cout << "quit " << e->getName() << std::endl;
|
pl->log("quit " + e->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, eventfptr> EventsPlugin::getEvents() {
|
std::map<std::string, eventfptr> EventsPlugin::getEvents() {
|
||||||
std::cout << "EventsPlugin::getEvents" << std::endl;
|
log("EventsPlugin::getEvents");
|
||||||
std::map<std::string, eventfptr> out;
|
std::map<std::string, eventfptr> out;
|
||||||
out.insert({"PlayerJoinEvent", eventJoin});
|
out.insert({"PlayerJoinEvent", eventJoin});
|
||||||
out.insert({"PlayerQuitEvent", eventQuit});
|
out.insert({"PlayerQuitEvent", eventQuit});
|
||||||
|
|
|
@ -10,7 +10,7 @@ using namespace Plugin;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
bool hicmd(JNIEnv* env, CppPlugin* plugin, jobject sender, jobject cmd, std::string& label, std::vector<std::string>& args) {
|
bool hicmd(JNIEnv* env, CppPlugin* plugin, jobject sender, jobject cmd, std::string& label, std::vector<std::string>& args) {
|
||||||
std::cout << "HICMD::hi " << label << " argsize: " << args.size() << std::endl;
|
plugin->log("HICMD::hi " + label + " argsize: " + std::to_string(args.size()));
|
||||||
for(std::string& arg : args) {
|
for(std::string& arg : args) {
|
||||||
std::cout << arg << std::endl;
|
std::cout << arg << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -28,16 +28,16 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
void CmdPlugin::onLoad(JNIEnv*) {
|
void CmdPlugin::onLoad(JNIEnv*) {
|
||||||
std::cout << "CmdPlugin::onLoad();" << std::endl;
|
log("CmdPlugin::onLoad();");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmdPlugin::onEnable(JNIEnv* env) {
|
void CmdPlugin::onEnable(JNIEnv* env) {
|
||||||
std::cout << "CmdPlugin::onEnable();" << std::endl;
|
log("CmdPlugin::onEnable();");
|
||||||
registerCmd(env, this, "hi", hicmd);
|
registerCmd(env, this, "hi", hicmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmdPlugin::onDisable(JNIEnv*) {
|
void CmdPlugin::onDisable(JNIEnv*) {
|
||||||
std::cout << "CmdPlugin::onDisable();" << std::endl;
|
log("CmdPlugin::onDisable();");
|
||||||
}
|
}
|
||||||
|
|
||||||
CppPlugin* init() {
|
CppPlugin* init() {
|
||||||
|
|
11
testplugins/04crashtest/Makefile
Normal file
11
testplugins/04crashtest/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
CFLAGS = -Wall -pedantic-errors -std=c++17 -g
|
||||||
|
SRCDIR = src/
|
||||||
|
INCDIR = ../../src/main/cpp/inc
|
||||||
|
LDFLAGS = -I/usr/lib/jvm/java-8-openjdk-amd64/include/ -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/ -I$(INCDIR)
|
||||||
|
NAME = crashtest.so
|
||||||
|
|
||||||
|
all:
|
||||||
|
g++ -fPIC -shared $(CFLAGS) $(SRCDIR)*.cpp $(LDFLAGS) -o $(NAME) -lplugin
|
||||||
|
|
||||||
|
#/home/yannis/git/Cppplugin/testserver/plugins/CppPlugins/libplugin.so
|
41
testplugins/04crashtest/src/plugin.cpp
Normal file
41
testplugins/04crashtest/src/plugin.cpp
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#include "plugin.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace Plugin;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void sub(CppPlugin* plugin) {
|
||||||
|
plugin->printStacktrace();
|
||||||
|
plugin->log("asdf");
|
||||||
|
throw std::string("Nope");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool throwcmd(JNIEnv* env, CppPlugin* plugin, jobject sender, jobject cmd, std::string& label, std::vector<std::string>& args) {
|
||||||
|
sub(plugin);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CmdPlugin : public CppPlugin {
|
||||||
|
public:
|
||||||
|
//virtual void onLoad(JNIEnv*);
|
||||||
|
virtual void onEnable(JNIEnv*);
|
||||||
|
//virtual void onDisable(JNIEnv*);
|
||||||
|
//virtual std::map<std::string, eventfptr> getEvents();
|
||||||
|
};
|
||||||
|
|
||||||
|
void CmdPlugin::onEnable(JNIEnv* env) {
|
||||||
|
log("CmdPlugin::onEnable();");
|
||||||
|
registerCmd(env, this, "throw", throwcmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CppPlugin* init() {
|
||||||
|
return new CmdPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
}//extern "C"
|
Loading…
Reference in New Issue
Block a user