Squashed 'libs/loguru/' content from commit 644f60d
git-subtree-dir: libs/loguru git-subtree-split: 644f60dca77de3b0f718a03d370c8ebdf5f97968
This commit is contained in:
39
loguru_example/CMakeLists.txt
Normal file
39
loguru_example/CMakeLists.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(loguru_example)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
|
||||
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
||||
endif(NOT CMAKE_BUILD_TYPE)
|
||||
|
||||
MESSAGE(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
|
||||
|
||||
if(MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wextra -pedantic")
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat-pedantic")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-noreturn")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-prototypes")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-disabled-macro-expansion")
|
||||
endif() # Clang
|
||||
|
||||
file(GLOB source
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
# "${CMAKE_CURRENT_SOURCE_DIR}/../*.cpp"
|
||||
)
|
||||
|
||||
add_executable(loguru_example ${source})
|
||||
|
||||
find_package(Threads)
|
||||
target_link_libraries(loguru_example ${CMAKE_THREAD_LIBS_INIT}) # For pthreads
|
||||
if(NOT WIN32)
|
||||
target_link_libraries(loguru_example dl) # For ldl
|
||||
endif()
|
||||
12
loguru_example/build_and_run.sh
Executable file
12
loguru_example/build_and_run.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
set -e # Fail on error
|
||||
|
||||
ROOT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
|
||||
|
||||
cd "$ROOT_DIR"
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
|
||||
./loguru_example $@
|
||||
26
loguru_example/loguru_example.hpp
Normal file
26
loguru_example/loguru_example.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "../loguru.hpp"
|
||||
|
||||
inline void sleep_ms(int ms)
|
||||
{
|
||||
VLOG_F(2, "Sleeping for %d ms", ms);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
||||
}
|
||||
|
||||
inline void complex_calculation()
|
||||
{
|
||||
LOG_SCOPE_F(INFO, "complex_calculation");
|
||||
LOG_F(INFO, "Starting time machine...");
|
||||
sleep_ms(200);
|
||||
LOG_F(WARNING, "The flux capacitor is not getting enough power!");
|
||||
sleep_ms(400);
|
||||
LOG_F(INFO, "Lighting strike!");
|
||||
VLOG_F(1, "Found 1.21 gigawatts...");
|
||||
sleep_ms(400);
|
||||
std::thread([](){
|
||||
loguru::set_thread_name("the past");
|
||||
LOG_F(ERROR, "We ended up in 1985!");
|
||||
}).join();
|
||||
}
|
||||
13
loguru_example/main.cpp
Normal file
13
loguru_example/main.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "loguru_example.hpp"
|
||||
|
||||
#include "../loguru.cpp"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
loguru::init(argc, argv);
|
||||
LOG_F(INFO, "Hello from main.cpp!");
|
||||
complex_calculation();
|
||||
LOG_F(INFO, "main function about to end!");
|
||||
}
|
||||
Reference in New Issue
Block a user