JSON backing store, I/O fixes, Networking Security
Introduced Newtonsoft.Json-backed persistence. Improved backing-store reliability and serialization across the caching stack. Improved networking security posture. Key changes: - Add new GameCult.Caching.NewtonsoftJson project with SingleFile/MultiFile backing stores and polymorphic known-type envelopes. - Add MessagePack helper serialization (DatabaseEntrySerialization) and update MessagePack backing stores to use the shared options/resolver; add DatabaseLink formatter and generator/analyzer docs. - Update CultLib.sln to include the new projects and new caching tests project. - Improve CultCache persistence behavior: track pending store operations, wait for operations on PullAll, and centralize async push handling with error logging. - Harden file I/O in multi-file/single-file stores: atomic temp-file writes, safe Replace/Move semantics, rename-safe deletes, and improved file-watcher subscription and debounce disposal. - Add README files and documentation for several subprojects and packaging projects. These changes add JSON persistence support, improve serialization consistency, and make on-disk operations more robust and observable.
This commit is contained in:
parent
d88eecb4ba
commit
0bfc85a4f2
50 changed files with 3957 additions and 325 deletions
|
|
@ -2,25 +2,32 @@ using System;
|
|||
|
||||
namespace GameCult.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes log messages to the process console.
|
||||
/// </summary>
|
||||
public class ConsoleLogger : ILogger
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void LogInfo(string message) => Console.WriteLine($"[INFO] {message}");
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogWarning(string message)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine($"[WARN] {message}"); Console.ResetColor();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogError(string message)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"[ERROR] {message}"); Console.ResetColor();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogDebug(string message)
|
||||
{
|
||||
if(Environment.GetEnvironmentVariable("NODEV") is not null) Console.WriteLine($"[DEBUG] {message}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,17 @@ using System.IO;
|
|||
|
||||
namespace GameCult.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Appends timestamped log entries to a file on disk.
|
||||
/// </summary>
|
||||
public class FileLogger : ILogger
|
||||
{
|
||||
private readonly string _logPath;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new file-backed logger.
|
||||
/// </summary>
|
||||
/// <param name="logPath">The path to the log file to append to.</param>
|
||||
public FileLogger(string logPath = "server.log")
|
||||
{
|
||||
_logPath = logPath;
|
||||
|
|
@ -17,9 +24,16 @@ namespace GameCult.Logging
|
|||
File.AppendAllText(_logPath, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{level}] {message}\n");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogInfo(string message) => Append("INFO", message);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogWarning(string message) => Append("WARN", message);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogError(string message) => Append("ERROR", message);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogDebug(string message) => Append("DEBUG", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,50 @@
|
|||
namespace GameCult.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the logging contract used across CultLib components.
|
||||
/// </summary>
|
||||
public interface ILogger
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes an informational message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to record.</param>
|
||||
void LogInfo(string message);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a warning message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to record.</param>
|
||||
void LogWarning(string message);
|
||||
|
||||
/// <summary>
|
||||
/// Writes an error message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to record.</param>
|
||||
void LogError(string message);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a debug message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to record.</param>
|
||||
void LogDebug(string message); // Optional; skip in prod
|
||||
}
|
||||
|
||||
// Null impl for no-op logging (e.g., perf tests)
|
||||
/// <summary>
|
||||
/// Provides a no-op logger implementation.
|
||||
/// </summary>
|
||||
public class NullLogger : ILogger
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void LogInfo(string message) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogWarning(string message) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogError(string message) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LogDebug(string message) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
69
src/GameCult.Logging/README.md
Normal file
69
src/GameCult.Logging/README.md
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# GameCult.Logging
|
||||
|
||||
`GameCult.Logging` provides a common logging contract for cache, networking, and Unity-facing code.
|
||||
|
||||
## Scope
|
||||
|
||||
This package provides a minimal logging abstraction. It does not provide structured logging, external sinks, scopes, or framework integration.
|
||||
|
||||
It is designed for:
|
||||
|
||||
- simple runtime diagnostics
|
||||
- lightweight library dependencies
|
||||
- swapping logging behavior by environment
|
||||
- avoiding a hard dependency on a specific logging ecosystem
|
||||
|
||||
## Included Types
|
||||
|
||||
- `ILogger`: interface with `LogInfo`, `LogWarning`, `LogError`, and `LogDebug`
|
||||
- `NullLogger`: no-op implementation
|
||||
- `ConsoleLogger`: writes to `System.Console`
|
||||
- `FileLogger`: appends timestamped log lines to a file
|
||||
- `UnityLogger`: Unity-specific implementation in `src/GameCult.Logging.Unity`
|
||||
|
||||
## Behavior Notes
|
||||
|
||||
- `NullLogger` is the safe default used by other libraries when no logger is supplied.
|
||||
- `ConsoleLogger` colors warnings and errors.
|
||||
- `FileLogger` writes plain text entries with timestamps.
|
||||
- `UnityLogger` schedules logging to the next Unity frame instead of writing immediately.
|
||||
|
||||
## Typical Usage
|
||||
|
||||
```csharp
|
||||
using GameCult.Logging;
|
||||
|
||||
ILogger logger = new ConsoleLogger();
|
||||
|
||||
logger.LogInfo("Server starting");
|
||||
logger.LogWarning("High latency detected");
|
||||
logger.LogError("Connection failed");
|
||||
```
|
||||
|
||||
## Swapping Implementations
|
||||
|
||||
Consumers can choose the implementation that fits the runtime.
|
||||
|
||||
```csharp
|
||||
using GameCult.Logging;
|
||||
using GameCult.Networking;
|
||||
|
||||
var client = new Client
|
||||
{
|
||||
Logger = new FileLogger("client.log")
|
||||
};
|
||||
|
||||
client.Connect("127.0.0.1", 3075);
|
||||
```
|
||||
|
||||
## When To Use Something Else
|
||||
|
||||
If you need:
|
||||
|
||||
- structured events
|
||||
- sinks to external observability platforms
|
||||
- log scopes
|
||||
- sampling and filtering pipelines
|
||||
- JSON log output
|
||||
|
||||
use a logging framework at the application boundary.
|
||||
Loading…
Reference in a new issue