forked fromglynos/cpp-netlib
- Notifications
You must be signed in to change notification settings - Fork425
Restructure dirs#179
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Restructure dirs#179
Changes from1 commit
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
e7bfb97 Moved around some directories and updated build scripts.
glynos4d424b8 Updated build scripts for the restructured uri so that it compiles on…
glynosfd5e7d5 Restructured the message framework, passing tests on Linux/GCC 4.7.
glynos9c4f0a5 Restructured logging code into a new subdirectory.
glynoseacf307 Updated build script references.
glynosdcbb386 Removed obsolete files; updated build scripts so that the include pat…
glynos33176c3 Adjustments to build scripts in order to compile on MSVC 2012.
glynosFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Restructured logging code into a new subdirectory.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit9c4f0a5bcc344b598269482c73230ae764d8a3bc
There are no files selected for viewing
1 change: 1 addition & 0 deletionsCMakeLists.txt
This file contains hidden or 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
11 changes: 11 additions & 0 deletionslogging/CMakeLists.txt
This file contains hidden or 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,11 @@ | ||
| # Copyright (c) Glyn Matthews 2012. | ||
| # Distributed under the Boost Software License, Version 1.0. | ||
| # (See accompanying file LICENSE_1_0.txt or copy at | ||
| # http://www.boost.org/LICENSE_1_0.txt) | ||
| add_subdirectory(src) | ||
| if(CPP-NETLIB_BUILD_TESTS) | ||
| enable_testing() | ||
| add_subdirectory(test) | ||
| endif(CPP-NETLIB_BUILD_TESTS) |
29 changes: 29 additions & 0 deletionslogging/src/CMakeLists.txt
This file contains hidden or 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,29 @@ | ||
| # Copyright (c) Glyn Matthews 2012. | ||
| # Distributed under the Boost Software License, Version 1.0. | ||
| # (See accompanying file LICENSE_1_0.txt or copy at | ||
| # http://www.boost.org/LICENSE_1_0.txt) | ||
| if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) | ||
| if (HAVE_STD11) | ||
| set(CPP-NETLIB_CXXFLAGS "-Wall -std=c++11") | ||
| elseif (HAVE_STD0X) | ||
| set(CPP-NETLIB_CXXFLAGS "-Wall -std=c++0x") | ||
| endif() | ||
| elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang) | ||
| CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11) | ||
| set(CPP-NETLIB_CXXFLAGS "-Wall -std=c++11 -stdlib=libc++") | ||
| set(CPP-NETLIB_CXXFLAGS "-Wall -std=c++11 -stdlib=libc++") | ||
| endif() | ||
| include_directories(${CPP-NETLIB_SOURCE_DIR}/logging/src) | ||
| set(CPP-NETLIB_LOGGING_SRCS logging.cpp) | ||
| add_library(cppnetlib-logging ${CPP-NETLIB_LOGGING_SRCS}) | ||
| foreach (src_file ${CPP-NETLIB_LOGGING_SRCS}) | ||
| if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) | ||
| set_source_files_properties(${src_file} | ||
| PROPERTIES COMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS}) | ||
| elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang) | ||
| set_source_files_properties(${src_file} | ||
| PROPERTIES COMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS}) | ||
| endif() | ||
| endforeach(src_file) |
58 changes: 58 additions & 0 deletionslogging/src/logging.cpp
This file contains hidden or 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,58 @@ | ||
| // Copyright 2011 A. Joel Lamotte <mjklaim@gmail.com>. | ||
| // Distributed under the Boost Software License, Version 1.0. | ||
| // (See accompanying file LICENSE_1_0.txt or copy at | ||
| // http://www.boost.org/LICENSE_1_0.txt) | ||
| #ifdef NETWORK_NO_LIB | ||
| #undef NETWORK_NO_LIB | ||
| #endif | ||
| #include <iostream> | ||
| #include <memory> | ||
| #include <network/logging/logging.hpp> | ||
| namespace network { namespace logging { | ||
| const char* log_record::UNKNOWN_FILE_NAME = "unknown"; | ||
| namespace handler | ||
| { | ||
| namespace | ||
| { | ||
| void std_log_handler( const log_record& log ) | ||
| { | ||
| std::cerr << "[network " << log.filename() << ":" << log.line() << "] " | ||
| << log.message() << std::endl; | ||
| } | ||
| } | ||
| log_record_handler get_std_log_handler() { return &std_log_handler; } | ||
| log_record_handler get_default_log_handler() { return &std_log_handler; } | ||
| } | ||
| namespace | ||
| { | ||
| // the log handler have to manage itself the thread safety on call | ||
| static auto current_log_record_handler = std::make_shared<log_record_handler>( &handler::std_log_handler ); | ||
| } | ||
| void set_log_record_handler( log_record_handler handler ) | ||
| { | ||
| current_log_record_handler = std::make_shared<log_record_handler>( handler ); | ||
| } | ||
| void log( const log_record& log ) | ||
| { | ||
| auto log_handler = current_log_record_handler; | ||
| if( log_handler ) | ||
| { | ||
| (*log_handler)( log ); | ||
| } | ||
| } | ||
| }} |
86 changes: 86 additions & 0 deletionslogging/src/network/logging/logging.hpp
This file contains hidden or 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,86 @@ | ||
| // Copyright (c) 2012 A. Joel Lamotte <mjklaim@gmail.com>. | ||
| // Distributed under the Boost Software License, Version 1.0. | ||
| // (See accompanying file LICENSE_1_0.txt or copy at | ||
| // http://www.boost.org/LICENSE_1_0.txt) | ||
| #ifndef NETWORK_LOGGING_HPP_20121112 | ||
| #define NETWORK_LOGGING_HPP_20121112 | ||
| #include <sstream> | ||
| #include <functional> | ||
| namespace network { namespace logging { | ||
| class log_record; | ||
| //using log_record_handler = std::function< void (const std::string&) >; // use this when VS can compile it... | ||
| typedef std::function< void (const log_record&) > log_record_handler; | ||
| void set_log_record_handler( log_record_handler handler ); | ||
| void log( const log_record& message ); | ||
| namespace handler | ||
| { | ||
| log_record_handler get_std_log_handler(); | ||
| log_record_handler get_default_log_handler(); | ||
| } | ||
| /** Helper to build a log record as a stream. */ | ||
| class log_record | ||
| { | ||
| public: | ||
| log_record() | ||
| : m_filename( UNKNOWN_FILE_NAME ) | ||
| , m_line(0) | ||
| {} // = default; | ||
| static const char* UNKNOWN_FILE_NAME; | ||
| // Implicit construction from anything serializable to text. | ||
| template< typename TypeOfSomething > | ||
| log_record( TypeOfSomething&& message ) | ||
| : m_filename( UNKNOWN_FILE_NAME ) | ||
| , m_line(0) | ||
| { | ||
| write( std::forward<TypeOfSomething>(message) ); | ||
| } | ||
| // Construction with recording context informations. | ||
| log_record( std::string filename, unsigned long line ) | ||
| : m_filename( filename ) | ||
| , m_line( line ) | ||
| { | ||
| } | ||
| template< typename TypeOfSomething > | ||
| log_record& write( TypeOfSomething&& something ) | ||
| { | ||
| m_text_stream << something; | ||
| return *this; | ||
| } | ||
| template< typename TypeOfSomething > | ||
| inline log_record& operator<<( TypeOfSomething&& something ) | ||
| { | ||
| return write( std::forward<TypeOfSomething>(something) ); | ||
| } | ||
| std::string message() const { return m_text_stream.str(); } | ||
| const std::string& filename() const { return m_filename; } | ||
| unsigned long line() const { return m_line; } | ||
| private: | ||
| // disable copy | ||
| log_record( const log_record& ); // = delete; | ||
| log_record& operator=( const log_record& ); // = delete; | ||
| std::ostringstream m_text_stream; // stream in which we build the message | ||
| std::string m_filename; // = UNKNOWN_FILE_NAME; | ||
| unsigned long m_line; // = 0; | ||
| }; | ||
| }} | ||
| #endif /* end of include guard: NETWORK_LOGGING_HPP_20121112 */ |
29 changes: 29 additions & 0 deletionslogging/test/CMakeLists.txt
This file contains hidden or 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,29 @@ | ||
| # Copyright (c) A. Joel Lamotte 2012. | ||
| # Distributed under the Boost Software License, Version 1.0. | ||
| # (See accompanying file LICENSE_1_0.txt or copy at | ||
| # http://www.boost.org/LICENSE_1_0.txt) | ||
| include_directories(${CPP-NETLIB_SOURCE_DIR}/include) | ||
| include_directories(${CPP-NETLIB_SOURCE_DIR}) | ||
| if (Boost_FOUND) | ||
| set( | ||
| TESTS | ||
| logging_log_record | ||
| logging_custom_handler | ||
| ) | ||
| foreach (test ${TESTS}) | ||
| if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) | ||
| set_source_files_properties(${test}.cpp | ||
| PROPERTIES COMPILE_FLAGS "-Wall") | ||
| endif() | ||
| add_executable(cpp-netlib-${test} ${test}.cpp) | ||
| add_dependencies(cpp-netlib-${test} cppnetlib-logging) | ||
| target_link_libraries(cpp-netlib-${test} | ||
| ${Boost_LIBRARIES} cppnetlib-logging) | ||
| set_target_properties(cpp-netlib-${test} | ||
| PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests) | ||
| add_test(cpp-netlib-${test} | ||
| ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test}) | ||
| endforeach (test) | ||
| endif() |
37 changes: 37 additions & 0 deletionslogging/test/logging_custom_handler.cpp
This file contains hidden or 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,37 @@ | ||
| // Copyright (c) 2012 A. Joel Lamotte <mjklaim@gmail.com> | ||
| // Distributed under the Boost Software License, Version 1.0. | ||
| // (See accompanying file LICENSE_1_0.txt or copy at | ||
| // http://www.boost.org/LICENSE_1_0.txt) | ||
| #include <string> | ||
| #include <sstream> | ||
| #define BOOST_TEST_MODULE logging log_record | ||
| #include <boost/config/warning_disable.hpp> | ||
| #include <boost/test/unit_test.hpp> | ||
| #include <network/logging/logging.hpp> | ||
| using namespace network::logging; | ||
| BOOST_AUTO_TEST_CASE(custom_log_handler_output) { | ||
| std::stringstream log_output; | ||
| auto custom_log_handler = [&]( const log_record& log ) | ||
| { | ||
| log_output << "[CPPNETLIB]<" << log.filename() << ":" << log.line() << "> " | ||
| << log.message(); | ||
| }; | ||
| const auto line_num = 42; | ||
| const auto file_name = "somewhere.cpp"; | ||
| const auto message = "At line " + std::to_string(line_num) + " we check the code."; | ||
| set_log_record_handler( custom_log_handler ); | ||
| log( log_record( file_name, line_num ) << "At line " << line_num << " we check the code." ); | ||
| const auto result_output = log_output.str(); | ||
| BOOST_CHECK( !result_output.empty() ); | ||
| BOOST_CHECK( result_output == "[CPPNETLIB]<somewhere.cpp:42> " + message ); | ||
| } |
78 changes: 78 additions & 0 deletionslogging/test/logging_log_record.cpp
This file contains hidden or 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,78 @@ | ||
| // Copyright (c) 2012 A. Joel Lamotte <mjklaim@gmail.com> | ||
| // Distributed under the Boost Software License, Version 1.0. | ||
| // (See accompanying file LICENSE_1_0.txt or copy at | ||
| // http://www.boost.org/LICENSE_1_0.txt) | ||
| #include <string> | ||
| #define BOOST_TEST_MODULE logging log_record | ||
| #include <boost/config/warning_disable.hpp> | ||
| #include <boost/test/unit_test.hpp> | ||
| #include <network/logging/logging.hpp> | ||
| #define NETWORK_ENABLE_LOGGING | ||
| #include <network/detail/debug.hpp> | ||
| using namespace network::logging; | ||
| BOOST_AUTO_TEST_CASE(default_constructor) { | ||
| log_record record; | ||
| BOOST_CHECK( record.message() == "" ); | ||
| BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME ); | ||
| BOOST_CHECK( record.line() == 0 ); | ||
| } | ||
| BOOST_AUTO_TEST_CASE(cstring_constructor) { | ||
| const auto message = "This is a test."; | ||
| log_record record( message ); | ||
| BOOST_CHECK( record.message() == message ); | ||
| BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME ); | ||
| BOOST_CHECK( record.line() == 0 ); | ||
| } | ||
| BOOST_AUTO_TEST_CASE(string_constructor) { | ||
| const std::string message("This is a test."); | ||
| log_record record( message ); | ||
| BOOST_CHECK( record.message() == message ); | ||
| BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME ); | ||
| BOOST_CHECK( record.line() == 0 ); | ||
| } | ||
| BOOST_AUTO_TEST_CASE(int_constructor) { | ||
| const auto num = 42; | ||
| log_record record( num ); | ||
| BOOST_CHECK( record.message() == std::to_string( num ) ); | ||
| BOOST_CHECK( record.filename() == log_record::UNKNOWN_FILE_NAME ); | ||
| BOOST_CHECK( record.line() == 0 ); | ||
| } | ||
| BOOST_AUTO_TEST_CASE(info_constructor) { | ||
| const auto line_num = 42; | ||
| const auto file_name = "somewhere.cpp"; | ||
| log_record record( file_name, line_num ); | ||
| BOOST_CHECK( record.message() == "" ); | ||
| BOOST_CHECK( record.filename() == file_name ); | ||
| BOOST_CHECK( record.line() == line_num ); | ||
| } | ||
| BOOST_AUTO_TEST_CASE(text_stream) { | ||
| const auto line_num = 42; | ||
| const auto file_name = "somewhere.cpp"; | ||
| const auto message = "At line " + std::to_string(line_num) + " we check the code."; | ||
| log_record record( file_name, line_num ); | ||
| record << "At line " << line_num << " we check the code."; | ||
| BOOST_CHECK( record.message() == message ); | ||
| BOOST_CHECK( record.filename() == file_name ); | ||
| BOOST_CHECK( record.line() == line_num ); | ||
| } | ||
| BOOST_AUTO_TEST_CASE(raw_log) { | ||
| log( "This is a raw log." ); | ||
| } | ||
| BOOST_AUTO_TEST_CASE(macro_log) { | ||
| NETWORK_MESSAGE( "This is a log through the macro." ); | ||
| NETWORK_MESSAGE( "This is a log through the macro, with a stream! Num=" << 42 << " - OK!" ); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.