8ab77c8983bb72a4c6d6855bee2dab4ccda2d3ca
[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 #ifdef BUILD_TYPE_DEBUG
31 int __log_level = LOG_DEBUG;
32 #else
33 int __log_level = LOG_ERR;
34 #endif
35
36 static int strlog2intlog(const char *strlog) {
37     if(!strncmp("LOG_EMERG", strlog, strlen("LOG_EMERG")))
38         return LOG_EMERG;
39     if(!strncmp("LOG_ALERT", strlog, strlen("LOG_ALERT")))
40         return LOG_ALERT;
41     if(!strncmp("LOG_CRIT", strlog, strlen("LOG_CRIT")))
42         return LOG_CRIT;
43     if(!strncmp("LOG_ERR", strlog, strlen("LOG_ERR")))
44         return LOG_ERR;
45     if(!strncmp("LOG_WARNING", strlog, strlen("LOG_WARNING")))
46         return LOG_WARNING;
47     if(!strncmp("LOG_NOTICE", strlog, strlen("LOG_NOTICE")))
48         return LOG_NOTICE;
49     if(!strncmp("LOG_INFO", strlog, strlen("LOG_INFO")))
50         return LOG_INFO;
51     if(!strncmp("LOG_DEBUG", strlog, strlen("LOG_DEBUG")))
52         return LOG_DEBUG;
53
54     return LOG_ERR;
55 }
56
57 void init_log(void) {
58     char *env_val = getenv("CYNARA_LOG_LEVEL");
59     if (env_val) {
60         __log_level = strlog2intlog(env_val);
61     }
62 }