Skip to content

Commit

Permalink
DB logger sample (#4759)
Browse files Browse the repository at this point in the history
* sample(DBLogger): New sample to demonstrate DB logging to a file. (#4750)

* sample(DBLogger): Create messages via SQL logger in a thread (#4750)

* sample(DBLogger): Save messages from SQL files to an SQL database (works with SQLite) (#4750)

* chore(Makefile): Data samples depend on PocoUtil (#4750)

* sample(DBLogger): Refactored DBLogger with std::filesystem::directory_iterator and std::thread.

* sample(DBLogger): Add missing include <condition_variable>

* sample(DBLogger): Extracted log scanning and inserting functionality to class SQLLogInserter.

* sample(DBLogger): Create new logging table only when using demo messages option.

* feat(DBLogger): VS projects

* sample(DBLogger): Acquire options from configuration file.

* feat(DBLogger): regenerate VS projects (progen file change)

* sample(DBLogger): Add example DBLogger.properties file.

* sample(DBLogger): Process as much as possible when stopping processing.

* sample(DBLogger): Meaningful defaults in properties file.

* sample(DBLogger): Verify validity of database session on startup.

* sample(DBLogger): Configure demo SQL channel in properties file.

* chore(DBLogger): style and warnings

---------

Co-authored-by: Aleksandar Fabijanic <[email protected]>
Co-authored-by: Alex Fabijanic <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2024
1 parent 2815ea4 commit 52959b9
Show file tree
Hide file tree
Showing 21 changed files with 3,208 additions and 255 deletions.
4 changes: 0 additions & 4 deletions Data/SQLite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ else()
POCO_SOURCES(SQLITE_SRCS sqlite3
src/sqlite3.c
)

POCO_HEADERS(SQLITE_SRCS sqlite3
src/sqlite3.h
)
endif()

# Version Resource
Expand Down
1 change: 1 addition & 0 deletions Data/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ add_subdirectory(RowFormatter)
add_subdirectory(Tuple)
add_subdirectory(TypeHandler)
add_subdirectory(WebNotifier)
add_subdirectory(DBLogger)
14 changes: 14 additions & 0 deletions Data/samples/DBLogger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Sources
file(GLOB SRCS_G "src/*.cpp")
POCO_SOURCES_AUTO(DBLOGGER_SRCS ${SRCS_G})

# Headers
file(GLOB_RECURSE HDRS_G "src/*.h")
POCO_HEADERS_AUTO(DBLOGGER_SRCS ${HDRS_G})

add_executable(DBLogger ${DBLOGGER_SRCS})

target_link_libraries(DBLogger PUBLIC Poco::Util Poco::DataSQLite)

add_custom_target(DBLogger-properties SOURCES DBLogger.properties)
11 changes: 11 additions & 0 deletions Data/samples/DBLogger/DBLogger.progen
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
vc.project.guid = ${vc.project.guidFromName}
vc.project.name = ${vc.project.baseName}
vc.project.target = ${vc.project.name}
vc.project.type = executable
vc.project.pocobase = ..\\..\\..
vc.project.platforms = Win32
vc.project.configurations = debug_shared, release_shared, debug_static_mt, release_static_mt, debug_static_md, release_static_md
vc.project.prototype = ${vc.project.name}_vs90.vcproj
vc.project.compiler.include = ..\\..\\..\\Foundation\\include;..\\..\\..\\JSON\\include;..\\..\\..\\XML\\include;..\\..\\..\\Util\\include;..\\..\\..\\Data\\include;..\\..\\..\\Data\\SQLParser;..\\Data\\SQLParser\\src;..\\..\\..\\Data\\SQLite\\include
vc.project.compiler.additionalOptions = /Zc:__cplusplus
vc.project.linker.dependencies = iphlpapi.lib
67 changes: 67 additions & 0 deletions Data/samples/DBLogger/DBLogger.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

#
# Database inserter (destination)
#

#
# Destination database parameters:
#
# (Mandatory) Database connector (for example sqlite)
#
DBLogger.connector = sqlite

#
# (Mandatory) Database connection string (connector specific)
#
DBLogger.constring = demo-logs.db3

#
# (Optional) Number of workers to insert logs into the database in parallel (default = 2)
#
# DBLogger.workers = 2

# ----------------------------------------------------------------

#
# (Optional) Create demo SQL messages for testing purposes (default = false)
#
DBLogger.demo = true

logging.loggers.root.channel = console
logging.loggers.root.level = information

logging.channels.console.class = ColorConsoleChannel
logging.channels.console.pattern = %L%Y-%m-%d %H:%M:%S.%i [%p] : %t

#
# SQL logger to create demo messages
# NOTE: Do not rename the logger.
#

logging.loggers.sqldemo.channel = sql
logging.loggers.sqldemo.name = SQLDemo
logging.loggers.sqldemo.level = debug

logging.channels.sql.class = SQLChannel
logging.channels.sql.name = DBLogger

#
# (Mandatory) Directory to scan for .sql files
#
logging.channels.sql.directory = .

#
# NOTE: Do not configure database to create SQL logger files
#
# logging.channels.sql.connector = SQLite
# logging.channels.sql.connect = DBLogger.db3

logging.channels.sql.timeout = 3000
logging.channels.sql.minBatch = 5
logging.channels.sql.maxBatch = 1000
logging.channels.sql.bulk = true
logging.channels.sql.table = T_LOG

logging.channels.sql.throw = false
logging.channels.sql.file = ${application.baseName}.sql

663 changes: 663 additions & 0 deletions Data/samples/DBLogger/DBLogger_vs160.vcxproj

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions Data/samples/DBLogger/DBLogger_vs160.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Header Files">
<UniqueIdentifier>{8747f452-7c1b-44d2-b0e5-1681f3dab78e}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files">
<UniqueIdentifier>{f73ed930-0047-402d-8e77-3b9b9ddbc3a7}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\SQLLogInserter.cpp" />
<ClCompile Include="src\DBLogger.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
978 changes: 978 additions & 0 deletions Data/samples/DBLogger/DBLogger_vs170.vcxproj

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions Data/samples/DBLogger/DBLogger_vs170.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Header Files">
<UniqueIdentifier>{b2b53da4-c45b-4734-9096-6c64453817a6}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files">
<UniqueIdentifier>{654b0a83-74d5-4a84-b813-6493ce240b90}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\SQLLogInserter.cpp" />
<ClCompile Include="src\DBLogger.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Loading

0 comments on commit 52959b9

Please sign in to comment.