Skip to content

Commit

Permalink
Add debug log support for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
shalithasuranga committed Sep 22, 2019
1 parent 4028c52 commit 7880f33
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core-linux/bin/app/assets/neutralino.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core-linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if [ -e bin/neutralino ]; then
rm bin/neutralino
fi

g++ -I ../core-shared -std=c++14 ../core-shared/log.cpp src/Buffer.cpp src/Handler.cpp src/requestparser.cpp src/Socket.cpp src/functions.cpp src/main.cpp src/router.cpp src/core/filesystem/filesystem.cpp src/settings.cpp src/core/os/os.cpp src/core/computer/computer.cpp src/auth/authbasic.cpp src/ping/ping.cpp src/core/storage/storage.cpp src/cloud/previleges.cpp -pthread -std=c++14 -DWEBVIEW_GTK=1 `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` -o bin/neutralino -no-pie -lstdc++fs
g++ -I ../core-shared -std=c++14 ../core-shared/log.cpp src/Buffer.cpp src/Handler.cpp src/requestparser.cpp src/Socket.cpp src/functions.cpp src/main.cpp src/router.cpp src/core/filesystem/filesystem.cpp src/settings.cpp src/core/os/os.cpp src/core/computer/computer.cpp src/core/debug/debug.cpp src/auth/authbasic.cpp src/ping/ping.cpp src/core/storage/storage.cpp src/cloud/previleges.cpp -pthread -std=c++14 -DWEBVIEW_GTK=1 `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` -o bin/neutralino -no-pie -lstdc++fs

if [ -e bin/neutralino ]; then
echo "Neutralino binary is compiled in to bin/netralino"
Expand Down
59 changes: 59 additions & 0 deletions core-linux/src/core/debug/debug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// MIT License

// Copyright (c) 2018 Neutralinojs

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <iostream>
#include <fstream>
#include "../../../lib/json/json.hpp"
#include "../../settings.h"
#include "../core-shared/log.h"

using namespace std;
using json = nlohmann::json;

namespace debug {
string log(string jso) {
json input;
json output;
try {
input = json::parse(jso);
}
catch(exception e){
output["error"] = "JSON parse error is occurred!";
return output.dump();
}
string type = input["type"].get<std::string>();
string message = input["message"].get<std::string>();

if(type == "INFO")
INFO() << message;
else if(type == "ERROR")
ERROR() << message;
else if(type == "WARN")
WARN() << message;
else
DEBUG() << message;

output["message"] = "Wrote to log file neutralino.log";
return output.dump();
}

}
40 changes: 40 additions & 0 deletions core-linux/src/core/debug/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// MIT License

// Copyright (c) 2018 Neutralinojs

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#ifndef DEBUG_H
#define DEBUG_H

#include <iostream>
#include <map>

using namespace std;

namespace debug {
string log(string jso);

typedef string (*pfunc)(string);

map <string, pfunc> funcmap = {
{"debug.log", debug::log}
};
}

#endif
5 changes: 5 additions & 0 deletions core-linux/src/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "core/os/os.h"
#include "core/computer/computer.h"
#include "core/storage/storage.h"
#include "core/debug/debug.h"
#include "../lib/json/json.hpp"
#include "auth/authbasic.h"
#include "ping/ping.h"
Expand Down Expand Up @@ -116,6 +117,10 @@ namespace routes {
pfunc f = storage::funcmap[modfunc];
output = (*f)(j);
}
else if(debug::funcmap.find(modfunc) != debug::funcmap.end() ){
pfunc f = debug::funcmap[modfunc];
output = (*f)(j);
}
else {
json o = {{"error", modfunc + " is not supported"}};
output = o.dump();
Expand Down

0 comments on commit 7880f33

Please sign in to comment.