mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 14:50:05 +00:00 
			
		
		
		
	Redirect Qt and mbgl logs to spdlog
This commit is contained in:
		
							parent
							
								
									a76da1caac
								
							
						
					
					
						commit
						4938b7c112
					
				
					 2 changed files with 44 additions and 1 deletions
				
			
		
							
								
								
									
										2
									
								
								external/maplibre-native
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								external/maplibre-native
									
										
									
									
										vendored
									
									
								
							|  | @ -1 +1 @@ | ||||||
| Subproject commit 237928075a8391e1c1469f79d74458d566075012 | Subproject commit 23e73b2b99088ab88801df92520fb397bc58d601 | ||||||
|  | @ -31,6 +31,9 @@ static const std::string logPrefix_ = "scwx::main"; | ||||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||||
| 
 | 
 | ||||||
| static void OverrideDefaultStyle(const std::vector<std::string>& args); | static void OverrideDefaultStyle(const std::vector<std::string>& args); | ||||||
|  | static void QtLogMessageHandler(QtMsgType                 messageType, | ||||||
|  |                                 const QMessageLogContext& context, | ||||||
|  |                                 const QString&            message); | ||||||
| 
 | 
 | ||||||
| int main(int argc, char* argv[]) | int main(int argc, char* argv[]) | ||||||
| { | { | ||||||
|  | @ -45,6 +48,9 @@ int main(int argc, char* argv[]) | ||||||
|    scwx::util::Logger::Initialize(); |    scwx::util::Logger::Initialize(); | ||||||
|    spdlog::set_level(spdlog::level::debug); |    spdlog::set_level(spdlog::level::debug); | ||||||
| 
 | 
 | ||||||
|  |    // Install Qt Message Handler
 | ||||||
|  |    qInstallMessageHandler(&QtLogMessageHandler); | ||||||
|  | 
 | ||||||
|    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); |    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); | ||||||
| 
 | 
 | ||||||
|    QApplication a(argc, argv); |    QApplication a(argc, argv); | ||||||
|  | @ -170,3 +176,40 @@ OverrideDefaultStyle([[maybe_unused]] const std::vector<std::string>& args) | ||||||
|    } |    } | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void QtLogMessageHandler(QtMsgType                 messageType, | ||||||
|  |                          const QMessageLogContext& context, | ||||||
|  |                          const QString&            message) | ||||||
|  | { | ||||||
|  |    static const auto qtLogger_ = scwx::util::Logger::Create("qt"); | ||||||
|  | 
 | ||||||
|  |    static const std::unordered_map<QtMsgType, spdlog::level::level_enum> | ||||||
|  |       levelMap_ {{QtMsgType::QtDebugMsg, spdlog::level::level_enum::debug}, | ||||||
|  |                  {QtMsgType::QtInfoMsg, spdlog::level::level_enum::info}, | ||||||
|  |                  {QtMsgType::QtWarningMsg, spdlog::level::level_enum::warn}, | ||||||
|  |                  {QtMsgType::QtCriticalMsg, spdlog::level::level_enum::err}, | ||||||
|  |                  {QtMsgType::QtFatalMsg, spdlog::level::level_enum::critical}}; | ||||||
|  | 
 | ||||||
|  |    spdlog::level::level_enum level = spdlog::level::level_enum::info; | ||||||
|  |    auto                      it    = levelMap_.find(messageType); | ||||||
|  |    if (it != levelMap_.cend()) | ||||||
|  |    { | ||||||
|  |       level = it->second; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    spdlog::source_loc location {}; | ||||||
|  |    if (context.file != nullptr && context.function != nullptr) | ||||||
|  |    { | ||||||
|  |       location = {context.file, context.line, context.function}; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    if (context.category != nullptr) | ||||||
|  |    { | ||||||
|  |       qtLogger_->log( | ||||||
|  |          location, level, "[{}] {}", context.category, message.toStdString()); | ||||||
|  |    } | ||||||
|  |    else | ||||||
|  |    { | ||||||
|  |       qtLogger_->log(location, level, message.toStdString()); | ||||||
|  |    } | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat