docker-actions/template: CI / BUILD (pull_request) Successful in 5s
- 依建立時間將 release 分為正式版與 beta 版(tag 含 beta),各自保留最新指定筆數(keep_count 預設 5、keep_count_beta 預設 10),其餘舊 release 連同對應 git tag 一併刪除 - Node.js 主程式置於 src/(index.js 主流程、logger.js 統一訊息格式 [yyyy/MM/dd HH:mm:ss][階段][等級]: 訊息) - 多階段建置 dockerfile(NODE_VERSION=latest / NODE_RUNTIME=slim),entrypoint.sh 輸出啟動訊息後 exec 主程式 - 補齊全部 JSDoc 與指令檔逐行註解,重建 readme.md - 移除範本的 .gitea/scoped_workflows/ci.yaml Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
80 lines
2.9 KiB
JavaScript
80 lines
2.9 KiB
JavaScript
/**
|
||
* 共用 logger:統一輸出格式為 [yyyy/MM/dd HH:mm:ss][階段][等級]: 訊息
|
||
* 無階段時為 [yyyy/MM/dd HH:mm:ss][等級]: 訊息;時間為台灣時區(Asia/Taipei)。
|
||
*/
|
||
|
||
const TAIPEI_FORMATTER = new Intl.DateTimeFormat('en-US', {
|
||
timeZone: 'Asia/Taipei',
|
||
year: 'numeric',
|
||
month: '2-digit',
|
||
day: '2-digit',
|
||
hour: '2-digit',
|
||
minute: '2-digit',
|
||
second: '2-digit',
|
||
hour12: false,
|
||
});
|
||
|
||
/**
|
||
* 取得目前台灣時區時間字串(yyyy/MM/dd HH:mm:ss);
|
||
* 以 Intl.DateTimeFormat 的 formatToParts 組字串,不受系統時區影響。
|
||
* @returns {string} 台灣時區(Asia/Taipei)的當下時間,固定 yyyy/MM/dd HH:mm:ss 格式
|
||
*/
|
||
function timestamp() {
|
||
const parts = {};
|
||
for (const { type, value } of TAIPEI_FORMATTER.formatToParts(new Date())) {
|
||
parts[type] = value;
|
||
}
|
||
// hour12: false 在部分環境會把 00 顯示成 24,統一正規化
|
||
const hour = parts.hour === '24' ? '00' : parts.hour;
|
||
return `${parts.year}/${parts.month}/${parts.day} ${hour}:${parts.minute}:${parts.second}`;
|
||
}
|
||
|
||
/**
|
||
* 組合訊息前綴並輸出一行訊息。
|
||
* @param {string} level 等級(INF/WRN/ERR/TRC/DBG)
|
||
* @param {string} message 訊息內容
|
||
* @param {string} [stage] 階段名稱;未提供時省略 [階段] 區塊
|
||
*/
|
||
function write(level, message, stage) {
|
||
const prefix = stage ? `[${timestamp()}][${stage}][${level}]` : `[${timestamp()}][${level}]`;
|
||
const line = `${prefix}: ${message}`;
|
||
if (level === 'ERR') {
|
||
console.error(line);
|
||
} else {
|
||
console.log(line);
|
||
}
|
||
}
|
||
|
||
module.exports = {
|
||
/**
|
||
* 輸出 INF(一般資訊)等級訊息至 stdout。
|
||
* @param {string} message 訊息內容
|
||
* @param {string} [stage] 階段名稱;未提供時省略 [階段] 區塊
|
||
*/
|
||
inf: (message, stage) => write('INF', message, stage),
|
||
/**
|
||
* 輸出 WRN(警告)等級訊息至 stdout,用於可繼續執行的異常狀況。
|
||
* @param {string} message 訊息內容
|
||
* @param {string} [stage] 階段名稱;未提供時省略 [階段] 區塊
|
||
*/
|
||
wrn: (message, stage) => write('WRN', message, stage),
|
||
/**
|
||
* 輸出 ERR(錯誤)等級訊息至 stderr(console.error)。
|
||
* @param {string} message 訊息內容
|
||
* @param {string} [stage] 階段名稱;未提供時省略 [階段] 區塊
|
||
*/
|
||
err: (message, stage) => write('ERR', message, stage),
|
||
/**
|
||
* 輸出 TRC(細部追蹤)等級訊息至 stdout,用於記錄 API 呼叫等細節。
|
||
* @param {string} message 訊息內容
|
||
* @param {string} [stage] 階段名稱;未提供時省略 [階段] 區塊
|
||
*/
|
||
trc: (message, stage) => write('TRC', message, stage),
|
||
/**
|
||
* 輸出 DBG(除錯)等級訊息至 stdout,用於開發除錯資訊。
|
||
* @param {string} message 訊息內容
|
||
* @param {string} [stage] 階段名稱;未提供時省略 [階段] 區塊
|
||
*/
|
||
dbg: (message, stage) => write('DBG', message, stage),
|
||
};
|