发布包改为 GCL 单目录布局,.GC 增加 safedog 与中英双语日志
包结构
- 压缩包内只有一个顶层目录 GCL-<版本>-<平台>/,解压后不再散落一屏 dll
- 启动器改名为 GCL-<版本>-<平台>(.exe),Flutter 前端与后端仍在同一目录
- 守护进程移入包内 safedog/,运行时复制到 .GC/safedog
运行目录
- .GC 新增 safedog/:实际运行守护进程,整目录替换永远不会覆盖正在运行的它
- .GC 新增 logs/:按天写 gc-YYYYMMDD.log(中文)与 gc-YYYYMMDD.en.log(英文)
- 启动器、后端、SAVEDOG 共用同一组日志文件,整条启动/更新链路可一起排查
更新链路
- 包名/目录统一 GCL- 前缀,同时兼容旧 GC- 包(可从旧版本升级)
- 更新包解压后展平单顶层目录,仍按整目录替换安装
- Linux 无扩展名启动器仍可识别,兼容脚本清理旧版时覆盖 GCL-*
验证
- ./build.sh build 通过,产物 GCL-1.0.9-{win-amd64,win-arm64,linux-amd64}.zip
- 实跑 Linux 包:.GC/safedog/GC-SAVEDOG 与 .GC/logs/gc-20261118[.en].log 均生成
- GC.Tests --update-test 全部通过
This commit is contained in:
1 parent
a361c889f8
commit
31b0c93b25
17 files changed
+415
-126
No files matched your search
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace GC.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 双语文件日志。
|
||||
///
|
||||
/// 每条记录同时写两个文件(都在 <c>.GC/logs</c> 下,按天滚动):
|
||||
/// <code>
|
||||
/// gc-20261118.log 中文
|
||||
/// gc-20261118.en.log 英文
|
||||
/// </code>
|
||||
/// 中英分开而不是写在一个文件里:用户排查时不用在一行里找自己看得懂的那半句;
|
||||
/// 也给反馈问题时直接发对应语言的文件即可。
|
||||
///
|
||||
/// 日志失败绝不影响主流程(磁盘满、只读目录都只是少一份日志)。
|
||||
/// </summary>
|
||||
public static class GcLog
|
||||
{
|
||||
private static readonly object Gate = new();
|
||||
private static string? _dir;
|
||||
private static string _day = "";
|
||||
private static string _zhPath = "";
|
||||
private static string _enPath = "";
|
||||
|
||||
public static bool Enabled
|
||||
{
|
||||
get { lock (Gate) return _dir != null; }
|
||||
}
|
||||
|
||||
/// <summary>绑定日志目录(通常是 <c>.GC/logs</c>)。重复调用会切到新目录。</summary>
|
||||
public static void Init(string dir)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 目录都建不了就退化成只写控制台
|
||||
return;
|
||||
}
|
||||
|
||||
lock (Gate)
|
||||
{
|
||||
_dir = dir;
|
||||
_day = "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void Info(string zh, string en) => Write("INFO ", zh, en);
|
||||
public static void Warn(string zh, string en) => Write("WARN ", zh, en);
|
||||
public static void Error(string zh, string en) => Write("ERROR", zh, en);
|
||||
|
||||
private static void Write(string level, string zh, string en)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var prefix = $"{now:yyyy-MM-dd HH:mm:ss} [{level}] ";
|
||||
var lineZh = prefix + zh;
|
||||
var lineEn = prefix + en;
|
||||
|
||||
try { Console.WriteLine(lineZh); } catch { /* 无控制台 */ }
|
||||
|
||||
lock (Gate)
|
||||
{
|
||||
if (_dir == null) return;
|
||||
|
||||
var day = now.ToString("yyyyMMdd");
|
||||
if (day != _day)
|
||||
{
|
||||
_day = day;
|
||||
_zhPath = Path.Combine(_dir, $"gc-{day}.log");
|
||||
_enPath = Path.Combine(_dir, $"gc-{day}.en.log");
|
||||
}
|
||||
|
||||
Append(_zhPath, lineZh);
|
||||
Append(_enPath, lineEn);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Append(string path, string line)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.AppendAllText(path, line + Environment.NewLine, new UTF8Encoding(false));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 日志失败不能影响程序
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user