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的更多相关文章

  1. java打印Jni层log

    在eclipse上新建jni工程可以参考:http://www.cnblogs.com/ashitaka/p/5953708.html 要在java层打印c的log必须引入这个头文件的宏定义: #if ...

  2. Junit测试打印详细的log日志,可以看到sql

    Junit测试打印详细的log日志,可以看到sql 在log4j.xml的日志配置文件中,把日志级别从info级别调整到debug级别: <?xml version="1.0" ...

  3. 使用真机导致Androidstudio打印不出log

    针对真机打印不出log这个问题,我具体的解决方案是这样: 1.你要确保你的Android studio中的菜单栏 ,Tools → Android → Enable ADB Integration这个 ...

  4. 循环读取寄存器(QSFP-DD)并且分别保存log

    #!/bin/bash ####################################################################### #Created by: Bin ...

  5. Android进阶:一、日志打印和保存策略

    前言: 项目开始没有做好日志统计工作,每次有问题后端都得找前端对接,严重影响工作效率.最近特地在项目中加上日志保存策略,在此分享,供需要的人学习. 一.更详细的日志信息 既然决定自定义一个log,那我 ...

  6. JMeter调试参数是否取值正确,调试正则提取的结果(log.info|log.error|print)

    JMeter调试参数是否取值正确,调试正则提取的结果(log.info | log.error | print) Jmeter的log输出控制(jmeter.log) 1 2 log_level.jm ...

  7. Android关于log日志,华为不输出log.v,log.d(zz)

    [java] view plain copy 我用的是mate8,本来虚拟机测试一点日志一点问题没有 [java] view plain copy 但是真机测试发现log.d一直不输出,正好又试了lo ...

  8. [日志log] 常用log日志记录方式对比和详解

    1.现在都有哪些记录日志的方法 A.java.util.logging.Logger - 使用详解 B.log4j - 使用详解 C.SLF4J(simple logging Facade for J ...

  9. tomcat日志 之 catalina.log & localhost.log

    体会 catalina.out catalina.log 是tomcat的标准输出(stdout)和标准出错(stderr) cataliana.{yyyy-MM-dd}.log和localhost. ...

随机推荐

  1. 操作系统下查看HBA卡信息wwn的方法

    一.Windows 系统在Windows系统中,可以使用FC HBA卡厂家提供的管理软件查看光纤适配器的WWN号码,具体如下:Qlogic:SANsurferEmulex:HBAnyware http ...

  2. git删除未跟踪文件

    # 删除 untracked files git clean -f   # 连 untracked 的目录也一起删掉 git clean -fd   # 连 gitignore 的untrack 文件 ...

  3. Thread 常搞混的几个概念sleep、wait、yield、interrupt (转)

    原文网址:http://blog.csdn.net/partner4java/article/details/7993420sleep:在指定的毫秒数内让当前正在执行的线程休眠(暂停执行),此操作受到 ...

  4. Silverlight 设置颜色

    透明色:00ff00ff //设置柱状图的颜色                ColorSet cs = new ColorSet();                cs.Id = "co ...

  5. cookie自封装对象

    cookie.js(设置名值对属性时候不支持设置成前后有空格的格式,如' key'或'key ',只支持‘key’) (function initCookieClass(win){// 定义匿名函数并 ...

  6. (原)ubuntu16重装显卡驱动后,torch中的问题

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6030232.html 参考网址: https://github.com/torch/cutorch/i ...

  7. 高级I/O函数(2)-splice函数

    splice函数: 功能描述:用于在两个文件描述符之间移动数据,也是零拷贝操作.函数定义如下: #include <fcntl.h> ssize_t splice(int fd_in,lo ...

  8. 使用pip install 或者easy_install安装Python的各种包出现cc failed with exit status 1

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  9. ACM训练计划step 2 [非原创]

    (Step2-500题)POJ训练计划+SGU 经过Step1-500题训练,接下来可以开始Step2-500题,包括POJ训练计划的298题和SGU前两章200题.需要1-1年半时间继续提高解决问题 ...

  10. HDU 4035 Maze(树形概率DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4035 题意:一棵树,从结点1出发,在每个结点 i 都有3种可能:(1)回到结点1 , 概率 Ki:(2 ...