| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using ET;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- public class SplitFilesLogger : ILog
- {
- StreamWriter swDebug;
- StreamWriter swInfo;
- StreamWriter swWarning;
- StreamWriter swError;
- public SplitFilesLogger(string path = null)
- {
- if (path == null)
- {
- #if UNITY_EDITOR || UNITY_STANDALONE
- path = "./";
- #elif UNITY_ANDROID
- path = Application.persistentDataPath;
- #endif
- path = Path.Combine(path, "UnityLogs");
- if (!Directory.Exists(path)) {
- Directory.CreateDirectory(path);
- }
- }
- FileStream fwDebug = File.Open(Path.Combine(path, $"{DateTime.Now.ToString("yyyyMMddHH")}_Debug.log"),
- FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
- fwDebug.Seek(0, SeekOrigin.End);
- swDebug = new StreamWriter(fwDebug);
- FileStream fwInfo = File.Open(Path.Combine(path, $"{DateTime.Now.ToString("yyyyMMddHH")}_Info.log"),
- FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
- fwInfo.Seek(0, SeekOrigin.End);
- swInfo = new StreamWriter(fwInfo);
- FileStream fwWarning = File.Open(Path.Combine(path, $"{DateTime.Now.ToString("yyyyMMddHH")}_Warning.log"),
- FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
- fwWarning.Seek(0, SeekOrigin.End);
- swWarning = new StreamWriter(fwWarning);
- FileStream fwError = File.Open(Path.Combine(path, $"{DateTime.Now.ToString("yyyyMMddHH")}_Error.log"),
- FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
- fwError.Seek(0, SeekOrigin.End);
- swError = new StreamWriter(fwError);
- }
- public void Debug(string message)
- {
- swDebug.WriteLine(message);
- swDebug.Flush();
- }
- public void Debug(string message, params object[] args)
- {
- swDebug.WriteLine(string.Format(message, args));
- swDebug.Flush();
- }
- public void Error(string message)
- {
- swError.WriteLine(message);
- swError.Flush();
- }
- public void Error(string message, params object[] args)
- {
- swError.WriteLine(string.Format(message, args));
- swError.Flush();
- }
- public void Info(string message)
- {
- swInfo.WriteLine(message);
- swInfo.Flush();
- }
- public void Info(string message, params object[] args)
- {
- swInfo.WriteLine(string.Format(message, args));
- swInfo.Flush();
- }
- public void Trace(string message)
- {
- swDebug.WriteLine(message);
- swDebug.Flush();
- }
- public void Trace(string message, params object[] args)
- {
- swDebug.WriteLine(string.Format(message, args));
- swDebug.Flush();
- }
- public void Warning(string message)
- {
- swWarning.WriteLine(message);
- swWarning.Flush();
- }
- public void Warning(string message, params object[] args)
- {
- swWarning.WriteLine(string.Format(message, args));
- swWarning.Flush();
- }
- }
|