Fix build with CYNARA_NO_LOGS
[platform/core/security/cynara.git] / src / common / log / log.cpp
1 /*
2  * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Lukasz Wojciechowski <l.wojciechow@partner.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  * @file        src/common/log/log.cpp
20  * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
21  * @version     1.0
22  * @brief       Simple file containing definition of logging level variable.
23  */
24
25 #include "log.h"
26
27 #include <cstring>
28 #include <stdlib.h>
29
30 #ifndef CYNARA_NO_LOGS
31 #ifdef BUILD_TYPE_DEBUG
32 int __log_level = LOG_DEBUG;
33 #else
34 int __log_level = LOG_ERR;
35 #endif
36
37 static int strlog2intlog(const char *strlog) {
38     if(!strncmp("LOG_EMERG", strlog, strlen("LOG_EMERG")))
39         return LOG_EMERG;
40     if(!strncmp("LOG_ALERT", strlog, strlen("LOG_ALERT")))
41         return LOG_ALERT;
42     if(!strncmp("LOG_CRIT", strlog, strlen("LOG_CRIT")))
43         return LOG_CRIT;
44     if(!strncmp("LOG_ERR", strlog, strlen("LOG_ERR")))
45         return LOG_ERR;
46     if(!strncmp("LOG_WARNING", strlog, strlen("LOG_WARNING")))
47         return LOG_WARNING;
48     if(!strncmp("LOG_NOTICE", strlog, strlen("LOG_NOTICE")))
49         return LOG_NOTICE;
50     if(!strncmp("LOG_INFO", strlog, strlen("LOG_INFO")))
51         return LOG_INFO;
52     if(!strncmp("LOG_DEBUG", strlog, strlen("LOG_DEBUG")))
53         return LOG_DEBUG;
54
55     return LOG_ERR;
56 }
57
58 void init_log(void) {
59     char *env_val = getenv("CYNARA_LOG_LEVEL");
60     if (env_val) {
61         __log_level = strlog2intlog(env_val);
62     }
63 }
64
65 #else
66
67 void init_log(void) {}
68
69 #endif //CYNARA_NO_LOGS