• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2013 Rockchip Electronics Co., LTD.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /*
19  * @file        Rockchip_OSAL_Log.h
20  * @brief
21  * @author      csy(csy@rock-chips.com)
22  * @version     1.0.0
23  * @history
24  *   2013.11.26 : Create
25  */
26 
27 #include "Rockchip_OSAL_Log.h"
28 #include <hdf_log.h>
29 #include <securec.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include "Rockchip_OSAL_Env.h"
34 
35 #include <hdf_log.h>
36 #define MPP_LOG_MAX_LEN 256
_Rockchip_OSAL_Log(ROCKCHIP_LOG_LEVEL logLevel,OMX_U32 flag,const char * tag,const char * msg,...)37 void _Rockchip_OSAL_Log(ROCKCHIP_LOG_LEVEL logLevel, OMX_U32 flag, const char *tag, const char *msg, ...)
38 {
39 #ifdef LOG_FILE
40     static FILE *fp = NULL;
41     if (fp == NULL) {
42         fp = fopen("/data/omx.log", "a");
43         if (fp == NULL) {
44             HDF_LOGE("%{public}s, open file failed", __func__);
45             return;
46         }
47     }
48 
49 #endif
50     va_list ap;
51     va_start(ap, msg);
52     char str[MPP_LOG_MAX_LEN] = {0};
53     if (vsnprintf_s(str, sizeof(str), sizeof(str), msg, ap) <= 0) {
54         HDF_LOGE("%{public}s, vsnprintf ret failed", __func__);
55         va_end(ap);
56         return;
57     }
58     va_end(ap);
59     switch (logLevel) {
60         case ROCKCHIP_LOG_TRACE: {
61 #ifdef LOG_FILE
62             fwrite(str, strlen(str), 1, fp);
63             fflush(fp);
64 #else
65             HDF_LOGD("%{public}s %{public}s", tag, str);
66 #endif
67             break;
68         }
69 
70         case ROCKCHIP_LOG_DEBUG: {
71 #ifdef LOG_FILE
72             fwrite(str, strlen(str), 1, fp);
73             fflush(fp);
74 #else
75             HDF_LOGD("%{public}s %{public}s", tag, str);
76 #endif
77             break;
78         }
79 
80         case ROCKCHIP_LOG_INFO: {
81 #ifdef LOG_FILE
82             fwrite(str, strlen(str), 1, fp);
83             fflush(fp);
84 #else
85             HDF_LOGI("%{public}s %{public}s", tag, str);
86 #endif
87             break;
88         }
89         case ROCKCHIP_LOG_WARNING: {
90 #ifdef LOG_FILE
91             fwrite(str, strlen(str), 1, fp);
92             fflush(fp);
93 #else
94             HDF_LOGW("%{public}s %{public}s", tag, str);
95 #endif
96             break;
97         }
98         case ROCKCHIP_LOG_ERROR: {
99 #ifdef LOG_FILE
100             fwrite(str, strlen(str), 1, fp);
101             fflush(fp);
102 #else
103             HDF_LOGE("%{public}s %{public}s", tag, str);
104 #endif
105             break;
106         }
107         default:
108             break;
109     }
110 }