-
Notifications
You must be signed in to change notification settings - Fork 112
[AIMIGRAPHX-371] Add logger with basic sinks #4469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eddieliao
wants to merge
19
commits into
develop
Choose a base branch
from
logger
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+810
−2
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
84d885b
Add basic logging functionality
eddieliao 5203de7
Formatting
eddieliao 625a627
Refactor logger to use variadic function and add record function
eddieliao b4a6ff6
Formatting
eddieliao 213fe9c
Add console and file logging using spdlog
eddieliao c818ecd
Formatting
eddieliao b6599ca
Add multi file logging; fix params not showing in logging
eddieliao 1fdb940
Fix color logging
eddieliao d8a8414
Add windows color logger
eddieliao 0cd773c
Add file-specific severity option
eddieliao 10a9ae1
Remove windows specific sinks, add unit tests
eddieliao 5c1fcff
Formatting
eddieliao 60b64c8
Cleanup
eddieliao 666e2c1
Merge branch 'develop' into logger
eddieliao 66f1d10
Remove spdlog usage, add thread safe access to sinks, update tests
eddieliao 5fbc196
Formatting
eddieliao 6889864
Add doc comments, error messages, use linux specific timestamp, remov…
eddieliao 3866156
Formatting
eddieliao 6d54ebd
Merge branch 'develop' into logger
eddieliao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,4 +29,4 @@ pybind/pybind11@3e9dfa2866941655c56877882565e7577de6fc7b --build | |
| msgpack/[email protected] -DMSGPACK_BUILD_TESTS=Off -DMSGPACK_BUILD_EXAMPLES=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5 | ||
| [email protected] -DCMAKE_POSITION_INDEPENDENT_CODE=On | ||
| ROCm/composable_kernel@b7775add2d28251674d81e220cd4a857b90b997a -DCK_BUILD_JIT_LIB=On -DCMAKE_POSITION_INDEPENDENT_CODE=On | ||
| ROCm/rocMLIR@b6c46dd51895148be0957fb0ba2d72b3efc4b87b -DBUILD_FAT_LIBROCKCOMPILER=On -DLLVM_INCLUDE_TESTS=Off | ||
| ROCm/rocMLIR@3a034fd4fa6c25ada90f1786700748b2f58aaf85 -DBUILD_FAT_LIBROCKCOMPILER=On -DLLVM_INCLUDE_TESTS=Off | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| /* | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
| #ifndef MIGRAPHX_GUARD_MIGRAPHX_LOGGER_HPP | ||
| #define MIGRAPHX_GUARD_MIGRAPHX_LOGGER_HPP | ||
|
|
||
| #include <migraphx/env.hpp> | ||
| #include <migraphx/source_location.hpp> | ||
| #include <functional> | ||
| #include <sstream> | ||
|
|
||
| namespace migraphx { | ||
| inline namespace MIGRAPHX_INLINE_NS { | ||
eddieliao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| namespace log { | ||
|
|
||
| enum class severity | ||
| { | ||
| none, | ||
| error, | ||
| warn, | ||
| info, | ||
| debug, | ||
| trace | ||
| }; | ||
|
|
||
| using sink = std::function<void(severity, std::string_view, source_location)>; | ||
|
|
||
| /** | ||
| * @brief Records a log message. This will invoke the callback for all sinks that are enabled at the | ||
| * given severity. | ||
| * | ||
| * @param s The severity of the log message | ||
| * @param msg The message to log | ||
| * @param loc The source location of the log message | ||
| */ | ||
| void record(severity s, std::string_view msg, source_location loc = source_location::current()); | ||
|
|
||
| /** | ||
| * @brief Checks if any sink is enabled at the given severity. | ||
| * | ||
| * @param level The severity to check | ||
| * @return true if any sink is enabled at the given severity, false otherwise | ||
| */ | ||
| bool is_enabled(severity level); | ||
|
|
||
| /** | ||
| * @brief Adds a sink to the logger. | ||
| * | ||
| * @param s The sink to add | ||
| * @param level The severity level of the sink | ||
| * @return The ID of the added sink | ||
| */ | ||
| size_t add_sink(sink s, severity level = severity::info); | ||
|
|
||
| /** | ||
| * @brief Removes a sink from the logger. | ||
| * | ||
| * @param id The ID of the sink to remove | ||
| */ | ||
| void remove_sink(size_t id); | ||
|
|
||
| /** | ||
| * @brief Sets the severity level for a specific sink. | ||
| * | ||
| * @param level The severity level to set | ||
| * @param id The ID of the sink to set the severity for; defaults to 0 for the stderr sink | ||
| */ | ||
| void set_severity(severity level, size_t id = 0); | ||
|
|
||
| /** | ||
| * @brief Adds a file sink to the logger. | ||
| * | ||
| * @param filename The name of the file to log to | ||
| * @param level The severity level of the file logger | ||
| * @return The ID of the added file logger | ||
| */ | ||
| size_t add_file_logger(std::string_view filename, severity level = severity::info); | ||
|
|
||
| template <severity Severity> | ||
| struct print | ||
| { | ||
| print(source_location ploc = source_location::current()) : loc(ploc) {} | ||
|
|
||
| struct stream | ||
| { | ||
| template <class T> | ||
| stream(severity ps, T&& x, source_location ploc = source_location::current()) | ||
| : s(ps), loc(ploc), enabled(is_enabled(s)) | ||
eddieliao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| if(enabled) | ||
| ss << x; | ||
| } | ||
|
|
||
| template <class T> | ||
| stream& operator<<(T&& x) | ||
| { | ||
| if(enabled) | ||
| ss << x; | ||
| return *this; | ||
| } | ||
|
|
||
| ~stream() | ||
| { | ||
| if(enabled) | ||
| record(s, ss.str(), loc); | ||
| } | ||
|
|
||
| stream(const stream&) = delete; | ||
| stream& operator=(const stream&) = delete; | ||
|
|
||
| severity s = severity::none; | ||
| source_location loc; | ||
| bool enabled; | ||
| std::ostringstream ss; | ||
| }; | ||
|
|
||
| template <class T> | ||
| stream operator<<(T&& x) | ||
| { | ||
| return stream{Severity, x, loc}; | ||
| } | ||
|
|
||
| template <class... Ts> | ||
| void operator()(Ts&&... xs) const | ||
| { | ||
| if(is_enabled(Severity)) | ||
| { | ||
| std::ostringstream ss; | ||
| (ss << ... << xs); | ||
| record(Severity, ss.str(), loc); | ||
| } | ||
| } | ||
|
|
||
| print(const print&) = delete; | ||
| print& operator=(const print&) = delete; | ||
|
|
||
| source_location loc; | ||
| }; | ||
|
|
||
| using error = print<severity::error>; | ||
| using warn = print<severity::warn>; | ||
| using info = print<severity::info>; | ||
| using debug = print<severity::debug>; | ||
| using trace = print<severity::trace>; | ||
|
|
||
| } // namespace log | ||
| } // namespace MIGRAPHX_INLINE_NS | ||
| } // namespace migraphx | ||
| #endif | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.