Init
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QFSW.QC
|
||||
{
|
||||
public interface ILog
|
||||
{
|
||||
string Text { get; }
|
||||
LogType Type { get; }
|
||||
bool NewLine { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5def4ecf09b4133b054e98f9afcc5c8
|
||||
timeCreated: 1615116599
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace QFSW.QC
|
||||
{
|
||||
public interface ILogQueue
|
||||
{
|
||||
int MaxStoredLogs { get; set; }
|
||||
bool IsEmpty { get; }
|
||||
|
||||
void QueueLog(ILog log);
|
||||
bool TryDequeue(out ILog log);
|
||||
void Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b76bcf3d7eaa412cb2428e464882ed89
|
||||
timeCreated: 1615123713
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QFSW.QC
|
||||
{
|
||||
public interface ILogStorage
|
||||
{
|
||||
int MaxStoredLogs { get; set; }
|
||||
IReadOnlyList<ILog> Logs { get; }
|
||||
|
||||
void AddLog(ILog log);
|
||||
void RemoveLog();
|
||||
void Clear();
|
||||
|
||||
string GetLogString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 859434497f964d328b18530b1230d97f
|
||||
timeCreated: 1615116625
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QFSW.QC
|
||||
{
|
||||
public readonly struct Log : ILog
|
||||
{
|
||||
public string Text { get; }
|
||||
public LogType Type { get; }
|
||||
public bool NewLine { get; }
|
||||
|
||||
public Log(string text, LogType type = LogType.Log, bool newLine = true)
|
||||
{
|
||||
Text = text;
|
||||
Type = type;
|
||||
NewLine = newLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f183a6a7c8672b9448d3c1023b68df30
|
||||
timeCreated: 1554340584
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace QFSW.QC
|
||||
{
|
||||
public class LogQueue : ILogQueue
|
||||
{
|
||||
private readonly ConcurrentQueue<ILog> _queuedLogs = new ConcurrentQueue<ILog>();
|
||||
|
||||
public int MaxStoredLogs { get; set; }
|
||||
public bool IsEmpty => _queuedLogs.IsEmpty;
|
||||
|
||||
public LogQueue(int maxStoredLogs = -1)
|
||||
{
|
||||
MaxStoredLogs = maxStoredLogs;
|
||||
}
|
||||
|
||||
public void QueueLog(ILog log)
|
||||
{
|
||||
_queuedLogs.Enqueue(log);
|
||||
if (MaxStoredLogs > 0 && _queuedLogs.Count > MaxStoredLogs)
|
||||
{
|
||||
_queuedLogs.TryDequeue(out _);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryDequeue(out ILog log)
|
||||
{
|
||||
return _queuedLogs.TryDequeue(out log);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
while (TryDequeue(out ILog _)) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20c64958e7fb4ef6a8089b2cdb9e651a
|
||||
timeCreated: 1615123680
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QFSW.QC
|
||||
{
|
||||
public class LogStorage : ILogStorage
|
||||
{
|
||||
private readonly List<ILog> _consoleLogs = new List<ILog>(10);
|
||||
private readonly StringBuilder _logTraceBuilder = new StringBuilder(2048);
|
||||
|
||||
public int MaxStoredLogs { get; set; }
|
||||
public IReadOnlyList<ILog> Logs => _consoleLogs;
|
||||
|
||||
public LogStorage(int maxStoredLogs = -1)
|
||||
{
|
||||
MaxStoredLogs = maxStoredLogs;
|
||||
}
|
||||
|
||||
public void AddLog(ILog log)
|
||||
{
|
||||
_consoleLogs.Add(log);
|
||||
|
||||
int logLength = _logTraceBuilder.Length + log.Text.Length;
|
||||
if (log.NewLine && _logTraceBuilder.Length > 0)
|
||||
{
|
||||
logLength += Environment.NewLine.Length;
|
||||
}
|
||||
|
||||
if (MaxStoredLogs > 0)
|
||||
{
|
||||
while (_consoleLogs.Count > MaxStoredLogs)
|
||||
{
|
||||
int junkLength = _consoleLogs[0].Text.Length;
|
||||
if (_consoleLogs.Count > 1 &&_consoleLogs[1].NewLine)
|
||||
{
|
||||
junkLength += Environment.NewLine.Length;
|
||||
}
|
||||
junkLength = Mathf.Min(junkLength, _logTraceBuilder.Length);
|
||||
logLength -= junkLength;
|
||||
|
||||
_logTraceBuilder.Remove(0, junkLength);
|
||||
_consoleLogs.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
int capacity = _logTraceBuilder.Capacity;
|
||||
while (capacity < logLength)
|
||||
{
|
||||
capacity *= 2;
|
||||
}
|
||||
|
||||
_logTraceBuilder.EnsureCapacity(capacity);
|
||||
|
||||
if (log.NewLine && _logTraceBuilder.Length > 0)
|
||||
{
|
||||
_logTraceBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
_logTraceBuilder.Append(log.Text);
|
||||
}
|
||||
|
||||
public void RemoveLog()
|
||||
{
|
||||
if (_consoleLogs.Count > 0)
|
||||
{
|
||||
ILog log = _consoleLogs[_consoleLogs.Count - 1];
|
||||
_consoleLogs.RemoveAt(_consoleLogs.Count - 1);
|
||||
|
||||
int removeLength = log.Text.Length;
|
||||
if (log.NewLine && _consoleLogs.Count > 0)
|
||||
{
|
||||
removeLength += Environment.NewLine.Length;
|
||||
}
|
||||
|
||||
_logTraceBuilder.Remove(_logTraceBuilder.Length - removeLength, removeLength);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_consoleLogs.Clear();
|
||||
_logTraceBuilder.Length = 0;
|
||||
}
|
||||
|
||||
public string GetLogString()
|
||||
{
|
||||
return _logTraceBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0b5e8fa829c491eb694d1dfc7a1842a
|
||||
timeCreated: 1615081378
|
||||
Reference in New Issue
Block a user