From bd1aed36640d5c7b5d39181050041bb91cc2befe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=8C=AF=E5=AE=87?= <> Date: Tue, 4 Feb 2025 11:06:07 +0800 Subject: [PATCH] refactor(CommitMessageLinter, log): enhance logging with timestamps and improve log messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙振宇 <> --- .../freeleaps/devops/CommitMessageLinter.groovy | 8 ++++---- first-class-pipeline/vars/log.groovy | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/first-class-pipeline/src/com/freeleaps/devops/CommitMessageLinter.groovy b/first-class-pipeline/src/com/freeleaps/devops/CommitMessageLinter.groovy index e2e0ff67..422de581 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/CommitMessageLinter.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/CommitMessageLinter.groovy @@ -10,18 +10,18 @@ class CommitMessageLinter { def lint(configurations) { def rules = steps.libraryResource 'com/freeleaps/devops/builtins/commitlint/default.js' - steps.log.info "Check if there has custom commit lint rules specified..." + steps.log.info " Check if there has custom commit lint rules specified..." if (configurations.commitLintRules != null && !configurations.commitLintRules.isEmpty()) { - steps.log.info "Custom commit lint rules found, using custom rules files: ${configurations.commitLintRules}" + steps.log.info " Custom commit lint rules found, using custom rules files: ${configurations.commitLintRules}" rules = configurations.commitLintRules } else { - steps.log.info "No custom commit lint rules found, using built-in rules at: ${defaultRules}" + steps.log.info " No custom commit lint rules found, using built-in rules at: ${defaultRule}" steps.sh "echo ${rules} > .commitlintrc.js" rules = '.commitlintrc.js' } - steps.log.info "Linting commit messages from HEAD..." + steps.log.info " Linting commit messages from HEAD..." steps.dir(steps.env.workspace) { steps.sh "commitlint --verbose -g ${rules} -f HEAD^" diff --git a/first-class-pipeline/vars/log.groovy b/first-class-pipeline/vars/log.groovy index e62bf90e..5818427d 100644 --- a/first-class-pipeline/vars/log.groovy +++ b/first-class-pipeline/vars/log.groovy @@ -1,13 +1,22 @@ #!groovy +import java.text.SimpleDateFormat +import java.util.Date + +def getTimestamp() { + // 定义时间戳格式,例如:2023-10-05 14:30:00 + def dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") + return dateFormat.format(new Date()) +} + def info(message) { - echo "[INFO] ${message}" + echo "[${getTimestamp()}] [INFO] ${message}" } def warn(message) { - echo "[WARN] ${message}" + echo "[${getTimestamp()}] [WARN] ${message}" } def error(message) { - echo "[ERROR] ${message}" + echo "[${getTimestamp()}] [ERROR] ${message}" } \ No newline at end of file