Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brayns 258 create a proper logging system for brayns #932

Merged
merged 22 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@
[submodule "deps/MorphIO"]
path = deps/MorphIO
url = https://github.com/BlueBrain/MorphIO
[submodule "deps/spdlog"]
path = deps/spdlog
url = https://github.com/gabime/spdlog.git
16 changes: 8 additions & 8 deletions apps/BraynsBenchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/

#include <brayns/Brayns.h>
#include <brayns/common/Log.h>
#include <brayns/common/Timer.h>
#include <brayns/common/log.h>
#include <brayns/common/types.h>
#include <brayns/engine/Camera.h>
#include <brayns/engine/Engine.h>
Expand All @@ -38,8 +38,8 @@ int main(int argc, const char** argv)
brayns::Brayns brayns(argc, argv);
timer.stop();

BRAYNS_INFO << "[PERF] Scene initialization took "
<< timer.milliseconds() << " milliseconds" << std::endl;
brayns::Log::info("[PERF] Scene initialization took {} milliseconds",
timer.milliseconds());

auto& engine = brayns.getEngine();
auto& scene = engine.getScene();
Expand All @@ -58,14 +58,14 @@ int main(int argc, const char** argv)
}
timer.stop();

BRAYNS_INFO << "[PERF] Rendering " << nbFrames << " frames took "
<< timer.milliseconds() << " milliseconds" << std::endl;
BRAYNS_INFO << "[PERF] Frames per second: "
<< nbFrames / timer.seconds() << std::endl;
brayns::Log::info("[PERF] Rendering {} frames took {} milliseconds.",
nbFrames, timer.milliseconds());
brayns::Log::info("[PERF] Frames per second: {}.",
nbFrames / timer.seconds());
}
catch (const std::runtime_error& e)
{
BRAYNS_ERROR << e.what() << std::endl;
brayns::Log::error(e.what());
return 1;
}
return 0;
Expand Down
8 changes: 4 additions & 4 deletions apps/BraynsService/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/

#include <brayns/Brayns.h>
#include <brayns/common/Log.h>
#include <brayns/common/Timer.h>
#include <brayns/common/log.h>
#include <brayns/engine/Engine.h>
#include <brayns/network/interface/ActionInterface.h>

Expand Down Expand Up @@ -83,12 +83,12 @@ int main(int argc, const char** argv)
service.run();

timer.stop();
BRAYNS_INFO << "Service was running for " << timer.seconds()
<< " seconds" << std::endl;
brayns::Log::info("Service was running for {} seconds.",
timer.seconds());
}
catch (const std::runtime_error& e)
{
BRAYNS_ERROR << e.what() << std::endl;
brayns::Log::error(e.what());
return 1;
}
return 0;
Expand Down
4 changes: 2 additions & 2 deletions apps/BraynsViewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <apps/ui/Application.h>
#include <brayns/Brayns.h>
#include <brayns/common/log.h>
#include <brayns/common/Log.h>

#include <brayns/parameters/ApplicationParameters.h>
#include <brayns/parameters/ParametersManager.h>
Expand All @@ -45,7 +45,7 @@ int main(int argc, const char** argv)
}
catch (const std::runtime_error& e)
{
BRAYNS_ERROR << e.what() << std::endl;
brayns::Log::error(e.what());
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
Expand Down
1 change: 1 addition & 0 deletions apps/ui/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include <algorithm>
#include <cassert>
#include <iostream>

namespace
{
Expand Down
49 changes: 22 additions & 27 deletions brayns/Brayns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include "EngineFactory.h"
#include "PluginManager.h"

#include <brayns/common/Log.h>
#include <brayns/common/Timer.h>
#include <brayns/common/input/KeyboardHandler.h>
#include <brayns/common/light/Light.h>
#include <brayns/common/log.h>
#include <brayns/common/mathTypes.h>
#include <brayns/utils/DynamicLib.h>
#include <brayns/utils/StringUtils.h>
Expand Down Expand Up @@ -75,27 +75,21 @@ struct Brayns::Impl : public PluginAPI
, _engineFactory{argc, argv, _parametersManager}
, _pluginManager{argc, argv}
{
BRAYNS_INFO << std::endl;
BRAYNS_INFO << " _|_|_|" << std::endl;
BRAYNS_INFO
<< " _| _| _| _|_| _|_|_| _| _| _|_|_| _|_|_| "
<< std::endl;
BRAYNS_INFO
<< " _|_|_| _|_| _| _| _| _| _| _| _|_| "
<< std::endl;
BRAYNS_INFO
<< " _| _| _| _| _| _| _| _| _| _|_| "
<< std::endl;
BRAYNS_INFO
<< " _|_|_| _| _|_|_| _|_|_| _| _| _|_|_| "
<< std::endl;
BRAYNS_INFO
<< " _| "
<< std::endl;
BRAYNS_INFO
<< " _|_| "
<< std::endl;
BRAYNS_INFO << std::endl;
Log::info("");
Log::info(" _|_|_|");
Log::info(
" _| _| _| _|_| _|_|_| _| _| _|_|_| _|_|_| ");
Log::info(
" _|_|_| _|_| _| _| _| _| _| _| _|_| ");
Log::info(
" _| _| _| _| _| _| _| _| _| _|_| ");
Log::info(
" _|_|_| _| _|_|_| _|_|_| _| _| _|_|_| ");
Log::info(
" _| ");
Log::info(
" _|_| ");
Log::info("");

// This initialization must happen before plugin intialization.
_createEngine();
Expand Down Expand Up @@ -379,7 +373,7 @@ struct Brayns::Impl : public PluginAPI
std::string msgLast;
auto timeLast = std::chrono::steady_clock::now();

BRAYNS_INFO << "Loading '" << path << "'" << std::endl;
Log::info("Loading '{}'.", path);

auto progress = [&](const std::string& msg, float t) {
constexpr auto MIN_SECS = 5;
Expand All @@ -400,7 +394,7 @@ struct Brayns::Impl : public PluginAPI
std::string p = std::to_string(percentage);
p.insert(p.begin(), 3 - p.size(), ' ');

BRAYNS_INFO << "[" << p << "%] " << msg << std::endl;
Log::info("[{}%] {}.", p, msg);
msgLast = msg;
percentageLast = percentage;
timeLast = time;
Expand Down Expand Up @@ -717,7 +711,7 @@ struct Brayns::Impl : public PluginAPI
auto fovy = camera.getProperty<double>("fovy");
fovy += delta;
camera.updateProperty("fovy", fovy);
BRAYNS_INFO << "Field of view: " << fovy << std::endl;
Log::info("Field of view: {}.", fovy);
}

void _changeEyeSeparation(const double delta)
Expand All @@ -729,7 +723,7 @@ struct Brayns::Impl : public PluginAPI
camera.getProperty<double>("interpupillaryDistance");
eyeSeparation += delta;
camera.updateProperty("interpupillaryDistance", eyeSeparation);
BRAYNS_INFO << "Eye separation: " << eyeSeparation << std::endl;
Log::info("Eye separation: {}.", eyeSeparation);
}

void _gradientMaterials()
Expand Down Expand Up @@ -766,7 +760,8 @@ struct Brayns::Impl : public PluginAPI

void _displayCameraInformation()
{
BRAYNS_INFO << _engine->getCamera() << std::endl;
auto& camera = _engine->getCamera();
Log::info("{}, {}", camera.getPosition(), camera.getOrientation());
}

ParametersManager _parametersManager;
Expand Down
7 changes: 3 additions & 4 deletions brayns/EngineFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "EngineFactory.h"

#include <brayns/common/log.h>
#include <brayns/common/Log.h>
#include <brayns/engine/Engine.h>
#include <brayns/parameters/ParametersManager.h>

Expand Down Expand Up @@ -67,14 +67,13 @@ Engine* EngineFactory::_loadEngine(const std::string& name, int argc,
{
_engines.emplace(name, std::unique_ptr<Engine>(plugin));
_libs.push_back(std::move(library));
BRAYNS_INFO << "Loaded engine '" << name << "'" << std::endl;
Log::info("Loaded engine '{}'.", name);
return plugin;
}
}
catch (const std::runtime_error& exc)
{
BRAYNS_ERROR << "Failed to load engine " << std::quoted(name) << ": "
<< exc.what() << std::endl;
Log::error("Failed to load engine '{}': {}", name, exc.what());
}
return nullptr;
}
Expand Down
6 changes: 3 additions & 3 deletions brayns/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "PluginManager.h"

#include <brayns/common/log.h>
#include <brayns/common/Log.h>
#include <brayns/parameters/ParametersManager.h>
#include <brayns/utils/StringUtils.h>

Expand Down Expand Up @@ -133,12 +133,12 @@ void PluginManager::_loadPlugin(const char* name, int argc, const char* argv[])
{
_extensions.emplace_back(plugin);
_libs.push_back(std::move(library));
BRAYNS_INFO << "Loaded plugin '" << name << "'" << std::endl;
Log::info("Loaded plugin '{}'.", name);
}
}
catch (const std::runtime_error& exc)
{
BRAYNS_ERROR << exc.what() << std::endl;
Log::error(exc.what());
}
}
} // namespace brayns
8 changes: 7 additions & 1 deletion brayns/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ set(BRAYNSCOMMON_PUBLIC_HEADERS
light/Light.h
loader/Loader.h
loader/LoaderRegistry.h
log.h
Log.h
material/Texture2D.h
mathTypes.h
scene/ClipPlane.h
Expand All @@ -59,6 +59,7 @@ set(BRAYNSCOMMON_PUBLIC_HEADERS
set(BRAYNSCOMMON_INCLUDE_NAME brayns/common)
set(BRAYNSCOMMON_LINK_LIBRARIES
PUBLIC glm Async++ ${LibJpegTurbo_LIBRARIES} braynsUtils braynsJson
PUBLIC spdlog::spdlog_header_only
PRIVATE braynsParameters ${Boost_PROGRAM_OPTIONS_LIBRARY}
${FREEIMAGE_LIBRARIES}
)
Expand All @@ -70,3 +71,8 @@ target_include_directories(braynsCommon SYSTEM PRIVATE ${FREEIMAGE_INCLUDE_DIRS}
if(FFMPEG_FOUND)
target_include_directories(braynsCommon SYSTEM PRIVATE ${FFMPEG_INCLUDE_DIR})
endif()

target_include_directories(braynsCommon PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/deps/spdlog/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>"
)
6 changes: 3 additions & 3 deletions brayns/common/ImageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
*/

#include "ImageManager.h"
#include <brayns/common/log.h>

#include <brayns/common/Log.h>
#include <brayns/utils/Filesystem.h>
#include <brayns/utils/ImageUtils.h>

Expand Down Expand Up @@ -155,8 +156,7 @@ Texture2DPtr ImageManager::importTextureFromFile(const std::string& filename,
}
return texture;
#else
BRAYNS_ERROR << "FreeImage is required to load images from file"
<< std::endl;
Log::error("FreeImage is required to load images from file");
return {};
#endif
}
Expand Down
Loading