From d04a2f69787ee30ef1ca07a183c6c1896458b74b Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Wed, 16 Apr 2025 16:44:37 +0800 Subject: [PATCH 01/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common-utils/hwlog/hwlog_adaptor.go | 31 ++++++- .../taskd/taskd/go/common/utils/utils.go | 8 +- .../taskd/taskd/python/constants/constants.py | 3 +- .../taskd/python/cython_api/cython_api.py | 4 +- .../taskd/taskd/python/utils/log/logger.py | 83 +++++++++++++++---- 5 files changed, 103 insertions(+), 26 deletions(-) diff --git a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go index f91a4be0f..8cd5afa60 100644 --- a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go +++ b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go @@ -18,29 +18,52 @@ package hwlog import ( "context" "errors" + "fmt" ) // RunLog run logger var RunLog *logger +var ModuleRunLog map[string]*logger // InitRunLogger initialize run logger -func InitRunLogger(config *LogConfig, ctx context.Context) error { +func InitRunLogger(config *LogConfig, moduleName string, ctx context.Context) error { if config == nil { return errors.New("run logger config is nil") } + if moduleName == "" { + return initDefaultRunLog(config) + } + if ModuleRunLog[moduleName] != nil && ModuleRunLog[moduleName].isInit() { + ModuleRunLog[moduleName].Warn("run logger for module %s has been initialized", moduleName) + return nil + } + ModuleRunLog[moduleName] = new(logger) + if ModuleRunLog[moduleName] == nil { + return errors.New("malloc new logger failed") + } + if err := ModuleRunLog[moduleName].setLogger(config); err != nil { + return err + } + if !ModuleRunLog[moduleName].isInit() { + return fmt.Errorf("run logger for module %s init failed", moduleName) + } + return nil +} + +func initDefaultRunLog(config *LogConfig) error { if RunLog != nil && RunLog.isInit() { - RunLog.Warn("run logger is been initialized") + RunLog.Warn("run logger has been initialized") return nil } RunLog = new(logger) if RunLog == nil { - return errors.New("malloc new logger flied") + return errors.New("malloc new logger failed") } if err := RunLog.setLogger(config); err != nil { return err } if !RunLog.isInit() { - return errors.New("run logger init failed") + return fmt.Errorf("run logger for module init failed") } return nil } diff --git a/component/taskd/taskd/go/common/utils/utils.go b/component/taskd/taskd/go/common/utils/utils.go index 7cbc81989..03591eefa 100644 --- a/component/taskd/taskd/go/common/utils/utils.go +++ b/component/taskd/taskd/go/common/utils/utils.go @@ -28,14 +28,14 @@ import ( ) // InitHwLog init hwlog -func InitHwLog(ctx context.Context) error { +func InitHwLog(ctx context.Context, moduleName string) error { var logFile string logFilePath := os.Getenv(constant.LogFilePathEnv) logFileName := "taskd-worker-" + strconv.Itoa(profiling.GlobalRankId) + ".log" if logFilePath == "" { - logFile = constant.DefaultLogFilePath + logFileName + logFile = filepath.Join(constant.DefaultLogFilePath, moduleName, logFileName) } else { - logFile = filepath.Join(logFilePath, logFileName) + logFile = filepath.Join(logFilePath, moduleName, logFileName) } hwLogConfig := hwlog.LogConfig{ LogFileName: logFile, @@ -46,7 +46,7 @@ func InitHwLog(ctx context.Context) error { // do not print to screen to avoid influence training log OnlyToFile: true, } - if err := hwlog.InitRunLogger(&hwLogConfig, context.Background()); err != nil { + if err := hwlog.InitRunLogger(&hwLogConfig, "worker", context.Background()); err != nil { fmt.Printf("hwlog init failed, error is %v\n", err) return err } diff --git a/component/taskd/taskd/python/constants/constants.py b/component/taskd/taskd/python/constants/constants.py index f73e35084..5044187a9 100644 --- a/component/taskd/taskd/python/constants/constants.py +++ b/component/taskd/taskd/python/constants/constants.py @@ -34,7 +34,8 @@ TASKD_LOG_PATH = 'TASKD_LOG_PATH' # logger default config LOG_MAX_LINE_LENGTH = 1023 -LOG_SIMPLE_FORMAT = '[%(levelname)s] %(asctime)s.%(msecs)06d %(process)d %(filename)s:%(lineno)d %(message)s' +LOG_SIMPLE_FORMAT = ('[%(levelname)s] %(asctime)s %(process)d %(name)s:%(module)s/%(filename)s:%(lineno)d ' + '%(message)s') LOG_DATE_FORMAT = '%Y/%m/%d %H:%M:%S' LOG_BACKUP_FORMAT = '%Y-%m-%dT%H-%M-%S.%f' LOG_BACKUP_PATTERN = '\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}\.\d{3}' diff --git a/component/taskd/taskd/python/cython_api/cython_api.py b/component/taskd/taskd/python/cython_api/cython_api.py index e15f12b9a..bee9a99f1 100644 --- a/component/taskd/taskd/python/cython_api/cython_api.py +++ b/component/taskd/taskd/python/cython_api/cython_api.py @@ -23,7 +23,7 @@ try: mode = os.RTLD_LAZY | os.RTLD_LOCAL lib_path = os.path.join(os.path.dirname(__file__), LIB_SO_PATH, LIB_SO_NAME) lib = ctypes.CDLL(lib_path, mode=mode) - run_log.info(f"{LIB_SO_NAME} loaded successfully") + # run_log.info(f"{LIB_SO_NAME} loaded successfully") except OSError as e: lib = None - run_log.info(f"{LIB_SO_NAME} loaded failed: {e}") + # run_log.info(f"{LIB_SO_NAME} loaded failed: {e}") diff --git a/component/taskd/taskd/python/utils/log/logger.py b/component/taskd/taskd/python/utils/log/logger.py index 74eaba1e2..400a2cc52 100644 --- a/component/taskd/taskd/python/utils/log/logger.py +++ b/component/taskd/taskd/python/utils/log/logger.py @@ -14,11 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== +import ctypes import datetime import logging import os import re import sys +import time from logging.handlers import RotatingFileHandler from taskd.python.constants.constants import (LOG_DEFAULT_FILE_PATH, LOG_MAX_LINE_LENGTH, LOG_DATE_FORMAT, @@ -27,6 +29,7 @@ from taskd.python.constants.constants import (LOG_DEFAULT_FILE_PATH, LOG_MAX_LIN LOG_PRIVILEGE, LOG_DIR_PRIVILEGE, LOG_BACKUP_PATTERN, TASKD_LOG_STDOUT, TASKD_LOG_PATH, TASKD_FILE_LOG_LEVEL, TASKD_STD_LOG_LEVEL) +from taskd.python.cython_api.cython_api import lib from taskd.python.utils.validator import FileValidator @@ -48,11 +51,22 @@ class MaxLengthFormatter(logging.Formatter): return msg[:self.max_length] + '...' return msg + def formatTime(self, record, datefmt=None): + ct = time.localtime(record.created) + timestamp = record.created + seconds = int(timestamp) + microseconds = int((timestamp - seconds) * 1000000) + if datefmt: + s = time.strftime(datefmt, ct) + else: + s = time.strftime(LOG_DATE_FORMAT, ct) + return f"{s}.{microseconds:06d}" + class CustomRotatingHandler(RotatingFileHandler): - ''' + """ Custom RotatingFileHandler to backup same format log file - ''' + """ def __init__(self, filename, maxBytes=0, backupCount=0, encoding=None, delay=None): super().__init__( @@ -124,15 +138,22 @@ class LogConfig: Log Config include logger configuration """ - def __init__(self): - self.log_max_line_length = LOG_MAX_LINE_LENGTH - self.file_log_level = logging.INFO - self.std_log_level = logging.INFO - self.log_format = LOG_SIMPLE_FORMAT - self.log_file = LOG_DEFAULT_FILE - self.log_std_out = True - self.log_backup_count = LOG_DEFAULT_BACKUP_COUNT - self.log_max_bytes = LOG_DEFAULT_MAX_BYTES + def __init__(self, log_file, + log_max_line_length=LOG_MAX_LINE_LENGTH, + file_log_level=logging.INFO, + std_log_level=logging.INFO, + log_format=LOG_SIMPLE_FORMAT, + log_std_out=True, + log_backup_count=LOG_DEFAULT_BACKUP_COUNT, + log_max_bytes=LOG_DEFAULT_MAX_BYTES): + self.log_max_line_length = log_max_line_length + self.file_log_level = file_log_level + self.std_log_level = std_log_level + self.log_format = log_format + self.log_file = log_file + self.log_std_out = log_std_out + self.log_backup_count = log_backup_count + self.log_max_bytes = log_max_bytes self.build_config() def build_config(self): @@ -230,10 +251,10 @@ def _get_file_handler(cfg: LogConfig): return file_handler -def _get_logger() -> logging.Logger: +def get_logger(sub_module_name: str, log_file_path: str, **kwargs) -> logging.Logger: # init logger and log config - log_cfg = LogConfig() - logger = logging.getLogger("taskd") + log_cfg = LogConfig(log_file=log_file_path, **kwargs) + logger = logging.getLogger(f"taskd.{sub_module_name}") logger.setLevel(logging.DEBUG) @@ -248,4 +269,36 @@ def _get_logger() -> logging.Logger: return logger -run_log = _get_logger() +class GoLogConfig(object): + _fields_ = [ + ('LogFileName', ctypes.c_char_p), + ('OnlyToStdout', ctypes.c_bool), + ('OnlyToFile', ctypes.c_bool), + ('LogLevel', ctypes.c_int), + ('FileMaxSize', ctypes.c_int), + ('MaxLineLength', ctypes.c_int), + ('MaxBackups', ctypes.c_int), + ('MaxAge', ctypes.c_int), + ('IsCompress', ctypes.c_bool), + ('ExpiredTime', ctypes.c_int), + ('CacheSize', ctypes.c_int) + ] + + +def init_go_logger(log_file_name, sub_module_name, **kwargs): + if isinstance(log_file_name, str): + log_file_name = log_file_name.encode() + + config = GoLogConfig() + config.LogFileName = log_file_name + + for key, value in kwargs.items(): + if hasattr(config, key): + setattr(config, key, value) + lib.InitModuleLogger(ctypes.byref(config), sub_module_name) + + +run_log = get_logger("worker", log_file_path=LOG_DEFAULT_FILE) + +if __name__ == "__main__": + run_log.info("stre") -- Gitee From a165247058ef6404d517d119c0122aa0b950cd84 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 11:03:19 +0800 Subject: [PATCH 02/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 2 +- component/taskd/taskd/go/common/utils/utils.go | 4 +++- .../taskd/taskd/python/constants/constants.py | 4 ++-- component/taskd/taskd/python/utils/log/logger.py | 15 ++++++++++----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index decee1461..b112de0f2 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -41,7 +41,7 @@ func InitTaskMonitor(rank int, upperLimitOfDiskInMb int) C.int { profiling.SetDiskUsageUpperLimitMB(upperLimitOfDiskInMb) profiling.GlobalRankId = rank // init so should not use print to avoid impact on system calls - err := utils.InitHwLog(ctx) + err := utils.InitHwLog("monitor-1") if err != nil { fmt.Println(err) return C.int(1) diff --git a/component/taskd/taskd/go/common/utils/utils.go b/component/taskd/taskd/go/common/utils/utils.go index 03591eefa..ce3b9b7cf 100644 --- a/component/taskd/taskd/go/common/utils/utils.go +++ b/component/taskd/taskd/go/common/utils/utils.go @@ -28,7 +28,9 @@ import ( ) // InitHwLog init hwlog -func InitHwLog(ctx context.Context, moduleName string) error { + +//export InitHwLog +func InitHwLog(moduleName string) error { var logFile string logFilePath := os.Getenv(constant.LogFilePathEnv) logFileName := "taskd-worker-" + strconv.Itoa(profiling.GlobalRankId) + ".log" diff --git a/component/taskd/taskd/python/constants/constants.py b/component/taskd/taskd/python/constants/constants.py index 5044187a9..10f0ccf0b 100644 --- a/component/taskd/taskd/python/constants/constants.py +++ b/component/taskd/taskd/python/constants/constants.py @@ -34,8 +34,8 @@ TASKD_LOG_PATH = 'TASKD_LOG_PATH' # logger default config LOG_MAX_LINE_LENGTH = 1023 -LOG_SIMPLE_FORMAT = ('[%(levelname)s] %(asctime)s %(process)d %(name)s:%(module)s/%(filename)s:%(lineno)d ' - '%(message)s') +LOG_SIMPLE_FORMAT = ('[%(levelname)s] %(asctime)s processID:%(process)d %(name)s:%(module)s/%(filename)s:%(' + 'lineno)d ''%(message)s') LOG_DATE_FORMAT = '%Y/%m/%d %H:%M:%S' LOG_BACKUP_FORMAT = '%Y-%m-%dT%H-%M-%S.%f' LOG_BACKUP_PATTERN = '\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}\.\d{3}' diff --git a/component/taskd/taskd/python/utils/log/logger.py b/component/taskd/taskd/python/utils/log/logger.py index 400a2cc52..a2ebac131 100644 --- a/component/taskd/taskd/python/utils/log/logger.py +++ b/component/taskd/taskd/python/utils/log/logger.py @@ -162,6 +162,8 @@ class LogConfig: self.build_log_stdout() def build_log_path(self): + if self.log_file != "": + return log_path = os.getenv(TASKD_LOG_PATH) if log_path is None: log_path = LOG_DEFAULT_FILE_PATH @@ -251,9 +253,10 @@ def _get_file_handler(cfg: LogConfig): return file_handler -def get_logger(sub_module_name: str, log_file_path: str, **kwargs) -> logging.Logger: +def get_logger(sub_module_name: str, log_file_name: str, **kwargs) -> logging.Logger: # init logger and log config - log_cfg = LogConfig(log_file=log_file_path, **kwargs) + log_file = os.path.join(LOG_DEFAULT_FILE_PATH,sub_module_name,log_file_name) + log_cfg = LogConfig(log_file=log_file, **kwargs) logger = logging.getLogger(f"taskd.{sub_module_name}") logger.setLevel(logging.DEBUG) @@ -295,10 +298,12 @@ def init_go_logger(log_file_name, sub_module_name, **kwargs): for key, value in kwargs.items(): if hasattr(config, key): setattr(config, key, value) - lib.InitModuleLogger(ctypes.byref(config), sub_module_name) + lib.InitHwLog(sub_module_name) -run_log = get_logger("worker", log_file_path=LOG_DEFAULT_FILE) +worker_log = get_logger("worker", log_file_name='worker.log') +monitor_log = get_logger("monitor", log_file_name='monitor.log') if __name__ == "__main__": - run_log.info("stre") + worker_log.warning("worker") + monitor_log.warning("monitor") -- Gitee From a7700b751d3cc99ae7b146256d28c4992f6851cc Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 11:32:23 +0800 Subject: [PATCH 03/21] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 33 +++++++++++++++- .../taskd/taskd/go/common/utils/utils.go | 39 ------------------- .../taskd/python/cython_api/cython_api.py | 2 +- .../taskd/taskd/python/utils/log/logger.py | 14 ++----- 4 files changed, 36 insertions(+), 52 deletions(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index b112de0f2..e91e5b0ff 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -21,12 +21,13 @@ import ( "fmt" "os" "os/signal" + "path/filepath" + "strconv" "syscall" "time" "ascend-common/common-utils/hwlog" "taskd/common/constant" - "taskd/common/utils" "taskd/framework_backend/worker/monitor/profiling" ) @@ -41,7 +42,7 @@ func InitTaskMonitor(rank int, upperLimitOfDiskInMb int) C.int { profiling.SetDiskUsageUpperLimitMB(upperLimitOfDiskInMb) profiling.GlobalRankId = rank // init so should not use print to avoid impact on system calls - err := utils.InitHwLog("monitor-1") + err := InitHwLog("monitor-1") if err != nil { fmt.Println(err) return C.int(1) @@ -87,5 +88,33 @@ func StartMonitorClient() C.int { return C.int(0) } +// InitHwLog init hwlog + +//export InitHwLog +func InitHwLog(moduleName string) error { + var logFile string + logFilePath := os.Getenv(constant.LogFilePathEnv) + logFileName := "taskd-worker-" + strconv.Itoa(profiling.GlobalRankId) + ".log" + if logFilePath == "" { + logFile = filepath.Join(constant.DefaultLogFilePath, moduleName, logFileName) + } else { + logFile = filepath.Join(logFilePath, moduleName, logFileName) + } + hwLogConfig := hwlog.LogConfig{ + LogFileName: logFile, + LogLevel: constant.DefaultLogLevel, + MaxBackups: constant.DefaultMaxBackups, + MaxAge: constant.DefaultMaxAge, + MaxLineLength: constant.DefaultMaxLineLength, + // do not print to screen to avoid influence training log + OnlyToFile: true, + } + if err := hwlog.InitRunLogger(&hwLogConfig, "worker", context.Background()); err != nil { + fmt.Printf("hwlog init failed, error is %v\n", err) + return err + } + return nil +} + func main() { } diff --git a/component/taskd/taskd/go/common/utils/utils.go b/component/taskd/taskd/go/common/utils/utils.go index ce3b9b7cf..62b6703d3 100644 --- a/component/taskd/taskd/go/common/utils/utils.go +++ b/component/taskd/taskd/go/common/utils/utils.go @@ -15,42 +15,3 @@ // Package utils is to provide go runtime utils package utils -import ( - "context" - "fmt" - "os" - "path/filepath" - "strconv" - - "ascend-common/common-utils/hwlog" - "taskd/common/constant" - "taskd/framework_backend/worker/monitor/profiling" -) - -// InitHwLog init hwlog - -//export InitHwLog -func InitHwLog(moduleName string) error { - var logFile string - logFilePath := os.Getenv(constant.LogFilePathEnv) - logFileName := "taskd-worker-" + strconv.Itoa(profiling.GlobalRankId) + ".log" - if logFilePath == "" { - logFile = filepath.Join(constant.DefaultLogFilePath, moduleName, logFileName) - } else { - logFile = filepath.Join(logFilePath, moduleName, logFileName) - } - hwLogConfig := hwlog.LogConfig{ - LogFileName: logFile, - LogLevel: constant.DefaultLogLevel, - MaxBackups: constant.DefaultMaxBackups, - MaxAge: constant.DefaultMaxAge, - MaxLineLength: constant.DefaultMaxLineLength, - // do not print to screen to avoid influence training log - OnlyToFile: true, - } - if err := hwlog.InitRunLogger(&hwLogConfig, "worker", context.Background()); err != nil { - fmt.Printf("hwlog init failed, error is %v\n", err) - return err - } - return nil -} diff --git a/component/taskd/taskd/python/cython_api/cython_api.py b/component/taskd/taskd/python/cython_api/cython_api.py index bee9a99f1..f44010b44 100644 --- a/component/taskd/taskd/python/cython_api/cython_api.py +++ b/component/taskd/taskd/python/cython_api/cython_api.py @@ -16,7 +16,7 @@ # ============================================================================== import ctypes import os -from taskd.python.utils.log import run_log +# from taskd.python.utils.log import run_log from taskd.python.constants.constants import LIB_SO_NAME, LIB_SO_PATH try: diff --git a/component/taskd/taskd/python/utils/log/logger.py b/component/taskd/taskd/python/utils/log/logger.py index a2ebac131..eb390fcc8 100644 --- a/component/taskd/taskd/python/utils/log/logger.py +++ b/component/taskd/taskd/python/utils/log/logger.py @@ -29,6 +29,7 @@ from taskd.python.constants.constants import (LOG_DEFAULT_FILE_PATH, LOG_MAX_LIN LOG_PRIVILEGE, LOG_DIR_PRIVILEGE, LOG_BACKUP_PATTERN, TASKD_LOG_STDOUT, TASKD_LOG_PATH, TASKD_FILE_LOG_LEVEL, TASKD_STD_LOG_LEVEL) +from taskd.python.cython_api import cython_api from taskd.python.cython_api.cython_api import lib from taskd.python.utils.validator import FileValidator @@ -289,19 +290,12 @@ class GoLogConfig(object): def init_go_logger(log_file_name, sub_module_name, **kwargs): - if isinstance(log_file_name, str): - log_file_name = log_file_name.encode() - - config = GoLogConfig() - config.LogFileName = log_file_name - - for key, value in kwargs.items(): - if hasattr(config, key): - setattr(config, key, value) - lib.InitHwLog(sub_module_name) + InitHwLog = cython_api.lib.InitHwLog + InitHwLog(sub_module_name) worker_log = get_logger("worker", log_file_name='worker.log') +init_go_logger(log_file_name="",sub_module_name="worker") monitor_log = get_logger("monitor", log_file_name='monitor.log') if __name__ == "__main__": -- Gitee From d47a428d4c395a4cdfe8de17853ba19231035442 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 11:36:44 +0800 Subject: [PATCH 04/21] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/ascend-common/common-utils/hwlog/hwlog_adaptor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go index 8cd5afa60..04785f4df 100644 --- a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go +++ b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go @@ -23,7 +23,7 @@ import ( // RunLog run logger var RunLog *logger -var ModuleRunLog map[string]*logger +var ModuleRunLog = make(map[string]*logger) // InitRunLogger initialize run logger func InitRunLogger(config *LogConfig, moduleName string, ctx context.Context) error { -- Gitee From 2597f36b5a95492bc3b12927848f6b4dc5f3fdf9 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 11:43:25 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/ascend-common/common-utils/hwlog/hwlog_adaptor.go | 4 ++++ component/taskd/taskd/go/backend_api.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go index 04785f4df..507843725 100644 --- a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go +++ b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go @@ -33,17 +33,21 @@ func InitRunLogger(config *LogConfig, moduleName string, ctx context.Context) er if moduleName == "" { return initDefaultRunLog(config) } + print(11111111111111111111111) if ModuleRunLog[moduleName] != nil && ModuleRunLog[moduleName].isInit() { ModuleRunLog[moduleName].Warn("run logger for module %s has been initialized", moduleName) return nil } + print(222222222222222222222222222222222) ModuleRunLog[moduleName] = new(logger) if ModuleRunLog[moduleName] == nil { return errors.New("malloc new logger failed") } + print(444444444444444444444444444444444) if err := ModuleRunLog[moduleName].setLogger(config); err != nil { return err } + print(555555555555555555555555555555555) if !ModuleRunLog[moduleName].isInit() { return fmt.Errorf("run logger for module %s init failed", moduleName) } diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index e91e5b0ff..01bcb445a 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -107,7 +107,7 @@ func InitHwLog(moduleName string) error { MaxAge: constant.DefaultMaxAge, MaxLineLength: constant.DefaultMaxLineLength, // do not print to screen to avoid influence training log - OnlyToFile: true, + OnlyToFile: false, } if err := hwlog.InitRunLogger(&hwLogConfig, "worker", context.Background()); err != nil { fmt.Printf("hwlog init failed, error is %v\n", err) -- Gitee From 06152ddfbdb5e1445d5c094223ed3594f3949252 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 11:44:59 +0800 Subject: [PATCH 06/21] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ascend-common/common-utils/hwlog/hwlog_adaptor.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go index 507843725..480dda7a4 100644 --- a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go +++ b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go @@ -33,21 +33,21 @@ func InitRunLogger(config *LogConfig, moduleName string, ctx context.Context) er if moduleName == "" { return initDefaultRunLog(config) } - print(11111111111111111111111) + print("11111111111111111111111") if ModuleRunLog[moduleName] != nil && ModuleRunLog[moduleName].isInit() { ModuleRunLog[moduleName].Warn("run logger for module %s has been initialized", moduleName) return nil } - print(222222222222222222222222222222222) + print("222222222222222222222222222222222") ModuleRunLog[moduleName] = new(logger) if ModuleRunLog[moduleName] == nil { return errors.New("malloc new logger failed") } - print(444444444444444444444444444444444) + print("444444444444444444444444444444444") if err := ModuleRunLog[moduleName].setLogger(config); err != nil { return err } - print(555555555555555555555555555555555) + print("555555555555555555555555555555555") if !ModuleRunLog[moduleName].isInit() { return fmt.Errorf("run logger for module %s init failed", moduleName) } -- Gitee From ce6e10ab33ea598d1cd74415a1feb24950ee6a34 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 14:03:32 +0800 Subject: [PATCH 07/21] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/ascend-common/common-utils/hwlog/hwlog_adaptor.go | 1 + component/taskd/taskd/go/backend_api.go | 1 + 2 files changed, 2 insertions(+) diff --git a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go index 480dda7a4..1e752b605 100644 --- a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go +++ b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go @@ -51,6 +51,7 @@ func InitRunLogger(config *LogConfig, moduleName string, ctx context.Context) er if !ModuleRunLog[moduleName].isInit() { return fmt.Errorf("run logger for module %s init failed", moduleName) } + print("6666666666666666666666") return nil } diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index 01bcb445a..0c55d13cf 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -113,6 +113,7 @@ func InitHwLog(moduleName string) error { fmt.Printf("hwlog init failed, error is %v\n", err) return err } + print("777777777") return nil } -- Gitee From 9672eed7b26a6afda49b0b5eb39a7f196af8b278 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 16:03:47 +0800 Subject: [PATCH 08/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/ascend-common/common-utils/hwlog/hwlog_adaptor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go index 1e752b605..5f30f9c89 100644 --- a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go +++ b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go @@ -47,11 +47,11 @@ func InitRunLogger(config *LogConfig, moduleName string, ctx context.Context) er if err := ModuleRunLog[moduleName].setLogger(config); err != nil { return err } - print("555555555555555555555555555555555") + print("555555555555555555555555555555555-1\n") if !ModuleRunLog[moduleName].isInit() { return fmt.Errorf("run logger for module %s init failed", moduleName) } - print("6666666666666666666666") + print("6666666666666666666666\n") return nil } -- Gitee From 04ff7660ef78f2a3f60bbcb588e52b21436d616c Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 16:10:08 +0800 Subject: [PATCH 09/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index 0c55d13cf..be773a649 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -42,9 +42,9 @@ func InitTaskMonitor(rank int, upperLimitOfDiskInMb int) C.int { profiling.SetDiskUsageUpperLimitMB(upperLimitOfDiskInMb) profiling.GlobalRankId = rank // init so should not use print to avoid impact on system calls - err := InitHwLog("monitor-1") - if err != nil { - fmt.Println(err) + retCode := InitHwLog("monitor-1") + if retCode != C.int(0) { + fmt.Println(retCode) return C.int(1) } if err := profiling.InitMspti(); err != nil { @@ -91,7 +91,7 @@ func StartMonitorClient() C.int { // InitHwLog init hwlog //export InitHwLog -func InitHwLog(moduleName string) error { +func InitHwLog(moduleName string) C.int { var logFile string logFilePath := os.Getenv(constant.LogFilePathEnv) logFileName := "taskd-worker-" + strconv.Itoa(profiling.GlobalRankId) + ".log" @@ -114,7 +114,7 @@ func InitHwLog(moduleName string) error { return err } print("777777777") - return nil + return C.int(0) } func main() { -- Gitee From 0552c727e9eeb5d94ab229401a0850bb0882435f Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 16:11:45 +0800 Subject: [PATCH 10/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index be773a649..c38b494e8 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -111,7 +111,7 @@ func InitHwLog(moduleName string) C.int { } if err := hwlog.InitRunLogger(&hwLogConfig, "worker", context.Background()); err != nil { fmt.Printf("hwlog init failed, error is %v\n", err) - return err + return C.int(1) } print("777777777") return C.int(0) -- Gitee From 68f91ff653d2b73a95c67006a8ac17a4f96da846 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 16:19:16 +0800 Subject: [PATCH 11/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/ascend-common/common-utils/hwlog/hwlog_adaptor.go | 5 ----- component/taskd/taskd/go/backend_api.go | 5 +---- component/taskd/taskd/python/utils/log/logger.py | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go index 5f30f9c89..04785f4df 100644 --- a/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go +++ b/component/ascend-common/common-utils/hwlog/hwlog_adaptor.go @@ -33,25 +33,20 @@ func InitRunLogger(config *LogConfig, moduleName string, ctx context.Context) er if moduleName == "" { return initDefaultRunLog(config) } - print("11111111111111111111111") if ModuleRunLog[moduleName] != nil && ModuleRunLog[moduleName].isInit() { ModuleRunLog[moduleName].Warn("run logger for module %s has been initialized", moduleName) return nil } - print("222222222222222222222222222222222") ModuleRunLog[moduleName] = new(logger) if ModuleRunLog[moduleName] == nil { return errors.New("malloc new logger failed") } - print("444444444444444444444444444444444") if err := ModuleRunLog[moduleName].setLogger(config); err != nil { return err } - print("555555555555555555555555555555555-1\n") if !ModuleRunLog[moduleName].isInit() { return fmt.Errorf("run logger for module %s init failed", moduleName) } - print("6666666666666666666666\n") return nil } diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index c38b494e8..59a420e59 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -22,7 +22,6 @@ import ( "os" "os/signal" "path/filepath" - "strconv" "syscall" "time" @@ -91,10 +90,9 @@ func StartMonitorClient() C.int { // InitHwLog init hwlog //export InitHwLog -func InitHwLog(moduleName string) C.int { +func InitHwLog(logFileName, moduleName string) C.int { var logFile string logFilePath := os.Getenv(constant.LogFilePathEnv) - logFileName := "taskd-worker-" + strconv.Itoa(profiling.GlobalRankId) + ".log" if logFilePath == "" { logFile = filepath.Join(constant.DefaultLogFilePath, moduleName, logFileName) } else { @@ -113,7 +111,6 @@ func InitHwLog(moduleName string) C.int { fmt.Printf("hwlog init failed, error is %v\n", err) return C.int(1) } - print("777777777") return C.int(0) } diff --git a/component/taskd/taskd/python/utils/log/logger.py b/component/taskd/taskd/python/utils/log/logger.py index eb390fcc8..fdeac9184 100644 --- a/component/taskd/taskd/python/utils/log/logger.py +++ b/component/taskd/taskd/python/utils/log/logger.py @@ -295,7 +295,7 @@ def init_go_logger(log_file_name, sub_module_name, **kwargs): worker_log = get_logger("worker", log_file_name='worker.log') -init_go_logger(log_file_name="",sub_module_name="worker") +init_go_logger(log_file_name="worker.log",sub_module_name="worker") monitor_log = get_logger("monitor", log_file_name='monitor.log') if __name__ == "__main__": -- Gitee From 41e2b2dc1e20a86eddda545a554c32ecc5fc1aa9 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 16:21:01 +0800 Subject: [PATCH 12/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index 59a420e59..dbf61e817 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -41,7 +41,7 @@ func InitTaskMonitor(rank int, upperLimitOfDiskInMb int) C.int { profiling.SetDiskUsageUpperLimitMB(upperLimitOfDiskInMb) profiling.GlobalRankId = rank // init so should not use print to avoid impact on system calls - retCode := InitHwLog("monitor-1") + retCode := InitHwLog("monitor.log", "monitor-1") if retCode != C.int(0) { fmt.Println(retCode) return C.int(1) -- Gitee From 02d797c2d0c0d0d464e93c9c376d0e7b5f61d79f Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 16:31:42 +0800 Subject: [PATCH 13/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 5 ++++- component/taskd/taskd/python/utils/log/logger.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index dbf61e817..78fa3a331 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -93,6 +93,9 @@ func StartMonitorClient() C.int { func InitHwLog(logFileName, moduleName string) C.int { var logFile string logFilePath := os.Getenv(constant.LogFilePathEnv) + fmt.Printf("LogFilePathEnv: %s\n", logFilePath) + fmt.Printf("logFileName: %s\n", logFileName) + fmt.Printf("moduleName: %s\n", moduleName) if logFilePath == "" { logFile = filepath.Join(constant.DefaultLogFilePath, moduleName, logFileName) } else { @@ -107,7 +110,7 @@ func InitHwLog(logFileName, moduleName string) C.int { // do not print to screen to avoid influence training log OnlyToFile: false, } - if err := hwlog.InitRunLogger(&hwLogConfig, "worker", context.Background()); err != nil { + if err := hwlog.InitRunLogger(&hwLogConfig, moduleName, context.Background()); err != nil { fmt.Printf("hwlog init failed, error is %v\n", err) return C.int(1) } diff --git a/component/taskd/taskd/python/utils/log/logger.py b/component/taskd/taskd/python/utils/log/logger.py index fdeac9184..57da81ce0 100644 --- a/component/taskd/taskd/python/utils/log/logger.py +++ b/component/taskd/taskd/python/utils/log/logger.py @@ -256,7 +256,7 @@ def _get_file_handler(cfg: LogConfig): def get_logger(sub_module_name: str, log_file_name: str, **kwargs) -> logging.Logger: # init logger and log config - log_file = os.path.join(LOG_DEFAULT_FILE_PATH,sub_module_name,log_file_name) + log_file = os.path.join(LOG_DEFAULT_FILE_PATH, sub_module_name, log_file_name) log_cfg = LogConfig(log_file=log_file, **kwargs) logger = logging.getLogger(f"taskd.{sub_module_name}") @@ -291,11 +291,11 @@ class GoLogConfig(object): def init_go_logger(log_file_name, sub_module_name, **kwargs): InitHwLog = cython_api.lib.InitHwLog - InitHwLog(sub_module_name) + InitHwLog(log_file_name, sub_module_name) worker_log = get_logger("worker", log_file_name='worker.log') -init_go_logger(log_file_name="worker.log",sub_module_name="worker") +init_go_logger(log_file_name="worker.log", sub_module_name="worker") monitor_log = get_logger("monitor", log_file_name='monitor.log') if __name__ == "__main__": -- Gitee From 46ff4f5dbe3dcc63fcc5567511d708577c9b387a Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 17:06:10 +0800 Subject: [PATCH 14/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 7 ++++--- component/taskd/taskd/python/utils/log/logger.py | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index 78fa3a331..ad69791d2 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -90,17 +90,18 @@ func StartMonitorClient() C.int { // InitHwLog init hwlog //export InitHwLog -func InitHwLog(logFileName, moduleName string) C.int { +func InitHwLog(logFileName string, moduleName string) C.int { var logFile string logFilePath := os.Getenv(constant.LogFilePathEnv) fmt.Printf("LogFilePathEnv: %s\n", logFilePath) - fmt.Printf("logFileName: %s\n", logFileName) - fmt.Printf("moduleName: %s\n", moduleName) + fmt.Printf("logFileName: %d\n", len(logFileName)) + fmt.Printf("moduleName: %d\n", len(moduleName)) if logFilePath == "" { logFile = filepath.Join(constant.DefaultLogFilePath, moduleName, logFileName) } else { logFile = filepath.Join(logFilePath, moduleName, logFileName) } + fmt.Println("11111111111111") hwLogConfig := hwlog.LogConfig{ LogFileName: logFile, LogLevel: constant.DefaultLogLevel, diff --git a/component/taskd/taskd/python/utils/log/logger.py b/component/taskd/taskd/python/utils/log/logger.py index 57da81ce0..8337695ad 100644 --- a/component/taskd/taskd/python/utils/log/logger.py +++ b/component/taskd/taskd/python/utils/log/logger.py @@ -291,7 +291,9 @@ class GoLogConfig(object): def init_go_logger(log_file_name, sub_module_name, **kwargs): InitHwLog = cython_api.lib.InitHwLog - InitHwLog(log_file_name, sub_module_name) + log_file_name_bytes = log_file_name.encode('utf-8') + sub_module_name_bytes = sub_module_name.encode('utf-8') + InitHwLog() worker_log = get_logger("worker", log_file_name='worker.log') -- Gitee From e566739a075caddada744f318cc50a4dac6ec573 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 17:14:23 +0800 Subject: [PATCH 15/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 10 ++++++---- component/taskd/taskd/python/utils/log/logger.py | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index ad69791d2..a9b80d184 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -92,14 +92,16 @@ func StartMonitorClient() C.int { //export InitHwLog func InitHwLog(logFileName string, moduleName string) C.int { var logFile string + goLogFileName := C.GoString(logFileName) + goModuleName := C.GoString(moduleName) logFilePath := os.Getenv(constant.LogFilePathEnv) fmt.Printf("LogFilePathEnv: %s\n", logFilePath) - fmt.Printf("logFileName: %d\n", len(logFileName)) - fmt.Printf("moduleName: %d\n", len(moduleName)) + fmt.Printf("logFileName: %d\n", len(goLogFileName)) + fmt.Printf("moduleName: %d\n", len(goModuleName)) if logFilePath == "" { - logFile = filepath.Join(constant.DefaultLogFilePath, moduleName, logFileName) + logFile = filepath.Join(constant.DefaultLogFilePath, goModuleName, goLogFileName) } else { - logFile = filepath.Join(logFilePath, moduleName, logFileName) + logFile = filepath.Join(logFilePath, goModuleName, goLogFileName) } fmt.Println("11111111111111") hwLogConfig := hwlog.LogConfig{ diff --git a/component/taskd/taskd/python/utils/log/logger.py b/component/taskd/taskd/python/utils/log/logger.py index 8337695ad..180e019d6 100644 --- a/component/taskd/taskd/python/utils/log/logger.py +++ b/component/taskd/taskd/python/utils/log/logger.py @@ -290,10 +290,12 @@ class GoLogConfig(object): def init_go_logger(log_file_name, sub_module_name, **kwargs): + lib.InitHwLog.argtypes = [ctypes.c_char_p, ctypes.c_char_p] + lib.InitHwLog.restype = ctypes.c_int InitHwLog = cython_api.lib.InitHwLog log_file_name_bytes = log_file_name.encode('utf-8') sub_module_name_bytes = sub_module_name.encode('utf-8') - InitHwLog() + InitHwLog("worker.log", "worker") worker_log = get_logger("worker", log_file_name='worker.log') -- Gitee From 5100cb3e31c5b5ae3b143e5617c8c5006ec5783e Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 17:16:31 +0800 Subject: [PATCH 16/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index a9b80d184..205615657 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -90,7 +90,7 @@ func StartMonitorClient() C.int { // InitHwLog init hwlog //export InitHwLog -func InitHwLog(logFileName string, moduleName string) C.int { +func InitHwLog(logFileName *C.char, moduleName *C.char) C.int { var logFile string goLogFileName := C.GoString(logFileName) goModuleName := C.GoString(moduleName) -- Gitee From 80d7e74119fb52ef8b53402658155614f6126f88 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 17:19:06 +0800 Subject: [PATCH 17/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index 205615657..b79d2ec09 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -41,11 +41,11 @@ func InitTaskMonitor(rank int, upperLimitOfDiskInMb int) C.int { profiling.SetDiskUsageUpperLimitMB(upperLimitOfDiskInMb) profiling.GlobalRankId = rank // init so should not use print to avoid impact on system calls - retCode := InitHwLog("monitor.log", "monitor-1") - if retCode != C.int(0) { - fmt.Println(retCode) - return C.int(1) - } + //retCode := InitHwLog("monitor.log", "monitor-1") + //if retCode != C.int(0) { + // fmt.Println(retCode) + // return C.int(1) + //} if err := profiling.InitMspti(); err != nil { hwlog.RunLog.Error(err) return C.int(1) -- Gitee From 12da10d0b83fe3e886c6e9b35671c148df4059e7 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Thu, 24 Apr 2025 17:20:47 +0800 Subject: [PATCH 18/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index b79d2ec09..750ce4182 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -113,7 +113,7 @@ func InitHwLog(logFileName *C.char, moduleName *C.char) C.int { // do not print to screen to avoid influence training log OnlyToFile: false, } - if err := hwlog.InitRunLogger(&hwLogConfig, moduleName, context.Background()); err != nil { + if err := hwlog.InitRunLogger(&hwLogConfig, goModuleName, context.Background()); err != nil { fmt.Printf("hwlog init failed, error is %v\n", err) return C.int(1) } -- Gitee From 9ad1a3376343bd910d5dfc72cd180b892a7c27d6 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Fri, 25 Apr 2025 10:59:05 +0800 Subject: [PATCH 19/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 9 +- .../taskd/taskd/python/constants/constants.py | 2 +- .../taskd/taskd/python/utils/log/logger.py | 122 ++---------------- 3 files changed, 20 insertions(+), 113 deletions(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index 750ce4182..f3c92e738 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -103,7 +103,14 @@ func InitHwLog(logFileName *C.char, moduleName *C.char) C.int { } else { logFile = filepath.Join(logFilePath, goModuleName, goLogFileName) } - fmt.Println("11111111111111") + go func() { + cnt := 1 + for { + time.Sleep(time.Second) + hwlog.RunLog.Infof("hwlog cnt:%d", cnt) + cnt++ + } + }() hwLogConfig := hwlog.LogConfig{ LogFileName: logFile, LogLevel: constant.DefaultLogLevel, diff --git a/component/taskd/taskd/python/constants/constants.py b/component/taskd/taskd/python/constants/constants.py index 10f0ccf0b..596952702 100644 --- a/component/taskd/taskd/python/constants/constants.py +++ b/component/taskd/taskd/python/constants/constants.py @@ -34,7 +34,7 @@ TASKD_LOG_PATH = 'TASKD_LOG_PATH' # logger default config LOG_MAX_LINE_LENGTH = 1023 -LOG_SIMPLE_FORMAT = ('[%(levelname)s] %(asctime)s processID:%(process)d %(name)s:%(module)s/%(filename)s:%(' +LOG_SIMPLE_FORMAT = ('[%(levelname)s] %(asctime)s %(process)d %(name)s:%(module)s/%(filename)s:%(' 'lineno)d ''%(message)s') LOG_DATE_FORMAT = '%Y/%m/%d %H:%M:%S' LOG_BACKUP_FORMAT = '%Y-%m-%dT%H-%M-%S.%f' diff --git a/component/taskd/taskd/python/utils/log/logger.py b/component/taskd/taskd/python/utils/log/logger.py index 180e019d6..759571de1 100644 --- a/component/taskd/taskd/python/utils/log/logger.py +++ b/component/taskd/taskd/python/utils/log/logger.py @@ -21,7 +21,6 @@ import os import re import sys import time -from logging.handlers import RotatingFileHandler from taskd.python.constants.constants import (LOG_DEFAULT_FILE_PATH, LOG_MAX_LINE_LENGTH, LOG_DATE_FORMAT, LOG_SIMPLE_FORMAT, LOG_DEFAULT_FILE, LOG_DEFAULT_FILE_NAME, @@ -64,76 +63,6 @@ class MaxLengthFormatter(logging.Formatter): return f"{s}.{microseconds:06d}" -class CustomRotatingHandler(RotatingFileHandler): - """ - Custom RotatingFileHandler to backup same format log file - """ - - def __init__(self, filename, maxBytes=0, backupCount=0, encoding=None, delay=None): - super().__init__( - filename, maxBytes=maxBytes, - backupCount=backupCount, - encoding=encoding, - delay=delay - ) - - def rotation_filename(self, default_name): - base, ext = os.path.splitext(self.baseFilename) - back_time = datetime.datetime.now(tz=datetime.timezone.utc).strftime(LOG_BACKUP_FORMAT)[:-3] - return f"{base}-{back_time}{ext}" - - def doRollover(self): - """ - rewrite to do roll log file - """ - if self.stream: - self.stream.close() - self.stream = None - - # create backup file name and rename the current log file - backup_file_name = self.rotation_filename(self.baseFilename) - if os.path.exists(backup_file_name): - os.remove(backup_file_name) - os.rename(self.baseFilename, backup_file_name) - - # clear backup files that exceed the file limit - if self.backupCount > 0: - dir_name = os.path.dirname(self.baseFilename) - base_filename = os.path.basename(self.baseFilename) - base, ext = os.path.splitext(base_filename) - - # match all backup files that match the format - pattern = re.compile(rf'^({re.escape(base)}-{LOG_BACKUP_PATTERN}{re.escape(ext)})$') - backups = [] - - for filename in os.listdir(dir_name): - match = pattern.match(filename) - if match: - timestamp_str = match.group(1) - # get timestamp str for sort file - timestamp_str = timestamp_str[len(base) + 1:-len(ext)] - - try: - # resolve timestamps in file names - ts = datetime.datetime.strptime( - timestamp_str, LOG_BACKUP_FORMAT) - backups.append((filename, ts)) - except ValueError: - continue - - # sort by time (old → new) - backups.sort(key=lambda x: x[1]) - - # delete old backups that exceed the reserved quantity - while len(backups) > self.backupCount: - oldest = backups.pop(0) - os.remove(os.path.join(dir_name, oldest[0])) - - # create new log file - if not self.delay: - self.stream = self._open() - - class LogConfig: """ Log Config include logger configuration @@ -207,25 +136,6 @@ def _set_loglevel(logger: logging.Logger, level: int): handler.setLevel(level) -def _set_rotator(logger: logging.Logger, rotate_func: callable): - for handler in logger.handlers: - handler.rotator = rotate_func - - -def _log_rotator(source: str, dest: str) -> None: - try: - if os.path.exists(source): - os.rename(source, dest) - os.chmod(dest, mode=LOG_PRIVILEGE) - if not os.path.exists(source): - os.mknod(source, mode=LOG_PRIVILEGE) - else: - _exit_file_process(source) - except Exception as e: - logging.error('exception occurred while rotating log: %s', str(e)) - return - - def _exit_file_process(log_path: str) -> None: """ Handle log file when file is already existed. @@ -248,7 +158,7 @@ def _get_stream_handler(cfg: LogConfig): def _get_file_handler(cfg: LogConfig): - file_handler = CustomRotatingHandler(cfg.log_file, maxBytes=cfg.log_max_bytes, backupCount=cfg.log_backup_count) + file_handler = logging.FileHandler(cfg.log_file) file_handler.setLevel(cfg.file_log_level) file_handler.setFormatter(logging.Formatter(cfg.log_format, datefmt=LOG_DATE_FORMAT)) return file_handler @@ -268,40 +178,30 @@ def get_logger(sub_module_name: str, log_file_name: str, **kwargs) -> logging.Lo # set log write to file logger.addHandler(_get_file_handler(log_cfg)) - _set_rotator(logger, rotate_func=_log_rotator) _set_formatter(logger, log_cfg.log_format) return logger -class GoLogConfig(object): - _fields_ = [ - ('LogFileName', ctypes.c_char_p), - ('OnlyToStdout', ctypes.c_bool), - ('OnlyToFile', ctypes.c_bool), - ('LogLevel', ctypes.c_int), - ('FileMaxSize', ctypes.c_int), - ('MaxLineLength', ctypes.c_int), - ('MaxBackups', ctypes.c_int), - ('MaxAge', ctypes.c_int), - ('IsCompress', ctypes.c_bool), - ('ExpiredTime', ctypes.c_int), - ('CacheSize', ctypes.c_int) - ] - - def init_go_logger(log_file_name, sub_module_name, **kwargs): lib.InitHwLog.argtypes = [ctypes.c_char_p, ctypes.c_char_p] lib.InitHwLog.restype = ctypes.c_int InitHwLog = cython_api.lib.InitHwLog log_file_name_bytes = log_file_name.encode('utf-8') sub_module_name_bytes = sub_module_name.encode('utf-8') - InitHwLog("worker.log", "worker") + InitHwLog(log_file_name_bytes, sub_module_name_bytes) worker_log = get_logger("worker", log_file_name='worker.log') -init_go_logger(log_file_name="worker.log", sub_module_name="worker") monitor_log = get_logger("monitor", log_file_name='monitor.log') +init_go_logger(log_file_name="worker.log", sub_module_name="worker") +init_go_logger(log_file_name="master.log", sub_module_name="master") if __name__ == "__main__": - worker_log.warning("worker") + monitor_log.info("monitor") + cnt = 0 + while True: + cnt += 1 + worker_log.warning(f"workerworkerworkerworkerworkerworkerworkerworkerworkerworker {cnt}") + if cnt>1000000: + break monitor_log.warning("monitor") -- Gitee From f25b7b2ae570dfb2135120a664c8c90808c5ca45 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Fri, 25 Apr 2025 11:06:40 +0800 Subject: [PATCH 20/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index f3c92e738..a3a3906ec 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -107,7 +107,7 @@ func InitHwLog(logFileName *C.char, moduleName *C.char) C.int { cnt := 1 for { time.Sleep(time.Second) - hwlog.RunLog.Infof("hwlog cnt:%d", cnt) + hwlog.ModuleRunLog[moduleName].Infof("hwlog cnt:%d", cnt) cnt++ } }() -- Gitee From b7578d8cd63986152e74c1a4928c4083bec1d498 Mon Sep 17 00:00:00 2001 From: Lianjun Zhang Atlas Date: Fri, 25 Apr 2025 11:08:24 +0800 Subject: [PATCH 21/21] =?UTF-8?q?taskd=E6=97=A5=E5=BF=97=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/taskd/taskd/go/backend_api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/taskd/taskd/go/backend_api.go b/component/taskd/taskd/go/backend_api.go index a3a3906ec..f6cfb47d9 100644 --- a/component/taskd/taskd/go/backend_api.go +++ b/component/taskd/taskd/go/backend_api.go @@ -107,7 +107,7 @@ func InitHwLog(logFileName *C.char, moduleName *C.char) C.int { cnt := 1 for { time.Sleep(time.Second) - hwlog.ModuleRunLog[moduleName].Infof("hwlog cnt:%d", cnt) + hwlog.ModuleRunLog[goModuleName].Infof("hwlog cnt:%d", cnt) cnt++ } }() -- Gitee