4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 /*TODO: clean up header files*/
23 #include <sys/types.h>
28 #include "sensor_logs.h"
31 #define EXTAPI __attribute__((visibility("default")))
34 #define SF_SERVER_MSG_LOG_FILE "/var/log/messages"
35 #define FILE_LENGTH 255
37 static int sf_debug_file_fd;
38 static char sf_debug_file_buf[FILE_LENGTH];
40 EXTAPI void sf_log(int type , int priority , const char *tag , const char *fmt , ...)
46 case SF_LOG_PRINT_FILE:
47 sf_debug_file_fd = open(SF_SERVER_MSG_LOG_FILE, O_WRONLY|O_CREAT|O_APPEND, 0644);
48 if (sf_debug_file_fd != -1) {
49 vsnprintf(sf_debug_file_buf,255, fmt , ap );
50 int total_bytes_written = 0;
51 while (total_bytes_written < (int) strlen(sf_debug_file_buf)){
52 int bytes_written = write(sf_debug_file_fd, (sf_debug_file_buf + total_bytes_written), strlen(sf_debug_file_buf) - total_bytes_written);
53 if (bytes_written == -1)
55 total_bytes_written = total_bytes_written + bytes_written;
57 close(sf_debug_file_fd);
65 syslog_prio = LOG_ERR|LOG_DAEMON;
68 syslog_prio = LOG_WARNING|LOG_DAEMON;
72 syslog_prio = LOG_DEBUG|LOG_DAEMON;
76 syslog_prio = LOG_INFO|LOG_DAEMON;
80 syslog_prio = priority;
84 vsyslog(syslog_prio, fmt, ap);
91 SLOG_VA(LOG_ERROR, tag ? tag : "NULL" , fmt ? fmt : "NULL" , ap);
95 SLOG_VA(LOG_WARN, tag ? tag : "NULL" , fmt ? fmt : "NULL" , ap);
99 SLOG_VA(LOG_DEBUG, tag ? tag : "NULL", fmt ? fmt : "NULL" , ap);
103 SLOG_VA(LOG_INFO, tag ? tag : "NULL" , fmt ? fmt : "NULL" , ap);