* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
#include <cstdarg>
#include <securec.h>
#include "acl_rt_impl.h"
#include "common/log_inner.h"
namespace {
constexpr const char_t* const TRUNCATED_MARK = "...[truncated]";
constexpr size_t TRUNCATED_MARK_LEN = 14U;
void AppendTruncatedMark(char_t* const buf)
{
(void)strcpy_s(&buf[acl::MAX_LOG_STRING - 1U - TRUNCATED_MARK_LEN], TRUNCATED_MARK_LEN + 1U, TRUNCATED_MARK);
}
}
#ifdef __cplusplus
extern "C" {
#endif
void aclAppLogImpl(
aclLogLevel logLevel, const char* func, const char* file, uint32_t line, const char* fmt, va_list args)
{
if ((fmt == nullptr) || (func == nullptr) || (file == nullptr)) {
return;
}
if (!acl::AclLog::IsLogOutputEnable(logLevel)) {
return;
}
char_t str[acl::MAX_LOG_STRING] = {};
const int32_t bodyRet = vsnprintf_truncated_s(str, static_cast<size_t>(acl::MAX_LOG_STRING), fmt, args);
if (bodyRet == -1) {
acl::AclLog::ACLSaveLog(ACL_ERROR, "aclAppLog format string is invalid");
return;
}
char_t strLog[acl::MAX_LOG_STRING] = {};
const int32_t headRet = snprintf_truncated_s(
strLog, static_cast<size_t>(acl::MAX_LOG_STRING), "%d %s:%s:%u: \"%s\"", acl::AclLog::GetTid(), func, file,
line, str);
if ((bodyRet >= static_cast<int32_t>(acl::MAX_LOG_STRING - 1U)) ||
(headRet >= static_cast<int32_t>(acl::MAX_LOG_STRING - 1U))) {
AppendTruncatedMark(strLog);
}
acl::AclLog::ACLSaveLog(logLevel, strLog);
return;
}
#ifdef __cplusplus
}
#endif