Skip to content

Commit 17bb030

Browse files
committed
feat(Logger): allow custom logger
1 parent 0f1c909 commit 17bb030

File tree

9 files changed

+497
-37
lines changed

9 files changed

+497
-37
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2019 - 2022 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#pragma once
25+
26+
#include <geode/basic/common.h>
27+
#include <geode/basic/logger_client.h>
28+
#include <geode/basic/pimpl.h>
29+
30+
namespace geode
31+
{
32+
class opengeode_basic_api ConsoleLoggerClient : public LoggerClient
33+
{
34+
public:
35+
ConsoleLoggerClient();
36+
~ConsoleLoggerClient();
37+
38+
private:
39+
void trace( const std::string &message ) override;
40+
41+
void debug( const std::string &message ) override;
42+
43+
void info( const std::string &message ) override;
44+
45+
void warn( const std::string &message ) override;
46+
47+
void error( const std::string &message ) override;
48+
49+
void critical( const std::string &message ) override;
50+
51+
private:
52+
IMPLEMENTATION_MEMBER( impl_ );
53+
};
54+
} // namespace geode
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2019 - 2022 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#pragma once
25+
26+
#include <geode/basic/common.h>
27+
28+
namespace geode
29+
{
30+
class opengeode_basic_api LoggerClient
31+
{
32+
public:
33+
virtual ~LoggerClient() = default;
34+
35+
virtual void trace( const std::string &message ) = 0;
36+
37+
virtual void debug( const std::string &message ) = 0;
38+
39+
virtual void info( const std::string &message ) = 0;
40+
41+
virtual void warn( const std::string &message ) = 0;
42+
43+
virtual void error( const std::string &message ) = 0;
44+
45+
virtual void critical( const std::string &message ) = 0;
46+
47+
protected:
48+
LoggerClient() = default;
49+
};
50+
} // namespace geode
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2019 - 2022 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#pragma once
25+
26+
#include <geode/basic/common.h>
27+
#include <geode/basic/pimpl.h>
28+
29+
namespace geode
30+
{
31+
class LoggerClient;
32+
} // namespace geode
33+
34+
namespace geode
35+
{
36+
class opengeode_basic_api LoggerManager
37+
{
38+
public:
39+
~LoggerManager();
40+
41+
static void register_client( std::unique_ptr< LoggerClient > &&client );
42+
43+
static void trace( const std::string &message );
44+
45+
static void debug( const std::string &message );
46+
47+
static void info( const std::string &message );
48+
49+
static void warn( const std::string &message );
50+
51+
static void error( const std::string &message );
52+
53+
static void critical( const std::string &message );
54+
55+
private:
56+
LoggerManager();
57+
58+
static LoggerManager &instance();
59+
60+
private:
61+
IMPLEMENTATION_MEMBER( impl_ );
62+
};
63+
} // namespace geode

src/geode/basic/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ add_geode_library(
2727
"bitsery_input.cpp"
2828
"bitsery_output.cpp"
2929
"common.cpp"
30+
"console_logger_client.cpp"
3031
"console_progress_logger_client.cpp"
3132
"filename.cpp"
3233
"identifier.cpp"
3334
"identifier_builder.cpp"
3435
"logger.cpp"
36+
"logger_manager.cpp"
3537
"permutation.cpp"
3638
"progress_logger.cpp"
3739
"progress_logger_manager.cpp"
@@ -48,12 +50,15 @@ add_geode_library(
4850
"attribute.h"
4951
"bitsery_archive.h"
5052
"common.h"
53+
"console_logger_client.h"
5154
"console_progress_logger_client.h"
5255
"factory.h"
5356
"filename.h"
5457
"identifier.h"
5558
"identifier_builder.h"
5659
"logger.h"
60+
"logger_client.h"
61+
"logger_manager.h"
5762
"mapping.h"
5863
"named_type.h"
5964
"passkey.h"

src/geode/basic/common.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@
2525

2626
#include <absl/memory/memory.h>
2727

28+
#include <geode/basic/console_logger_client.h>
2829
#include <geode/basic/console_progress_logger_client.h>
30+
#include <geode/basic/logger_manager.h>
2931
#include <geode/basic/progress_logger_manager.h>
3032

3133
namespace
3234
{
3335
OPENGEODE_LIBRARY_INITIALIZE( OpenGeode_basic )
3436
{
37+
geode::LoggerManager::register_client(
38+
absl::make_unique< geode::ConsoleLoggerClient >() );
39+
3540
geode::ProgressLoggerManager::register_client(
3641
absl::make_unique< geode::ConsoleProgressLoggerClient >() );
3742
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (c) 2019 - 2022 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#include <geode/basic/console_logger_client.h>
25+
26+
// clang-format off
27+
#include <spdlog/spdlog.h>
28+
#include <spdlog/sinks/stdout_color_sinks.h>
29+
// clang-format on
30+
31+
#include <geode/basic/logger.h>
32+
#include <geode/basic/pimpl_impl.h>
33+
34+
namespace geode
35+
{
36+
class ConsoleLoggerClient::Impl
37+
{
38+
public:
39+
Impl() : logger_impl_( spdlog::stdout_color_mt( "console" ) )
40+
{
41+
spdlog::set_level( spdlog::level::level_enum::trace );
42+
}
43+
44+
void trace( const std::string &message )
45+
{
46+
logger_impl_->trace( message );
47+
}
48+
49+
void debug( const std::string &message )
50+
{
51+
logger_impl_->debug( message );
52+
}
53+
54+
void info( const std::string &message )
55+
{
56+
logger_impl_->info( message );
57+
}
58+
59+
void warn( const std::string &message )
60+
{
61+
logger_impl_->warn( message );
62+
}
63+
64+
void error( const std::string &message )
65+
{
66+
logger_impl_->error( message );
67+
}
68+
69+
void critical( const std::string &message )
70+
{
71+
logger_impl_->critical( message );
72+
}
73+
74+
private:
75+
std::shared_ptr< spdlog::logger > logger_impl_;
76+
};
77+
78+
ConsoleLoggerClient::ConsoleLoggerClient() {}
79+
80+
ConsoleLoggerClient::~ConsoleLoggerClient() {}
81+
82+
void ConsoleLoggerClient::trace( const std::string &message )
83+
{
84+
impl_->trace( message );
85+
}
86+
87+
void ConsoleLoggerClient::debug( const std::string &message )
88+
{
89+
impl_->debug( message );
90+
}
91+
92+
void ConsoleLoggerClient::info( const std::string &message )
93+
{
94+
impl_->info( message );
95+
}
96+
97+
void ConsoleLoggerClient::warn( const std::string &message )
98+
{
99+
impl_->warn( message );
100+
}
101+
102+
void ConsoleLoggerClient::error( const std::string &message )
103+
{
104+
impl_->error( message );
105+
}
106+
107+
void ConsoleLoggerClient::critical( const std::string &message )
108+
{
109+
impl_->critical( message );
110+
}
111+
} // namespace geode

0 commit comments

Comments
 (0)