| 1 |
/* |
| 2 |
* Copyright 2026 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef SkLog_DEFINED |
| 9 |
#define SkLog_DEFINED |
| 10 |
|
| 11 |
#include <cstdarg> |
| 12 |
|
| 13 |
#include "include/private/base/SkAPI.h" |
| 14 |
#include "include/private/base/SkAttributes.h" |
| 15 |
#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep |
| 16 |
#include "include/private/base/SkLogPriority.h" |
| 17 |
|
| 18 |
#if !defined(SkLog) |
| 19 |
// To be implemented per platform. |
| 20 |
void SkLogVAList(SkLogPriority priority, const char format[], va_list args) SK_PRINTF_LIKE(2, 0); |
| 21 |
void SK_SPI SkLog(SkLogPriority priority, const char format[], ...) SK_PRINTF_LIKE(2, 3); |
| 22 |
#endif |
| 23 |
|
| 24 |
/** |
| 25 |
* TODO (b/469441457): SKGPU_GRAPHITE_LOWEST_ACTIVE_LOG_PRIORITY Was the config used to set the log |
| 26 |
* priority, so we check for that define as well. Eventually, we should move clients using this |
| 27 |
* define to the new one. |
| 28 |
*/ |
| 29 |
#if defined (SKGPU_GRAPHITE_LOWEST_ACTIVE_LOG_PRIORITY) |
| 30 |
#define SKIA_LOWEST_ACTIVE_LOG_PRIORITY SKGPU_GRAPHITE_LOWEST_ACTIVE_LOG_PRIORITY |
| 31 |
#endif |
| 32 |
|
| 33 |
#if !defined(SKIA_LOWEST_ACTIVE_LOG_PRIORITY) |
| 34 |
#ifdef SK_DEBUG |
| 35 |
#define SKIA_LOWEST_ACTIVE_LOG_PRIORITY SkLogPriority::kWarning |
| 36 |
#else |
| 37 |
#define SKIA_LOWEST_ACTIVE_LOG_PRIORITY SkLogPriority::kError |
| 38 |
#endif |
| 39 |
#endif |
| 40 |
|
| 41 |
#define SKIA_LOG(priority, fmt, ...) \ |
| 42 |
do { \ |
| 43 |
if constexpr (priority <= SKIA_LOWEST_ACTIVE_LOG_PRIORITY) { \ |
| 44 |
if constexpr (priority == SkLogPriority::kFatal) { \ |
| 45 |
SK_ABORT("[skia] " fmt, ##__VA_ARGS__); \ |
| 46 |
} \ |
| 47 |
else { \ |
| 48 |
SkLog(priority, "[skia] " fmt "\n", ##__VA_ARGS__); \ |
| 49 |
} \ |
| 50 |
} \ |
| 51 |
} while (0) |
| 52 |
|
| 53 |
#define SKIA_LOG_F(fmt, ...) SKIA_LOG(SkLogPriority::kFatal, "** ERROR ** " fmt, ##__VA_ARGS__) |
| 54 |
#define SKIA_LOG_E(fmt, ...) SKIA_LOG(SkLogPriority::kError, "** ERROR ** " fmt, ##__VA_ARGS__) |
| 55 |
#define SKIA_LOG_W(fmt, ...) SKIA_LOG(SkLogPriority::kWarning, "WARNING - " fmt, ##__VA_ARGS__) |
| 56 |
#define SKIA_LOG_D(fmt, ...) SKIA_LOG(SkLogPriority::kDebug, fmt, ##__VA_ARGS__) |
| 57 |
|
| 58 |
#endif // SkLog_DEFINED |