-
-
Notifications
You must be signed in to change notification settings - Fork 523
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 #2293 from mavlink/pr-log-callback-example
examples: add log_callback demo
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required(VERSION 3.10.2) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
project(log_callback) | ||
|
||
add_executable(log_callback | ||
log_callback.cpp | ||
) | ||
|
||
find_package(MAVSDK REQUIRED) | ||
|
||
target_link_libraries(log_callback | ||
MAVSDK::mavsdk | ||
) | ||
|
||
if(NOT MSVC) | ||
add_compile_options(log_callback PRIVATE -Wall -Wextra) | ||
else() | ||
add_compile_options(log_callback PRIVATE -WX -W2) | ||
endif() |
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,30 @@ | ||
// | ||
// Example how to customize MAVSDK log messages. | ||
// | ||
|
||
#include <mavsdk/mavsdk.h> | ||
#include <mavsdk/log_callback.h> | ||
|
||
#include <iostream> | ||
|
||
using namespace mavsdk; | ||
|
||
int main(int, char**) | ||
{ | ||
// Set our own custom log function. | ||
log::subscribe( | ||
[](log::Level level, const std::string& message, const std::string& file, int line) { | ||
std::cout << "My custom print function: " << message << std::endl; | ||
|
||
// Prevent unused warnings. | ||
(void)level; | ||
(void)file; | ||
(void)line; | ||
return true; | ||
}); | ||
|
||
// Instantiate Mavsdk after. This will just print the version. | ||
Mavsdk mavsdk{Mavsdk::Configuration{Mavsdk::ComponentType::GroundStation}}; | ||
|
||
return 0; | ||
} |