Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2010-2014 Intel Corporation 3 : : */ 4 : : 5 : : #include <stdio.h> 6 : : #include <sys/types.h> 7 : : #include <syslog.h> 8 : : 9 : : #include <rte_log.h> 10 : : 11 : : #include "log_internal.h" 12 : : 13 : : /* 14 : : * default log function 15 : : */ 16 : : static ssize_t 17 : 1918 : console_log_write(__rte_unused void *c, const char *buf, size_t size) 18 : : { 19 : : ssize_t ret; 20 : : 21 : : /* write on stderr */ 22 : 1918 : ret = fwrite(buf, 1, size, stderr); 23 : 1918 : fflush(stderr); 24 : : 25 : : /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ 26 : 1918 : syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); 27 : : 28 : 1918 : return ret; 29 : : } 30 : : 31 : : static int 32 : 167 : console_log_close(__rte_unused void *c) 33 : : { 34 : 167 : closelog(); 35 : 167 : return 0; 36 : : } 37 : : 38 : : static cookie_io_functions_t console_log_func = { 39 : : .write = console_log_write, 40 : : .close = console_log_close, 41 : : }; 42 : : 43 : : /* 44 : : * set the log to default function, called during eal init process, 45 : : * once memzones are available. 46 : : */ 47 : : int 48 : 167 : eal_log_init(const char *id, int facility) 49 : : { 50 : : FILE *log_stream; 51 : : 52 : 167 : log_stream = fopencookie(NULL, "w+", console_log_func); 53 [ + - ]: 167 : if (log_stream == NULL) 54 : : return -1; 55 : : 56 : 167 : openlog(id, LOG_NDELAY | LOG_PID, facility); 57 : : 58 : 167 : eal_log_set_default(log_stream); 59 : : 60 : 167 : return 0; 61 : : }