This is an automated email from the ASF dual-hosted git repository.

zhaoqingran pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hertzbeat-collector-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 1dbeb5e  feat: update some code (#28)
1dbeb5e is described below

commit 1dbeb5e200b0030a3b734257a72e5197df13c52a
Author: shown <[email protected]>
AuthorDate: Tue Nov 25 17:02:55 2025 +0800

    feat: update some code (#28)
    
    Signed-off-by: yuluo-yx <[email protected]>
---
 .editorconfig                                      |  15 +++
 .gitattributes                                     |  11 ++
 internal/banner/embed.go                           |  13 +++
 internal/util/logger/logger.go                     | 107 ++++++++++----------
 tools/linter/license/.licenserc.yaml               |   1 +
 .../linter/markdownlint/markdown_lint_config.yaml  |   2 +
 tools/make/linter.mk                               |  12 +--
 tools/scripts/new-line-check.py                    | 112 ---------------------
 8 files changed, 97 insertions(+), 176 deletions(-)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..cfd9a42
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+# http://editorconfig.org
+
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 2
+max_line_length = 80
+trim_trailing_whitespace = true
+
+[Makefile]
+indent_style = tab
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..47d0d3c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,11 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+* text eol=lf
+
+# Binary files - treat as binary, no line ending conversion
+*.png binary
+*.jpg binary
+*.jpeg binary
+*.gif binary
+*.ico binary
+*.svg binary
diff --git a/internal/banner/embed.go b/internal/banner/embed.go
index 4b01756..e18bdd1 100644
--- a/internal/banner/embed.go
+++ b/internal/banner/embed.go
@@ -19,6 +19,7 @@ package banner
 
 import (
        "embed"
+       "fmt"
        "os"
        "strconv"
        "text/template"
@@ -27,6 +28,14 @@ import (
        bannertypes 
"hertzbeat.apache.org/hertzbeat-collector-go/internal/collector/common/types/err"
 )
 
+const (
+       // ANSI color codes
+       ColorReset  = "\033[0m"
+       ColorPurple = "\033[35m"
+       ColorGreen  = "\033[32m"
+       ColorYellow = "\033[33m"
+)
+
 //go:embed banner.txt
 var EmbedLogo embed.FS
 
@@ -74,7 +83,11 @@ func (r *Runner) PrintBanner(appName, port string) error {
                Pid:           strconv.Itoa(os.Getpid()),
        }
 
+       // Print banner with color
+       fmt.Print(ColorPurple)
        err = tmpl.Execute(os.Stdout, vars)
+       fmt.Print(ColorReset)
+
        if err != nil {
                r.Logger.Error(bannertypes.BannerPrintExecuteError, "template 
parse error", "error", err)
                return err
diff --git a/internal/util/logger/logger.go b/internal/util/logger/logger.go
index 90bdb23..67d4652 100644
--- a/internal/util/logger/logger.go
+++ b/internal/util/logger/logger.go
@@ -18,64 +18,65 @@
 package logger
 
 import (
-       "io"
-       "os"
-
-       "github.com/go-logr/logr"
-       "github.com/go-logr/zapr"
-       "go.uber.org/zap"
-       "go.uber.org/zap/zapcore"
-       
"hertzbeat.apache.org/hertzbeat-collector-go/internal/collector/common/types/logger"
+  "io"
+  "os"
+
+  "github.com/go-logr/logr"
+  "github.com/go-logr/zapr"
+  "go.uber.org/zap"
+  "go.uber.org/zap/zapcore"
+
+  
"hertzbeat.apache.org/hertzbeat-collector-go/internal/collector/common/types/logger"
 )
 
 type Logger struct {
-       logr.Logger
-       out           io.Writer
-       logging       *logger.HertzBeatLogging
-       sugaredLogger *zap.SugaredLogger
+  logr.Logger
+  out           io.Writer
+  logging       *logger.HertzBeatLogging
+  sugaredLogger *zap.SugaredLogger
 }
 
 func NewLogger(w io.Writer, logging *logger.HertzBeatLogging) Logger {
 
-       logger := initZapLogger(w, logging, 
logging.Level[logger.LogComponentHertzbeatDefault])
+  logger := initZapLogger(w, logging, 
logging.Level[logger.LogComponentHertzbeatDefault])
 
-       return Logger{
-               Logger:        zapr.NewLogger(logger),
-               out:           w,
-               logging:       logging,
-               sugaredLogger: logger.Sugar(),
-       }
+  return Logger{
+    Logger:        zapr.NewLogger(logger),
+    out:           w,
+    logging:       logging,
+    sugaredLogger: logger.Sugar(),
+  }
 }
 
 func FileLogger(file, name string, level logger.LogLevel) Logger {
 
-       writer, err := os.OpenFile(file, os.O_WRONLY, 0o666)
-       if err != nil {
-               panic(err)
-       }
+  writer, err := os.OpenFile(file, os.O_WRONLY, 0o666)
+  if err != nil {
+    panic(err)
+  }
 
-       logging := logger.DefaultHertzbeatLogging()
-       logger := initZapLogger(writer, logging, level)
+  logging := logger.DefaultHertzbeatLogging()
+  logger := initZapLogger(writer, logging, level)
 
-       return Logger{
-               Logger:        zapr.NewLogger(logger).WithName(name),
-               logging:       logging,
-               out:           writer,
-               sugaredLogger: logger.Sugar(),
-       }
+  return Logger{
+    Logger:        zapr.NewLogger(logger).WithName(name),
+    logging:       logging,
+    out:           writer,
+    sugaredLogger: logger.Sugar(),
+  }
 }
 
 func DefaultLogger(out io.Writer, level logger.LogLevel) Logger {
 
-       logging := logger.DefaultHertzbeatLogging()
-       logger := initZapLogger(out, logging, level)
+  logging := logger.DefaultHertzbeatLogging()
+  logger := initZapLogger(out, logging, level)
 
-       return Logger{
-               Logger:        zapr.NewLogger(logger),
-               out:           out,
-               logging:       logging,
-               sugaredLogger: logger.Sugar(),
-       }
+  return Logger{
+    Logger:        zapr.NewLogger(logger),
+    out:           out,
+    logging:       logging,
+    sugaredLogger: logger.Sugar(),
+  }
 }
 
 // WithName returns a new Logger instance with the specified name element added
@@ -85,23 +86,23 @@ func DefaultLogger(out io.Writer, level logger.LogLevel) 
Logger {
 // more information).
 func (l Logger) WithName(name string) Logger {
 
-       logLevel := l.logging.Level[logger.HertzbeatLogComponent(name)]
-       logger := initZapLogger(l.out, l.logging, logLevel)
+  logLevel := l.logging.Level[logger.HertzbeatLogComponent(name)]
+  logger := initZapLogger(l.out, l.logging, logLevel)
 
-       return Logger{
-               Logger:        zapr.NewLogger(logger).WithName(name),
-               logging:       l.logging,
-               out:           l.out,
-               sugaredLogger: logger.Sugar().Named(name),
-       }
+  return Logger{
+    Logger:        zapr.NewLogger(logger).WithName(name),
+    logging:       l.logging,
+    out:           l.out,
+    sugaredLogger: logger.Sugar().Named(name),
+  }
 }
 
 // WithValues returns a new Logger instance with additional key/value pairs.
 // See Info for documentation on how key/value pairs work.
 func (l Logger) WithValues(keysAndValues ...interface{}) Logger {
 
-       l.Logger = l.Logger.WithValues(keysAndValues...)
-       return l
+  l.Logger = l.Logger.WithValues(keysAndValues...)
+  return l
 }
 
 // A Sugar wraps the base Logger functionality in a slower, but less
@@ -124,13 +125,13 @@ func (l Logger) WithValues(keysAndValues ...interface{}) 
Logger {
 //     Infoln(...any)         Println-style logger
 func (l Logger) Sugar() *zap.SugaredLogger {
 
-       return l.sugaredLogger
+  return l.sugaredLogger
 }
 
 func initZapLogger(w io.Writer, logging *logger.HertzBeatLogging, level 
logger.LogLevel) *zap.Logger {
 
-       parseLevel, _ := 
zapcore.ParseLevel(string(logging.DefaultHertzBeatLoggingLevel(level)))
-       core := 
zapcore.NewCore(zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()), 
zapcore.AddSync(w), zap.NewAtomicLevelAt(parseLevel))
+  parseLevel, _ := 
zapcore.ParseLevel(string(logging.DefaultHertzBeatLoggingLevel(level)))
+  core := 
zapcore.NewCore(zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()), 
zapcore.AddSync(w), zap.NewAtomicLevelAt(parseLevel))
 
-       return zap.New(core, zap.AddCaller())
+  return zap.New(core, zap.AddCaller())
 }
diff --git a/tools/linter/license/.licenserc.yaml 
b/tools/linter/license/.licenserc.yaml
index 69e249a..759d4a5 100644
--- a/tools/linter/license/.licenserc.yaml
+++ b/tools/linter/license/.licenserc.yaml
@@ -59,6 +59,7 @@ header:
     - 'tools/linter/yamllint/.yamllint'
     - '.go-version'
     - 'VERSION'
+    - '.editorconfig'
 
   comment: on-failure
 
diff --git a/tools/linter/markdownlint/markdown_lint_config.yaml 
b/tools/linter/markdownlint/markdown_lint_config.yaml
index 1bab6b5..b3114a7 100644
--- a/tools/linter/markdownlint/markdown_lint_config.yaml
+++ b/tools/linter/markdownlint/markdown_lint_config.yaml
@@ -44,3 +44,5 @@ MD051: false
 MD056: false
 # MD055/table-pipe-style
 MD055: false
+# MD060/table
+MD060: false
diff --git a/tools/make/linter.mk b/tools/make/linter.mk
index 557f073..597208d 100644
--- a/tools/make/linter.mk
+++ b/tools/make/linter.mk
@@ -19,7 +19,7 @@
 
 .PHONY: lint
 lint: ## Check files
-lint: markdown-lint-check yaml-lint codespell newline-check
+lint: markdown-lint-check yaml-lint codespell
 
 .PHONY: codespell
 codespell: CODESPELL_SKIP := $(shell cat 
tools/linter/codespell/.codespell.skip | tr \\n ',')
@@ -64,16 +64,6 @@ markdown-lint-fix: ## Fix the markdown files style.
        markdownlint --version
        markdownlint --config 
./tools/linter/markdownlint/markdown_lint_config.yaml --fix .
 
-.PHONY: newline-check
-newline-check: ## Check the newline
-       @$(LOG_TARGET)
-       python3 tools/scripts/new-line-check.py check
-
-.PHONY: newline-fix
-newline-fix: ## Fix the newline
-       @$(LOG_TARGET)
-       python3 tools/scripts/new-line-check.py fix
-
 .PHONY: secrets-check
 secrets-check: ## Check the secrets
        @$(LOG_TARGET)
diff --git a/tools/scripts/new-line-check.py b/tools/scripts/new-line-check.py
deleted file mode 100644
index 50aebc8..0000000
--- a/tools/scripts/new-line-check.py
+++ /dev/null
@@ -1,112 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-
-
-import os
-import sys
-
-# Ignored project folders
-ignore_dirs = [
-    "node_modules",
-    ".idea",
-    ".git",
-    ".vscode",
-    "target",
-    "static",
-    "static_legacy",
-    "frontend",
-    ".husky",
-    "docs",
-    "docker"
-]
-
-# A list of ignored suffix files
-ignore_suffix = [
-    ".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico",
-    ".webp", ".pdf", ".word", ".docx", ".doc", ".ppt",
-    ".xlsx", ".xls", ".exe", "chromedriver", ".pptx", ".jar",
-    ".wav", ".bib", ".cmd", "mvnw", ".bin", ".pcm", ".flac", ".ttf",
-    ".mp4", ".PPT", ".jif", ".zip", ".tar", ".gz", ".rar", ".7z",
-    ".tar.gz", ".tar.bz2", ".tar.xz", ".tgz", ".tbz2", ".txz",
-    ".txt", "collector", ".DS_Store"
-]
-
-# Check if the incoming file ends with a blank line
-def check_file(path):
-    try:
-        with open(path, 'rb') as f:
-            f.seek(0, os.SEEK_END)
-            size = f.tell()
-            if size == 0:
-                return None
-            f.seek(-1, os.SEEK_END)
-            if f.read(1) != b'\n':
-                return path
-    except OSError as e:
-        print(f"Cannot check file: {path}: {e}")
-    return None
-
-# Accept a list, check if each file ends with a blank line, and if not, write 
a new line at the end of the file
-def add_newline(file):
-    print("Fixing: " + file)
-    with open(file, 'a') as f:
-        f.write('\n')
-
-# Gets all the files in the current directory and returns a list of files
-def get_files():
-    files_to_check = []
-    for root, dirs, files in os.walk('.'):
-        # Ignore the specified directory
-        dirs[:] = [d for d in dirs if d not in ignore_dirs]
-        for file in files:
-            if not any(file.endswith(suffix) for suffix in ignore_suffix):
-                files_to_check.append(os.path.join(root, file))
-    return files_to_check
-
-# Run the checks
-def run(check_only=False):
-    files = get_files()
-    files_to_fix = []
-
-    for file in files:
-        result = check_file(file)
-        if result:
-            files_to_fix.append(result)
-
-    if files_to_fix:
-        print("The following files are missing a blank line:")
-        for file in files_to_fix:
-            print(file)
-        if check_only:
-            print("Error: Some files do not end with a blank line.")
-            sys.exit(1)  # Exit with an error code
-        else:
-            for file in files_to_fix:
-                add_newline(file)
-                print(f"Added a line break at the end of {file}.")
-    else:
-        print("All files have ended with a blank line.")
-
-if __name__ == "__main__":
-    mode = sys.argv[1] if len(sys.argv) > 1 else 'check'
-    if mode == 'check':
-        run(check_only=True)
-    elif mode == 'fix':
-        run(check_only=False)
-    else:
-        print("Invalid mode. Please use 'check' or 'fix'.")


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to