Skip to content

Commit

Permalink
Merge pull request #34 from ess-dmsc/33_flush_log_messages
Browse files Browse the repository at this point in the history
Flush log messages and other improvements
  • Loading branch information
SkyToGround authored Jan 16, 2020
2 parents 23d38bc + 8f86bc4 commit 92fca3e
Show file tree
Hide file tree
Showing 46 changed files with 1,189 additions and 415 deletions.
37 changes: 31 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.7)
project("graylog-logger"
VERSION 1.2.0
VERSION 2.0.0
DESCRIPTION "A simple logging library."
LANGUAGES CXX
)
Expand All @@ -27,8 +27,10 @@ elseif(${CONAN} MATCHES "MANUAL")
else()
message(FATAL_ERROR "CONAN set to MANUAL but no file named conanbuildinfo.cmake found in build directory")
endif()
elseif(${CONAN} MATCHES "DISABLE")
message(STATUS "***Deactivating Conan support.***")
else()
message(FATAL_ERROR "Unrecognised option for CONAN, use AUTO or MANUAL")
message(FATAL_ERROR "Unrecognised option for CONAN, use AUTO, MANUAL or DISABLE")
endif()

if (NOT WIN32)
Expand All @@ -39,12 +41,35 @@ else()
endif(NOT WIN32)

find_package(ASIO REQUIRED MODULE)
find_package(nlohmann_json REQUIRED)
find_package(Threads REQUIRED)
find_package(ConcurrentQueue REQUIRED)

find_package(GTest)
find_package(GMock)
find_package(fmt 6)
find_package(GoogleBenchmark)

add_subdirectory(src)
add_subdirectory(console_logger)

if(fmt_FOUND)
set(WITH_FMT 1)
endif()

option(BUILD_EVERYTHING "Build UnitTests & Console Logger" ON)
configure_file(include/graylog_logger/LibConfig.hpp.in include/graylog_logger/LibConfig.hpp)

IF(BUILD_EVERYTHING)
if(GTest_FOUND AND GMock_FOUND)
message(STATUS "GTest and GMock found, adding unit tests.")
add_subdirectory(unit_tests)
add_subdirectory(console_logger)
ENDIF()
else()
message(STATUS "Unable to find GTest and/or GMock. Skipping unit tests.")
endif()

if(GoogleBenchmark_FOUND AND fmt_FOUND)
message(STATUS "google-benchmark and fmtlib found, adding performance tests.")
add_subdirectory(performance_test)
else()
message(STATUS "Unable to find google-benchmark and/or fmtlib. Skipping performance tests.")
endif()

2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,7 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED =
PREDEFINED = WITH_FMT

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
58 changes: 47 additions & 11 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ builders = pipeline_builder.createBuilders { container ->
container.sh """
cd build
. ./activate_run.sh
make VERBOSE=1 all > ${container.key}-build.log
make all unit_tests > ${container.key}-build.log
"""
container.copyFrom("build/${container.key}-build.log", "${container.key}-build.log")
archiveArtifacts "${container.key}-build.log"
Expand All @@ -78,14 +78,50 @@ builders = pipeline_builder.createBuilders { container ->
} // if

if (container.key == clangformat_os) {
pipeline_builder.stage("${container.key}: check formatting") {
container.sh """
clang-format -version
cd ${pipeline_builder.project}
find . \\\\( -name '*.cpp' -or -name '*.cxx' -or -name '*.h' -or -name '*.hpp' \\\\) \\
-exec clangformatdiff.sh {} +
"""
} // stage
pipeline_builder.stage("${container.key}: Formatting") {
if (!env.CHANGE_ID) {
// Ignore non-PRs
return
}
try {
// Do clang-format of C++ files
container.sh """
clang-format -version
cd ${project}
find . \\\\( -name '*.cpp' -or -name '*.cxx' -or -name '*.h' -or -name '*.hpp' \\\\) \\
-exec clang-format -i {} +
git config user.email 'dm-jenkins-integration@esss.se'
git config user.name 'cow-bot'
git status -s
git add -u
git commit -m 'GO FORMAT YOURSELF (clang-format)'
"""
} catch (e) {
// Okay to fail as there could be no badly formatted files to commit
} finally {
// Clean up
}

// Push any changes resulting from formatting
try {
withCredentials([
usernamePassword(
credentialsId: 'cow-bot-username',
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD'
)
]) {
container.sh """
cd ${project}
git push https://${USERNAME}:${PASSWORD}@github.com/ess-dmsc/${pipeline_builder.project}.git HEAD:${CHANGE_BRANCH}
"""
} // withCredentials
} catch (e) {
// Okay to fail; there may be nothing to push
} finally {
// Clean up
}
} // stage

pipeline_builder.stage("${container.key}: cppcheck") {
def test_output = "cppcheck.txt"
Expand Down Expand Up @@ -160,7 +196,7 @@ def get_macos_pipeline()
}

try {
sh "source activate_run.sh && make all"
sh "source activate_run.sh && make all unit_tests"
sh "source activate_run.sh && ./unit_tests/unit_tests"
} catch (e) {
failure_function(e, 'MacOSX / build+test failed')
Expand Down Expand Up @@ -201,7 +237,7 @@ def get_win10_pipeline() {
stage("win10: Build") {
bat """cd _build
cmake .. -G \"Visual Studio 15 2017 Win64\" -DCMAKE_BUILD_TYPE=Release -DCONAN=MANUAL -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE
cmake --build . --config Release
cmake --build . --target unit_tests --config Release
"""
} // stage

Expand Down
47 changes: 38 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

# Graylog logger

This is a simple logging library which can be used to send log messages to a Graylog server. This is done by creating messages in the [GELF](http://docs.graylog.org/en/2.1/pages/gelf.html) format and sending them to a Graylog server via TCP. For testing purposes a [Vagrant](https://www.vagrantup.com/) machine running Graylog can be used. A simple Vagrantfile for creating this set-up can be [found here](https://github.com/ess-dmsc/graylog-machine). The argument for creating yet another logging library instead of writing a plugin/sink/handler for an already existing one is that a relatively light weight solution was desired. The library has functionality for writing log messages to console and file as well and by default the library will only write log messages to console.
This is a simple logging library which can be used to send log messages to a Graylog server. This is done by creating messages in the [GELF](http://docs.graylog.org/en/2.1/pages/gelf.html) format and sending them to a Graylog server via TCP. For testing purposes a [Vagrant](https://www.vagrantup.com/) machine running Graylog can be used. A simple Vagrantfile for creating this set-up can be [found here](https://github.com/ess-dmsc/graylog-machine). The argument for creating yet another logging library instead of writing a plugin/sink/handler for an already existing one is that a relatively light weight solution was desired. The library has functionality for writing log messages to console and file as well. By default the library will only write log messages to console.

The repository is split into three parts:
The repository is split into four parts:

* The logging library.
* Unit tests of the logging library which are completely self contained (i.e. does not require a Graylog server).
* A simple console application which uses the logging library.
* Some benchmarking code which is used for profiling and optimising the code as well as test for performance regression.

A sister project to this library is the Python logging handler [GraylogHandler](https://github.com/ess-dmsc/graylog-handler).

- [Further documentation](documentation/README.md)
- Further documentation can be [found here.](documentation/README.md)

## Getting Started

Expand All @@ -21,18 +22,30 @@ These instructions will get you a copy of the project up and running on your loc
### Prerequisites


The logging library depends on several external libraries:
The logging library has the following (requried) external dependencies:

* [GTest](https://github.com/google/googletest) (For testing.)
* [JSONForModernCPP](https://github.com/nlohmann/json)
* [ASIO](http://think-async.com) (For networking.)
* [moodycamel::ConcurrentQueue](https://github.com/cameron314/concurrentqueue) For message passing to and within the logging library.
* [JSONForModernCPP](https://github.com/nlohmann/json) For generating graylog GELF messages.
* [ASIO](http://think-async.com) For networking.

This library can also make use of the following (optional) dependencies:

* [libfmt](https://github.com/fmtlib/fmt) For doing fast (multi-threaded) string formatting.
* [GTest](https://github.com/google/googletest) For unit testing.
* [google-benchmark](https://github.com/google/benchmark) For benchmarking.

You will also need CMake (version ≥ 3.9) to build the project. The project makes use of library and language features provided by C++14. It might be possible to link to the library using compilers that only supports C++11 though this has not been tested.

Due to the use of ASIO, the library should compile on most \*nix systems and Windows 10 with no issues though only limited testing has been done.


### Installing
There are two methods for building this library. They are described below.

#### Using conan
When using conan to provide the dependencies, all the optional and required dependencies are provided automatically. Follow the instructions below.

First, add the required conan repositories:

```
conan remote add community https://api.bintray.com/conan/conan-community/conan
Expand All @@ -52,6 +65,19 @@ cmake ..
make install
```

#### System installed dependencies
If using conan is not an option, it is possible to build the library using system installed dependencies. This requires a bit more work though and might not be as reliable.

Run the following commands:

```
git clone https://github.com/ess-dmsc/graylog-logger.git
cd graylog-logger
mkdir build
cd build
cmake .. -DCONAN=DISABLE -DCMAKE_PREFIX_PATH=/path/to/dir/containing/the/concurrentqueue/directory/
make install
```

#### Documentation
The code has some documentation. To generate it, run _doxygen_ in the root of the repository i.e.:
Expand All @@ -73,7 +99,8 @@ Examples illustrating how the library can be used can be found in the [examples.
* [Conan](https://conan.io/) - Package manager for C++

## Contributing
TBD

Get in contact by [creating an issue](https://github.com/ess-dmsc/graylog-logger/issues). I will be happy to assist you making the changes that you want.

## Versioning

Expand All @@ -84,8 +111,10 @@ We use [SemVer](http://semver.org/) for versioning. For the versions available,
## Authors

* **Jonas Nilsson** - *Initial work* - [SkyToGround](https://github.com/SkyToGround)
* **Afonso Mukai** - Provided much assistance in setting up the continous integration system.
* **Matthew Jones** - Improved the CMake code and suggested improvements to the interface.

See also the list of [contributors](https://github.com/ess-dmsc/graylog-logger/graphs/contributors) who participated in this project.
See also the list of [contributors](https://github.com/ess-dmsc/graylog-logger/graphs/contributors) to this project.

## License

Expand Down
3 changes: 0 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# To do
The items in the following list is in no particular order. Suggestions and/or patches are welcome.

* Improved threading model
* Performance testing and improvements
* Version number from git tag
* Log file rotation
* UDP Messages
* Integrate the fmt library?
* Add example logging macros
24 changes: 24 additions & 0 deletions cmake/FindConcurrentQueue.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
find_path(ConcurrentQueue_INCLUDE_DIR
NAMES concurrentqueue/concurrentqueue.h
PATHS /usr/local/include/ /opt/local/include/
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ConcurrentQueue FOUND_VAR ConcurrentQueue_FOUND REQUIRED_VARS
ConcurrentQueue_INCLUDE_DIR
)

mark_as_advanced(
ConcurrentQueue_INCLUDE_DIR
)

if(ConcurrentQueue_FOUND)
set(ConcurrentQueue_INCLUDE_DIRS ${ConcurrentQueue_INCLUDE_DIR})
endif()

if(ConcurrentQueue_FOUND AND NOT TARGET ConcurrentQueue::ConcurrentQueue)
add_library(ConcurrentQueue::ConcurrentQueue INTERFACE IMPORTED)
set_target_properties(ConcurrentQueue::ConcurrentQueue PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ConcurrentQueue_INCLUDE_DIR}"
)
endif()
Loading

0 comments on commit 92fca3e

Please sign in to comment.