Files
distributedhardware_distrib…/utils/src/dinput_log.cpp
T
xxxx faed0d55dd Description:modify log title
Match-id-7cf4f9e93b57a81fcfcd677467e8bd2b78c551cc
2022-12-14 15:12:26 +08:00

88 lines
2.3 KiB
C++

/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed 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.
*/
#include "dinput_log.h"
#include "constants_dinput.h"
#include "securec.h"
#ifdef HI_LOG_ENABLE
#include "hilog/log.h"
#else
#include <cstdio>
#endif
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
static void DHLogOut(DHLogLevel logLevel, const char *logBuf)
{
#ifdef HI_LOG_ENABLE
LogLevel hiLogLevel = LOG_INFO;
switch (logLevel) {
case DH_LOG_DEBUG:
hiLogLevel = LOG_DEBUG;
break;
case DH_LOG_INFO:
hiLogLevel = LOG_INFO;
break;
case DH_LOG_WARN:
hiLogLevel = LOG_WARN;
break;
case DH_LOG_ERROR:
hiLogLevel = LOG_ERROR;
break;
default:
break;
}
(void)HiLogPrint(LOG_CORE, hiLogLevel, LOG_DOMAIN, DINPUT_LOG_TITLE_TAG.c_str(), "%{public}s", logBuf);
#else
switch (logLevel) {
case DH_LOG_DEBUG:
printf("[D]%s\n", logBuf);
break;
case DH_LOG_INFO:
printf("[I]%s\n", logBuf);
break;
case DH_LOG_WARN:
printf("[W]%s\n", logBuf);
break;
case DH_LOG_ERROR:
printf("[E]%s\n", logBuf);
break;
default:
break;
}
#endif
}
void DHLog(DHLogLevel logLevel, const char *fmt, ...)
{
char logBuf[LOG_MAX_LEN] = {0};
va_list arg;
va_start(arg, fmt);
int32_t ret = vsprintf_s(logBuf, sizeof(logBuf), fmt, arg);
va_end(arg);
if (ret < 0) {
DHLogOut(logLevel, "DH log length error.");
return;
}
DHLogOut(logLevel, logBuf);
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS