mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:52:45 +00:00 
			
		
		
		
	AK: Add an optional 'extra' descriptive field to ScopeLogger
Often it's easier to know what the functions are doing with a unique name next to the function's name :)
This commit is contained in:
		
							parent
							
								
									d301bd6732
								
							
						
					
					
						commit
						080f2c0e3e
					
				
					 1 changed files with 18 additions and 3 deletions
				
			
		|  | @ -13,27 +13,42 @@ namespace AK { | ||||||
| class ScopeLogger { | class ScopeLogger { | ||||||
| public: | public: | ||||||
| #ifdef DEBUG_SPAM | #ifdef DEBUG_SPAM | ||||||
|     ScopeLogger(const SourceLocation& location = SourceLocation::current()) |     ScopeLogger(StringView extra, const SourceLocation& location = SourceLocation::current()) | ||||||
|         : m_location(location) |         : m_location(location) | ||||||
|  |         , m_extra(extra) | ||||||
|     { |     { | ||||||
|         StringBuilder sb; |         StringBuilder sb; | ||||||
| 
 | 
 | ||||||
|         for (auto indent = m_depth++; indent > 0; indent--) |         for (auto indent = m_depth++; indent > 0; indent--) | ||||||
|             sb.append(' '); |             sb.append(' '); | ||||||
|         dbgln("\033[1;{}m{}entering {}\033[0m", m_depth % 8 + 30, sb.to_string(), m_location); |         if (m_extra.is_empty()) | ||||||
|  |             dbgln("\033[1;{}m{}entering {}\033[0m", m_depth % 8 + 30, sb.to_string(), m_location); | ||||||
|  |         else | ||||||
|  |             dbgln("\033[1;{}m{}entering {} ({})\033[0m", m_depth % 8 + 30, sb.to_string(), m_location, m_extra); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     ScopeLogger(SourceLocation location = SourceLocation::current()) | ||||||
|  |         : ScopeLogger({}, move(location)) | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     ~ScopeLogger() |     ~ScopeLogger() | ||||||
|     { |     { | ||||||
|         StringBuilder sb; |         StringBuilder sb; | ||||||
| 
 | 
 | ||||||
|  |         auto depth = m_depth; | ||||||
|         for (auto indent = --m_depth; indent > 0; indent--) |         for (auto indent = --m_depth; indent > 0; indent--) | ||||||
|             sb.append(' '); |             sb.append(' '); | ||||||
|         dbgln("\033[1;{}m{}leaving {}\033[0m", (m_depth + 1) % 8 + 30, sb.to_string(), m_location); |         if (m_extra.is_empty()) | ||||||
|  |             dbgln("\033[1;{}m{}leaving {}\033[0m", depth % 8 + 30, sb.to_string(), m_location); | ||||||
|  |         else | ||||||
|  |             dbgln("\033[1;{}m{}leaving {} ({})\033[0m", depth % 8 + 30, sb.to_string(), m_location, m_extra); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     static inline size_t m_depth = 0; |     static inline size_t m_depth = 0; | ||||||
|     SourceLocation m_location; |     SourceLocation m_location; | ||||||
|  |     StringView m_extra; | ||||||
| #else | #else | ||||||
|     ScopeLogger() = default; |     ScopeLogger() = default; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ali Mohammad Pur
						Ali Mohammad Pur