ue4 打个log难如狗
注意:
把log相关两个宏写到类中,并编译后,在输出日志的位置的Categories关键字过滤的位置看不到自己的标签是因为需要先运行一次,输出一些这个标签的log后,这个自定义的标签才会显示在这
原文 https://wiki.unrealengine.com/Logs,_Printing_Messages_To_Yourself_During_Runtime#Log_an_FString
http://www.cnblogs.com/blueroses/p/6037981.html
说明:本文为Wiki上的RAMA大神文章的大致翻译
游戏模式:
在游戏模式下,你需要在游戏的快捷方式后面加 -Log,才会在游戏中显示。
编辑器模式(Play In Editor):
你可以在Output窗口中看到log信息。
如果想在游戏中看到,需要到Engin.ini中修改参数添加"GameCommandLine=-log,如果没有,则需要按~,输入-Log命令开启。
快速使用:
UE_LOG(LogTemp, Warning, TEXT("Your message"));
不用设置标签,简单快速。
设置拥有自己标签的Log:
在你的游戏头文件中加入:

//General Log
DECLARE_LOG_CATEGORY_EXTERN(YourLog, Log, All); //Logging during game startup
DECLARE_LOG_CATEGORY_EXTERN(YourInit, Log, All); //Logging for your AI system
DECLARE_LOG_CATEGORY_EXTERN(YourAI, Log, All); //Logging for Critical Errors that must always be addressed
DECLARE_LOG_CATEGORY_EXTERN(YourCriticalErrors, Log, All);

这样输出的Log你就可以知道是哪个部分的,这也是UE_Log很有用的原因。
在你的游戏Cpp文件中:

//General Log
DEFINE_LOG_CATEGORY(YourLog); //Logging during game startup
DEFINE_LOG_CATEGORY(YourInit); //Logging for your AI system
DEFINE_LOG_CATEGORY(YourAI); //Logging for Critical Errors that must always be addressed
DEFINE_LOG_CATEGORY(YourCriticalErrors);

Log格式:
Log Message
//"This is a message to yourself during runtime!"
UE_LOG(YourLog,Warning,TEXT("This is a message to yourself during runtime!"));
Log an FString
%s strings are wanted as TCHAR* by Log, so use *FString()
//"MyCharacter's Name is %s"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Name is %s"), *MyCharacter->GetName() );
Log an Int
//"MyCharacter's Health is %d"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %d"), MyCharacter->Health );
Log a Float
//"MyCharacter's Health is %f"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %f"), MyCharacter->Health );
Log an FVector
//"MyCharacter's Location is %s"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Location is %s"),
*MyCharacter->GetActorLocation().ToString());
Log an FName
//"MyCharacter's FName is %s"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's FName is %s"),
*MyCharacter->GetFName().ToString());
Log an FString,Int,Float
//"%s has health %d, which is %f percent of total health"
UE_LOG(YourLog,Warning,TEXT("%s has health %d, which is %f percent of total health"),
*MyCharacter->GetName(), MyCharacter->Health, MyCharacter->HealthPercent);
Log的颜色设置:
//"this is Grey Text"
UE_LOG(YourLog,Log,TEXT("This is grey text!"));
//"this is Yellow Text"
UE_LOG(YourLog,Warning,TEXT("This is yellow text!"));
//"This is Red Text"
UE_LOG(YourLog,Error,TEXT("This is red text!"));
可以看得出第二个参数是是用来控制颜色的。
传递客户端信息(网络模式):
PlayerController->ClientMessage("Your Message");
命令行命令以及Engine.ini配置:
Log conventions (in the console, ini files, or environment variables)
[cat] = a category for the command to operate on, or 'global' for all categories.
标签,没有设置就显示所有的Log
[level] = verbosity level, one of: none, error, warning, display, log, verbose, all, default
关卡,显示某某关卡的Log
At boot time, compiled in default is overridden by ini files setting, which is overridden by command line
Log console command usage

Log list - list all log categories
Log list [string] - list all log categories containing a substring
Log reset - reset all log categories to their boot-time default
Log [cat] - toggle the display of the category [cat]
Log [cat] off - disable display of the category [cat]
Log [cat] on - resume display of the category [cat]
Log [cat] [level] - set the verbosity level of the category [cat]
Log [cat] break - toggle the debug break on display of the category [cat]

Log command line
-LogCmds=\"[arguments],[arguments]...\" - applies a list of console commands at boot time
-LogCmds=\"foo verbose, bar off\" - turns on the foo category and turns off the bar category
Environment variables
Any command line option can be set via the environment variable UE-CmdLineArgs
set UE-CmdLineArgs=\"-LogCmds=foo verbose breakon, bar off\"
Config file
In DefaultEngine.ini or Engine.ini:
[Core.Log]
global=[default verbosity for things not listed later]
[cat]=[level]
foo=verbose break
Rama后面的一篇文章提供了显示代码行号、函数名称、类名等功能:
https://wiki.unrealengine.com/Logs,_Printing_the_Class_Name,_Function_Name,_Line_Number_of_your_Calling_Code!
ue4 打个log难如狗的更多相关文章
- JavaScript面向对象轻松入门之多态(demo by ES5、ES6、TypeScript)
多态(Polymorphism)按字面的意思就是"多种状态",同样的行为(方法)在不同对象上有不同的状态. 在OOP中很多地方都要用到多态的特性,比如同样是点击鼠标右键,点击快捷方 ...
- javascript重修之书(一):如何判断变量的数据类型
javascript重修之书(一):如何判断变量的数据类型 一:检测值类型 基本类型:(Undefined.Null.Boolean.Number和String) javascript之所以被称为一门 ...
- js各种继承方式汇总
js中的各种继承实现汇总 首先定义一个父类: function Animal(name) { this.name = name || '动物' this.sleep = function () { c ...
- 前端综合学习笔记---异步、ES6/7、Module、Promise同步 vs 异步
同步 vs 异步 先看下面的 demo,根据程序阅读起来表达的意思,应该是先打印100,1秒钟之后打印200,最后打印300.但是实际运行根本不是那么回事 console.log(100) setTi ...
- Vuex、axios、跨域请求处理和import/export的注意问题
一.Vuex 1.介绍 vuex是一个专门为Vue.js设计的集中式状态管理架构. 对于状态,我们把它理解为在data中需要共享给其他组件使用的部分数据. Vuex和单纯的全局对象有以下不同: 1. ...
- web笔试
类型判断用到哪些方法? typeof和instanceof 值类型和引用类型的区别? 根据 JavaScript中的变量类型传递方式,又分为值类型和引用类型,在参数传递方式上,值类型是按值传递,引用类 ...
- 潭州课堂25班:Ph201805201 WEB 之 JS 第五课 (课堂笔记)
算数运算符 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- Javascript MVC 学习笔记(一) 模型和数据
写在前面 近期在看<MVC的Javascript富应用开发>一书.本来是抱着一口气读完的想法去看的.结果才看了一点就傻眼了:太多不懂的地方了. 仅仅好看一点查一点,一点一点往下看吧,进度虽 ...
- 《前端JavaScript面试技巧》笔记一
思考: 拿到一个面试题,你第一时间看到的是什么 -> 考点 又如何看待网上搜出来的永远也看不完的题海 -> 不变应万变 如何对待接下来遇到的面试题 -> 题目到知识再到题目 知识体系 ...
随机推荐
- Redis之java增删改查
jedis是java的redis客户端实现,要使用jedis须要加入jedis的maven依赖: <dependency> <groupId>redis.clients< ...
- python mmap使用记录
1.写文件 with open('??', 'r+b') as f: with contextlib.closing(mmap.mmap(f.fileno(), size, flags=mmap.MA ...
- clone和dup
ruby中clone和dup都是对一个对象的浅拷贝,其区别如下: 1.clone会拷贝单例方法,而dup不会. a = Object.new def a.hello "hello" ...
- IOS 关于 NSUserDefault
转载 并不是所有的东西都能往里放的.NSUserDefaults只支持: NSString, NSNumber, NSDate, NSArray, NSDictionary. NSUserDefa ...
- Macaca,app-inspector安装
1.安装brew 软件包管理工具:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/inst ...
- js作用域总结
一.在ES5中,js 的作用域 js作用域,只有全局作用域与函数作用域,没有块级作用域. 1.全局作用域 var a = 10; function aaa() {alert(a) } function ...
- Python多人聊天室
一.目的 以实现小项目的方式,来巩固之前学过的Python基本语法以及相关的知识. 二.相关技术: 1.wxpython GUI编程 2.网络编程 3.多线程编程 4.数据库编程 5.简单的将数据导出 ...
- ActivemMQ之消息服务器平台(发邮件)
消息服务平台 处理公司内部各种消息业务 比如 发送邮件 发送短信 微信推送 接口有两种类型 异步 同步 同步需求: 当调用消息服务平台,需要返回消息服务平台调用第三方平台接口是否成功 异步需求: ...
- XXL-Job集群
底层已经实现好了 调度中心集群 调度中心支持集群部署,提升调度系统容灾和可用性. 调度中心集群部署时,几点要求和建议: DB配置保持一致: 登陆账号配置保持一致: 群机器时钟保持一致(单机集群忽视): ...
- Spring Boot2.0之多环境配置
本地开发环境 测试环境 实际项目中 区分不同的环境配置文件信息 首先创建三种不同场景下的配置文件: 内容分别是: ###dev http_url="dev" ###prdhttp_ ...