• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "cipher_log.h"
17 
18 #include "securec.h"
19 
20 #include "log.h"
21 
22 
23 #define MAX_LOG_BUFF_LEN 512
24 
CipherLog(uint32_t logLevel,const char * funcName,uint32_t lineNo,const char * format,...)25 void CipherLog(uint32_t logLevel, const char *funcName, uint32_t lineNo, const char *format, ...)
26 {
27     char *buf = (char *)malloc(MAX_LOG_BUFF_LEN);
28     if (buf == NULL) {
29         HILOG_ERROR(HILOG_MODULE_SCY, "Cipher log malloc fail");
30         return;
31     }
32     (void)memset_s(buf, MAX_LOG_BUFF_LEN, 0, MAX_LOG_BUFF_LEN);
33 
34     va_list ap;
35     va_start(ap, format);
36     int32_t ret = vsnprintf_s(buf, MAX_LOG_BUFF_LEN, MAX_LOG_BUFF_LEN - 1, format, ap);
37     va_end(ap);
38     if (ret < 0) {
39         HILOG_ERROR(HILOG_MODULE_SCY, "Cipher log concatenate error.");
40         free(buf);
41         buf = NULL;
42         return;
43     }
44 
45     switch (logLevel) {
46         case CIPHER_LOG_LEVEL_E:
47 #if defined(__LINUX__)
48             HILOG_ERROR(HILOG_MODULE_SCY, "%s[%u]: %s\n", funcName, lineNo, buf);
49 #else
50             HILOG_ERROR(HILOG_MODULE_SCY, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, buf);
51 #endif
52             break;
53         default:
54             free(buf);
55             buf = NULL;
56             return;
57     }
58 
59     free(buf);
60     buf = NULL;
61 }