打印log 保存log
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using System.Text; namespace SC.Debuger
{
/// <summary>
/// log等级
/// </summary>
public enum LogLevel
{
None = ,
Debug = ,
Error = ,
Warning = ,
Exception = ,
All = LogLevel.Debug | LogLevel.Error | LogLevel.Warning | LogLevel.Exception
}
} namespace SC.Debuger
{
public class LogWriter
{
// private string m_logPath = Application.persistentDataPath + "/log/";
private string m_logPath = Environment.CurrentDirectory + "/log/";
private string m_logFileName = "log_{0}.txt";
private string m_logFilePath = string.Empty; public LogWriter()
{
if (!Directory.Exists(m_logPath))
{
Directory.CreateDirectory(m_logPath);
}
this.m_logFilePath = this.m_logPath + string.Format(this.m_logFileName, DateTime.Today.ToString("yyyyMMdd"));
Debug.Log (this.m_logFilePath);
} public void ExcuteWrite(string content)
{
using (StreamWriter writer = new StreamWriter(m_logFilePath, true, Encoding.UTF8))
{
writer.WriteLine(content);
}
}
}
} namespace SC.Debuger
{
public class LogHelper
{
static public LogLevel m_logLevel = LogLevel.All;
static LogWriter m_logWriter = new LogWriter(); static LogHelper()
{
Application.logMessageReceived += ProcessExceptionReport;
} private static void ProcessExceptionReport(string message, string stackTrace, LogType type)
{
LogLevel dEBUG = LogLevel.Debug;
switch (type)
{
case LogType.Error:
dEBUG = LogLevel.Error;
break;
case LogType.Assert:
dEBUG = LogLevel.Debug;
break;
case LogType.Warning:
dEBUG = LogLevel.Warning;
break;
case LogType.Log:
dEBUG = LogLevel.Debug;
break;
case LogType.Exception:
dEBUG = LogLevel.Exception;
break;
} if (dEBUG == (m_logLevel & dEBUG))
{
Log(string.Concat(new object[] { " [", dEBUG, "]: ", message, '\n', stackTrace }));
}
} /// <summary>
/// 加上时间戳
/// </summary>
/// <param name="message"></param>
private static void Log(string message)
{
string msg = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss,fff") + message;
m_logWriter.ExcuteWrite(msg);
} static public void Log(object message)
{
Log(message, null);
}
static public void Log(object message, UnityEngine.Object context)
{
if (LogLevel.Debug == (m_logLevel & LogLevel.Debug))
{
Debug.Log(message, context);
}
}
static public void LogError(object message)
{
LogError(message, null);
}
static public void LogError(object message, UnityEngine.Object context)
{
if (LogLevel.Error == (m_logLevel & LogLevel.Error))
{
Debug.LogError(message, context);
}
}
static public void LogWarning(object message)
{
LogWarning(message, null);
}
static public void LogWarning(object message, UnityEngine.Object context)
{
if (LogLevel.Warning == (m_logLevel & LogLevel.Warning))
{
Debug.LogWarning(message, context);
}
}
}
}
//游戏上线之前把LogHelper.m_logLevel = LogLevel.None;Log就不显示了。
//LogHelper.m_logLevel = LogLevel.Error;是显示Error。
//LogHelper.m_logLevel = LogLevel.Debug | LogLevel.Error;同时显示Debug和Error。
//private string m_logPath = Environment.CurrentDirectory + "/log/";
//log文件是保存在 private string m_logPath = Application.persistentDataPath + "/log/";在手机上就是沙盒路径。
//log文件是以天为单位,同一天的log会被记录到一个文件里面。 //using UnityEngine;
//using SC.Debuger;
//
//public class Test : MonoBehaviour
//{
// void Start()
// {
// LogHelper.m_logLevel = LogLevel.All;
// LogHelper.Log("debug");
// LogHelper.LogError("error");
// LogHelper.LogWarning("warning");
//
// GameObject go = GameObject.Find("fsdfsd");
// GameObject.Instantiate(go);
// }
//}
打印log 保存log的更多相关文章
- java打印Jni层log
在eclipse上新建jni工程可以参考:http://www.cnblogs.com/ashitaka/p/5953708.html 要在java层打印c的log必须引入这个头文件的宏定义: #if ...
- Junit测试打印详细的log日志,可以看到sql
Junit测试打印详细的log日志,可以看到sql 在log4j.xml的日志配置文件中,把日志级别从info级别调整到debug级别: <?xml version="1.0" ...
- 使用真机导致Androidstudio打印不出log
针对真机打印不出log这个问题,我具体的解决方案是这样: 1.你要确保你的Android studio中的菜单栏 ,Tools → Android → Enable ADB Integration这个 ...
- 循环读取寄存器(QSFP-DD)并且分别保存log
#!/bin/bash ####################################################################### #Created by: Bin ...
- Android进阶:一、日志打印和保存策略
前言: 项目开始没有做好日志统计工作,每次有问题后端都得找前端对接,严重影响工作效率.最近特地在项目中加上日志保存策略,在此分享,供需要的人学习. 一.更详细的日志信息 既然决定自定义一个log,那我 ...
- JMeter调试参数是否取值正确,调试正则提取的结果(log.info|log.error|print)
JMeter调试参数是否取值正确,调试正则提取的结果(log.info | log.error | print) Jmeter的log输出控制(jmeter.log) 1 2 log_level.jm ...
- Android关于log日志,华为不输出log.v,log.d(zz)
[java] view plain copy 我用的是mate8,本来虚拟机测试一点日志一点问题没有 [java] view plain copy 但是真机测试发现log.d一直不输出,正好又试了lo ...
- [日志log] 常用log日志记录方式对比和详解
1.现在都有哪些记录日志的方法 A.java.util.logging.Logger - 使用详解 B.log4j - 使用详解 C.SLF4J(simple logging Facade for J ...
- tomcat日志 之 catalina.log & localhost.log
体会 catalina.out catalina.log 是tomcat的标准输出(stdout)和标准出错(stderr) cataliana.{yyyy-MM-dd}.log和localhost. ...
随机推荐
- Samba-ADS/WINBIND
Samba Security = ADShttp://www.justlinux.com/forum/showt...hreadid=118288 Winbindhttp://www.justlinu ...
- css伪类选择器详细解析及案例使用-----伪元素
伪元素:(css3中将所有伪元素前变成了两个冒号,即::first-letter.::first-line.::before.::after.::selection.目的是为了区分伪元素与伪类.对于I ...
- GDI+ 颜色表示
一.GDI+中:Color位于System.Drawing命名空间下.当我们需要使用某种颜色时,我们可以用以下几种方式: ()Color.FromArgb(alpha, red, green, bl ...
- silverlight 生产图表(动态图表类型,Y轴数量) .xaml.cs文件
silverlight 页面后台方法 .xaml.cs文件 public void CreateChart(Grid oGrid, ObservableCollection<ListItem&g ...
- 华为oj - 统计大写字母个数
练手而已. 给初学者参考 #include <stdio.h> #include <string.h> int main(void) { char string[200]={' ...
- jaxb xml to bean
package www.garbin.com.utils; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException ...
- 把python项目部署到centos里
.安装centos VMware9下面安装centos .在centos下面设置共享文件夹为你本地的论坛的代码,然后设置网络为桥接:直接连接到物理网络,赋值网络连接状态 .进入forum_svr.py ...
- system进程启动普通用户进程调研
system进程启动普通用户进程 关键函数是CreateProcessAsUser 主要思路是先取得目的用户的token,然后用上面的函数启动 1.从explorer中取token BOOL GetT ...
- C++第一课(2013.9.26 )
//C++三大特性:封装,继承,多态 //C++新增的数据类型:bool型 一个字节 真 true 假 false //case 定义变量的问题 ; switch(nValue) { : { prin ...
- ecshop优化修改sitemap.xml到根目录
大家都知道sitemap.xml是用来给搜索引擎提交收录的工具,虽然搜索引擎自己也会收录网站但是有了sitemap.xml之后速度会加快不少.而ecshop程序是有自动生成sitemap.xml的功能 ...