2021-01-23 14:47:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Denis Campredon <deni_@hotmail.fr>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-01-23 14:47:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-04-25 03:05:38 +00:00
|
|
|
#include <AK/SourceLocation.h>
|
2021-01-23 14:47:20 +00:00
|
|
|
#include <AK/StringBuilder.h>
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
class ScopeLogger {
|
|
|
|
public:
|
2021-04-25 03:05:38 +00:00
|
|
|
#ifdef DEBUG_SPAM
|
|
|
|
ScopeLogger(const SourceLocation& location = SourceLocation::current())
|
|
|
|
: m_location(location)
|
2021-01-23 14:47:20 +00:00
|
|
|
{
|
|
|
|
StringBuilder sb;
|
|
|
|
|
|
|
|
for (auto indent = m_depth++; indent > 0; indent--)
|
|
|
|
sb.append(' ');
|
2021-04-25 03:05:38 +00:00
|
|
|
dbgln("\033[1;{}m{}entering {}\033[0m", m_depth % 8 + 30, sb.to_string(), m_location);
|
2021-01-23 14:47:20 +00:00
|
|
|
}
|
|
|
|
~ScopeLogger()
|
|
|
|
{
|
|
|
|
StringBuilder sb;
|
|
|
|
|
|
|
|
for (auto indent = --m_depth; indent > 0; indent--)
|
|
|
|
sb.append(' ');
|
2021-04-25 03:05:38 +00:00
|
|
|
dbgln("\033[1;{}m{}leaving {}\033[0m", (m_depth + 1) % 8 + 30, sb.to_string(), m_location);
|
2021-01-23 14:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static inline size_t m_depth = 0;
|
2021-04-25 03:05:38 +00:00
|
|
|
SourceLocation m_location;
|
|
|
|
#else
|
|
|
|
ScopeLogger() = default;
|
|
|
|
#endif
|
2021-01-23 14:47:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::ScopeLogger;
|