Skip to content

Commit

Permalink
g2log.hpp is kept as a helper include. It will pull in the most frequ…
Browse files Browse the repository at this point in the history
…ent include files

All other are under g3log. Example: #include <g3log/time.hpp> #include <g3log/g3log.hpp> etc
This makes sure that the package manager (to be  used soon) does NOT clutter any /usr/local/include space
instead all the includes will be in /usr/local/include/g3log (or similar)
  • Loading branch information
Kjell Hedstrom authored and Kjell Hedstrom committed Jul 16, 2015
1 parent 94db9bb commit 6750efe
Show file tree
Hide file tree
Showing 67 changed files with 2,900 additions and 2,855 deletions.
8 changes: 4 additions & 4 deletions Build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ IF (MSVC OR MINGW)
ENDIF()

# GENERIC STEPS
file(GLOB SRC_FILES ${LOG_SRC}/*.h ${LOG_SRC}/*.hpp ${LOG_SRC}/*.cpp ${LOG_SRC}/*.ipp)
file(GLOB HEADER_FILES ${LOG_SRC}/*.h ${LOG_SRC}/*.hpp)
file(GLOB SRC_FILES ${LOG_SRC}/g3log/*.h ${LOG_SRC}/g3log/*.hpp ${LOG_SRC}/g3log/*.cpp ${LOG_SRC}/g3log/*.ipp)
file(GLOB HEADER_FILES ${LOG_SRC}/g3log/*.hpp ${LOG_SRC}/*.hpp)
#MESSAGE(" HEADER FILES ARE: ${HEADER_FILES}")

IF (MSVC OR MINGW)
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_unix.cpp)
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/g3log/crashhandler_unix.cpp)
ELSE()
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_windows.cpp ${LOG_SRC}/stacktrace_windows.hpp ${LOG_SRC}/stacktrace_windows.cpp)
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/g3log/crashhandler_windows.cpp ${LOG_SRC}/g3log/stacktrace_windows.hpp ${LOG_SRC}/g3log/stacktrace_windows.cpp)
ENDIF (MSVC OR MINGW)

set(SRC_FILES ${SRC_FILES} ${SRC_PLATFORM_SPECIFIC})
Expand Down
36 changes: 19 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# g3log is a KjellKod Logger
# 2010 @author Kjell Hedström, [email protected]
# ==================================================================
# 2010 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own
# risk and comes with no warranties.
#
# This code is yours to share, use and modify with no strings attached
# and no restrictions or obligations.
# ===================================================================
# ==========================================================================
# 2010 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own risk and comes
# with no warranties. This code is yours to share, use and modify with no
# strings attached and no restrictions or obligations.
#
# For more information see g3log/LICENSE or refer refer to http://unlicense.org
# ============================================================================*/


# Below are details for compiling on Windows and Linux
# by default only an example g3log binary is created
Expand Down Expand Up @@ -53,14 +52,6 @@ set(CMAKE_BUILD_TYPE Release)

project (g3log)

MESSAGE("Run 'make clean-cmake-files' to purge your build directory of CMake generated cache files")
add_custom_target(clean-cmake-files
COMMAND ${CMAKE_COMMAND} -P ${g3log_SOURCE_DIR}/CleanAll.cmake
)




# Detect 64 or 32 bit
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64-bit project
Expand Down Expand Up @@ -132,6 +123,17 @@ endif()
# INCLUDE (${g3log_SOURCE_DIR}/CPackLists.txt)


MESSAGE("\n\n
*******************************************************************
Please do 'make clean-cmake-files' before next cmake generation.
It is a good idea to purge your build directory of CMake
generated cache files
*******************************************************************
")
add_custom_target(clean-cmake-files
COMMAND ${CMAKE_COMMAND} -P ${g3log_SOURCE_DIR}/CleanAll.cmake
)




Expand Down
9 changes: 9 additions & 0 deletions CPackLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# ==========================================================================
# 2015 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own risk and comes
# with no warranties. This code is yours to share, use and modify with no
# strings attached and no restrictions or obligations.
#
# For more information see g3log/LICENSE or refer refer to http://unlicense.org
# ============================================================================*/



# INSTALL( TARGETS g3logger_shared
# ARCHIVE
Expand Down
8 changes: 8 additions & 0 deletions CleanAll.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# ==========================================================================
# 2015 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own risk and comes
# with no warranties. This code is yours to share, use and modify with no
# strings attached and no restrictions or obligations.
#
# For more information see g3log/LICENSE or refer refer to http://unlicense.org
# ============================================================================*/


set(cmake_generated ${CMAKE_BINARY_DIR}/CMakeCache.txt
${CMAKE_BINARY_DIR}/cmake_install.cmake
Expand Down
10 changes: 9 additions & 1 deletion GenerateMacroDefinitionsFile.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# ==========================================================================
# 2015 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own risk and comes
# with no warranties. This code is yours to share, use and modify with no
# strings attached and no restrictions or obligations.
#
# For more information see g3log/LICENSE or refer refer to http://unlicense.org
# ============================================================================*/

# Prerequisite : Options.cmake should run first

SET(HEADER "/** ==========================================================================
Expand All @@ -16,7 +24,7 @@ MESSAGE("End of COMPILE_DEFINITIONS")
SET(GENERATED_G3_DEFINITIONS src/g3log/generated_definitions.hpp)
file(REMOVE ${GENERATED_G3_DEFINITIONS} )
FILE(WRITE ${GENERATED_G3_DEFINITIONS} "// AUTO GENERATED MACRO DEFINITIONS FOR G3LOG\n\n")
FILE(APPEND ${GENERATED_G3_DEFINITIONS} ${HEADER}"\n")
FILE(APPEND ${GENERATED_G3_DEFINITIONS} "${HEADER}\n")
FILE(APPEND ${GENERATED_G3_DEFINITIONS} "#pragma once\n\n")
FILE(APPEND ${GENERATED_G3_DEFINITIONS} "// CMake induced definitions below. See g3log/Options.cmake for details.\n\n")

Expand Down
69 changes: 35 additions & 34 deletions example/main_contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,61 @@
* 2011 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own risk and comes
* with no warranties. This code is yours to share, use and modify with no
* strings attached and no restrictions or obligations.
*
*
* For more information see g3log/LICENSE or refer refer to http://unlicense.org
* ============================================================================*/

#include "g2logworker.hpp"
#include "g2log.hpp"
#include <iomanip>
#include <thread>
#include <iostream>


namespace
{
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
const std::string path_to_log_file = "./";
const std::string path_to_log_file = "./";
#else
const std::string path_to_log_file = "/tmp/";
const std::string path_to_log_file = "/tmp/";
#endif
}

namespace example_fatal
{
void killWithContractIfNonEqual(int first, int second)
{
CHECK(first == second) << "Test to see if contract works: onetwothree: " << 123 << ". This should be at the end of the log, and will exit this example";
}
void killWithContractIfNonEqual(int first, int second)
{
CHECK(first == second) << "Test to see if contract works: onetwothree: " << 123 << ". This should be at the end of the log, and will exit this example";
}
} // example fatal

int main(int argc, char** argv)
int main(int argc, char **argv)
{
double pi_d = 3.1415926535897932384626433832795;
float pi_f = 3.1415926535897932384626433832795f;

auto logger_n_handle = g2::LogWorker::createWithDefaultLogger(argv[0], path_to_log_file);
g2::initializeLogging(logger_n_handle.worker.get());
std::future<std::string> log_file_name = logger_n_handle.sink->call(&g2::FileSink::fileName);
std::cout << "* This is an example of g2log. It WILL exit by a failed CHECK(...)" << std::endl;
std::cout << "* that acts as a FATAL trigger. Please see the generated log and " << std::endl;
std::cout << "* compare to the code at:\n* \t g2log/test_example/main_contract.cpp" << std::endl;
std::cout << "*\n* Log file: [" << log_file_name.get() << "]\n\n" << std::endl;

LOGF(INFO, "Hi log %d", 123);
LOG(INFO) << "Test SLOG INFO";
LOG(DEBUG) << "Test SLOG DEBUG";
LOG(INFO) << "one: " << 1;
LOG(INFO) << "two: " << 2;
LOG(INFO) << "one and two: " << 1 << " and " << 2;
LOG(DEBUG) << "float 2.14: " << 1000/2.14f;
LOG(DEBUG) << "pi double: " << pi_d;
LOG(DEBUG) << "pi float: " << pi_f;
LOG(DEBUG) << "pi float (width 10): " << std::setprecision(10) << pi_f;
LOGF(INFO, "pi float printf:%f", pi_f);
double pi_d = 3.1415926535897932384626433832795;
float pi_f = 3.1415926535897932384626433832795f;

auto logger_n_handle = g2::LogWorker::createWithDefaultLogger(argv[0], path_to_log_file);
g2::initializeLogging(logger_n_handle.worker.get());
std::future<std::string> log_file_name = logger_n_handle.sink->call(&g2::FileSink::fileName);
std::cout << "* This is an example of g2log. It WILL exit by a failed CHECK(...)" << std::endl;
std::cout << "* that acts as a FATAL trigger. Please see the generated log and " << std::endl;
std::cout << "* compare to the code at:\n* \t g2log/test_example/main_contract.cpp" << std::endl;
std::cout << "*\n* Log file: [" << log_file_name.get() << "]\n\n" << std::endl;

LOGF(INFO, "Hi log %d", 123);
LOG(INFO) << "Test SLOG INFO";
LOG(DEBUG) << "Test SLOG DEBUG";
LOG(INFO) << "one: " << 1;
LOG(INFO) << "two: " << 2;
LOG(INFO) << "one and two: " << 1 << " and " << 2;
LOG(DEBUG) << "float 2.14: " << 1000 / 2.14f;
LOG(DEBUG) << "pi double: " << pi_d;
LOG(DEBUG) << "pi float: " << pi_f;
LOG(DEBUG) << "pi float (width 10): " << std::setprecision(10) << pi_f;
LOGF(INFO, "pi float printf:%f", pi_f);

// FATAL SECTION
int smaller = 1;
int larger = 2;
example_fatal::killWithContractIfNonEqual(smaller, larger);
int smaller = 1;
int larger = 2;
example_fatal::killWithContractIfNonEqual(smaller, larger);
}

Loading

0 comments on commit 6750efe

Please sign in to comment.