Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@bwrsandman
Copy link
Contributor

Add levels to public API.
Default to old stderr logging method.
Add function pointer and userdata pointer as static globals.

Implements #179

@bwrsandman bwrsandman marked this pull request as ready for review January 3, 2024 05:25
bwrsandman added a commit to bwrsandman/openblack that referenced this pull request Jan 3, 2024
@bwrsandman
Copy link
Contributor Author

bwrsandman commented Jan 3, 2024

Example use of custom logger using spdlog in c++

void unshield_log_handler([[maybe_unused]] void* userdata, int level, const char* file, int line, const char* format, va_list args)
{
	spdlog::level::level_enum spdlogLevel;
	switch (level)
	{
	case UNSHIELD_LOG_LEVEL_TRACE:
		spdlogLevel = spdlog::level::trace;
		break;
	case UNSHIELD_LOG_LEVEL_WARNING:
		spdlogLevel = spdlog::level::warn;
		break;
	case UNSHIELD_LOG_LEVEL_ERROR:
		spdlogLevel = spdlog::level::err;
		break;
	}

	// Get the length of the message
	va_list args_copy;
	va_copy(args_copy, args);
	int length = vsnprintf(nullptr, 0, format, args_copy) + 1;
	va_end(args_copy);

	std::vector<char> message(length);
	vsnprintf(message.data(), message.size(), format, args);

	SPDLOG_LOGGER_CALL(spdlog::get("filesystem"), spdlogLevel, "unshield: {}", message.data());
}

@bwrsandman bwrsandman force-pushed the log-handler branch 2 times, most recently from a97300a to 6da5ca2 Compare January 3, 2024 06:42
bwrsandman added a commit to bwrsandman/openblack that referenced this pull request Jan 3, 2024
@twogood
Copy link
Owner

twogood commented Jan 3, 2024

@bwrsandman sorry about the merge conflict!

@twogood twogood self-assigned this Jan 3, 2024
Default to old stderr logging method.
Add function pointer and userdata pointer as static globals.
@bwrsandman
Copy link
Contributor Author

rebased!

bwrsandman added a commit to bwrsandman/openblack that referenced this pull request Jan 3, 2024
bwrsandman added a commit to bwrsandman/openblack that referenced this pull request Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.