Lagrange
logger.h
1/*
2 * Copyright 2022 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/Logger.h>
15#include <lagrange/ui/Entity.h>
16
17namespace lagrange {
18namespace ui {
19
21template <typename... Args>
23 ui::Registry& r,
24 spdlog::level::level_enum level,
25 const std::string_view& fmt,
26 Args&&... args)
27{
28 struct LogOnceCache
29 {
30 std::unordered_set<std::string> messages;
31 };
32 auto& msgs = r.ctx().emplace<LogOnceCache>().messages;
33 if (msgs.count(fmt.data())) return;
34 logger().log(level, fmt, std::forward<Args>(args)...);
35 msgs.insert(fmt.data());
36}
37
38
39template <typename... Args>
40void log_trace_once(ui::Registry& r, const std::string_view& fmt, Args&&... args)
41{
42 log_once(r, spdlog::level::trace, fmt, std::forward<Args>(args)...);
43}
44
45template <typename... Args>
46void log_debug_once(ui::Registry& r, const std::string_view& fmt, Args&&... args)
47{
48 log_once(r, spdlog::level::debug, fmt, std::forward<Args>(args)...);
49}
50
51template <typename... Args>
52void log_info_once(ui::Registry& r, const std::string_view& fmt, Args&&... args)
53{
54 log_once(r, spdlog::level::info, fmt, std::forward<Args>(args)...);
55}
56
57template <typename... Args>
58void log_warn_once(ui::Registry& r, const std::string_view& fmt, Args&&... args)
59{
60 log_once(r, spdlog::level::warn, fmt, std::forward<Args>(args)...);
61}
62
63template <typename... Args>
64void log_error_once(ui::Registry& r, const std::string_view& fmt, Args&&... args)
65{
66 log_once(r, spdlog::level::err, fmt, std::forward<Args>(args)...);
67}
68
69template <typename... Args>
70void log_critical_once(ui::Registry& r, const std::string_view& fmt, Args&&... args)
71{
72 log_once(r, spdlog::level::critical, fmt, std::forward<Args>(args)...);
73}
74
75
76} // namespace ui
77} // namespace lagrange
LA_CORE_API spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:40
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
void log_once(ui::Registry &r, spdlog::level::level_enum level, const std::string_view &fmt, Args &&... args)
Log message once per registry lifetime.
Definition: logger.h:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Definition: project.cpp:27