UE4/UE5 日志插件(基于spdlog)

2023-12-15 16:04:16

1 解决问题

对于高频日志序列化到本地的需求,spdlog肯定完美满足。

源码地址:https://github.com/gabime/spdlog

博主下载的版本为 spdlog-1.12.0,各位大佬可以根绝自己爱好选择。

2 过程介绍

大概目录:

SpdlogLibC目录下是对spdlog的封装:

bin里是.dll,lib放是.lib,include是.h文件。

SpdLoggerLib.Build.cs文件内容:

// Copyright Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;
using System.IO;


public class SpdLoggerLib : ModuleRules
{
	private string OuterLibPath
	{
		get { return Path.GetFullPath(Path.Combine(ModuleDirectory, "SpdlogLibC/")); }
	}

	public SpdLoggerLib(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;


		PublicIncludePaths.AddRange(
			new string[] { 
			
			}
			);

		PrivateIncludePaths.AddRange(
			new string[] {
				// ... add other private include paths required here ...
			}
			);
			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				"Projects"
				// ... add other public dependencies that you statically link with here ...
			}
			);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"CoreUObject",
				"Engine",
				"InputCore"// ... add private dependencies that you statically link with here ...	
			}
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				// ... add any modules that your module loads dynamically here ...
			}
			);

		if (Target.Platform == UnrealTargetPlatform.Win64)
		{
			string LibPath = OuterLibPath + "lib/x64/";
			string DllPath = OuterLibPath + "bin/x64/";
			string IncludePath = OuterLibPath + "include/";

			PublicSystemIncludePaths.AddRange(
				new string[] {
					IncludePath
				}
				);
			foreach (string file in Directory.GetFiles(LibPath))
			{
				PublicAdditionalLibraries.Add(file);
			}
			foreach (string file in Directory.GetFiles(DllPath))
			{
				string filename = Path.GetFileName(file);
				string outdll = "$(TargetOutputDir)/";
				outdll += filename;
				RuntimeDependencies.Add(outdll, file);
			}
		}
		else if (Target.Platform == UnrealTargetPlatform.Mac) { }
		else if (Target.Platform == UnrealTargetPlatform.Linux) { }
	}
}

3 使用简介

将插件拷贝到您的项目插件目录下:

蓝图里直接使用:

产生的日志在您的项目content根目录下:

4 插件特点

  • 屏蔽大量实现细节,只暴露一个接口到蓝图;
  • 足够高效,继承了spdlog的多线程、高并发;
  • 封装的原生dll库不区分debug和release,实用性更广。

5 下载地址

UE4/5高并发日志插件资源-CSDN文库

文章来源:https://blog.csdn.net/A_Pointer/article/details/135016645
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。