Base patch (skeleton code)
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-lib / src / zblib_log.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Contact: Suresh Kumar N (suresh.n@samsung.com)
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include <glib.h>
24
25 #include <dlog.h>
26
27 #include <zblib_log.h>
28
29 #define BUFFER_SIZE 1024
30
31 void zblib_log(enum zblib_log_type type, enum zblib_log_priority priority, const char *tag, const char *fmt, ...)
32 {
33         va_list ap;
34         char buf[BUFFER_SIZE];
35         int log_id = LOG_ID_RADIO;
36
37         switch (type) {
38         case ZIGBEE_LOG_TYPE_SYSTEM: {
39                 if (priority >= ZIGBEE_LOG_INFO) {
40                         va_start(ap, fmt);
41                         vsnprintf(buf, BUFFER_SIZE-1, fmt, ap);
42                         va_end(ap);
43                         __dlog_print(log_id, priority, tag, "%s", buf);
44                 } else {
45 #ifdef TIZEN_DEBUG_ENABLE
46                         va_start(ap, fmt);
47                         vsnprintf(buf, BUFFER_SIZE-1, fmt, ap);
48                         va_end(ap);
49                         __dlog_print(log_id, priority, tag, "%s", buf);
50 #endif
51                 }
52         }
53         break;
54
55         case ZIGBEE_LOG_TYPE_TIME_CHECK: {
56 #ifdef TIZEN_DEBUG_ENABLE /* User Mode should not log performance data */
57                 float a = 0.00, b = 0.00;
58                 int next = 0;
59                 FILE *fp = fopen("/proc/uptime", "r");
60                 if (NULL == fp) {
61                         Z_LOGE("fopen() failed");
62                         return;
63                 }
64                 if (fscanf(fp, "%f %f", &a, &b) != 1)
65                         next = snprintf(buf, BUFFER_SIZE, "[UPTIME] [Not Set] ");
66                 else
67                         next = snprintf(buf, BUFFER_SIZE, "[UPTIME] %f ", a);
68                 fclose(fp);
69                 if (next < 0)
70                         return;
71
72                 va_start(ap, fmt);
73                 vsnprintf(buf + next, (BUFFER_SIZE-1) - next, fmt, ap);
74                 va_end(ap);
75                 __dlog_print(log_id, priority, tag, "%s", buf);
76 #endif
77         }
78         break;
79
80         default:
81         break;
82         }
83 }
84