Fix directory hierarchy & cmake configuration files
[platform/core/appfw/launchpad.git] / src / launchpad-process-pool / src / launchpad_log.c
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #define _GNU_SOURCE
18 #include <stdarg.h>
19 #include <stdio.h>
20
21 #include "launchpad_log.h"
22 #include "launchpad_logger.h"
23 #include "log_private.h"
24
25 #define PATH_LAUNCHPAD_LOG "/var/log/appfw/launchpad/launchpad.log"
26
27 static logger_h __logger;
28
29 int _log_print(const char *tag, const char *format, ...)
30 {
31         char formatted_buf[LAUNCHPAD_LOG_MAX_STRING_SIZE];
32         va_list ap;
33
34         if (!__logger)
35                 return 0;
36
37         va_start(ap, format);
38         vsnprintf(formatted_buf, sizeof(formatted_buf), format, ap);
39         va_end(ap);
40
41         return _logger_print(__logger, tag, formatted_buf);
42 }
43
44 int _log_init(void)
45 {
46         int ret;
47
48         _W("LOG_INIT");
49
50         ret = _logger_create(PATH_LAUNCHPAD_LOG, &__logger);
51         if (ret != 0) {
52                 _E("Failed to create log file. error(%d)", ret);
53                 return ret;
54         }
55
56         return 0;
57 }
58
59 void _log_fini(void)
60 {
61         _W("LOG_FINI");
62
63         if (__logger)
64                 _logger_destroy(__logger);
65 }