t2ex/t2ex_source/t2ex/network/net/src/netmain/tkn_log.c | bare source | permlink (0.01 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * T2EX Software Package 4: * 5: * Copyright 2012 by Ken Sakamura. 6: * This software is distributed under the latest version of T-License 2.x. 7: *---------------------------------------------------------------------- 8: * 9: * Released by T-Engine Forum(http://www.t-engine.org/) at 2012/12/12. 10: * Modified by T-Engine Forum at 2013/03/08. 11: * Modified by TRON Forum(http://www.tron.org/) at 2015/06/04. 12: * 13: *---------------------------------------------------------------------- 14: */ 15: /* 16: * This software package is available for use, modification, 17: * and redistribution in accordance with the terms of the attached 18: * T-License 2.x. 19: * If you want to redistribute the source code, you need to attach 20: * the T-License 2.x document. 21: * There's no obligation to publish the content, and no obligation 22: * to disclose it to the TRON Forum if you have modified the 23: * software package. 24: * You can also distribute the modified source code. In this case, 25: * please register the modification to T-Kernel traceability service. 26: * People can know the history of modifications by the service, 27: * and can be sure that the version you have inherited some 28: * modification of a particular version or not. 29: * 30: * http://trace.tron.org/tk/?lang=en 31: * http://trace.tron.org/tk/?lang=ja 32: * 33: * As per the provisions of the T-License 2.x, TRON Forum ensures that 34: * the portion of the software that is copyrighted by Ken Sakamura or 35: * the TRON Forum does not infringe the copyrights of a third party. 36: * However, it does not make any warranty other than this. 37: * DISCLAIMER: TRON Forum and Ken Sakamura shall not be held 38: * responsible for any consequences or damages caused directly or 39: * indirectly by the use of this software package. 40: * 41: * The source codes in bsd_source.tar.gz in this software package are 42: * derived from NetBSD or OpenBSD and not covered under T-License 2.x. 43: * They need to be changed or redistributed according to the 44: * representation of each source header. 45: */ 46: 47: /* 48: * @(#)tkn_log.c 49: * 50: */ 51: 52: #include <tk/tkernel.h> 53: #include <tm/tmonitor.h> 54: 55: 56: #include <sys/cdefs.h> 57: #include <sys/types.h> 58: #include <sys/param.h> 59: #include <sys/systm.h> 60: 61: #include <stdarg.h> 62: #include <sys/syslog.h> 63: 64: #if defined(T2EX_LOG) || defined(DEBUG) 65: LOCAL void log_output(const char* format, va_list ap) 66: { 67: static char buf[128]; 68: 69: vsnprintf(buf, sizeof(buf), format, ap); 70: buf[sizeof(buf) - 1] = '\0'; 71: 72: tm_putstring((UB*)buf); 73: } 74: #endif 75: 76: #ifdef T2EX_LOG 77: /* log level */ 78: #ifndef TKN_LOG_LEVEL 79: #define TKN_LOG_LEVEL LOG_WARNING 80: #endif 81: 82: int tkn_log_level = TKN_LOG_LEVEL; 83: 84: /* 85: * message logging - instead of kernel log func. 'log()' 86: */ 87: void 88: log(int level, const char* format, ...) 89: { 90: va_list list; 91: 92: if (level > tkn_log_level) { 93: return; 94: } 95: 96: va_start(list, format); 97: log_output(format, list); 98: va_end(list); 99: } 100: #endif 101: 102: #ifdef DEBUG 103: void tkn_panic(const char* format, ...) 104: { 105: va_list list; 106: 107: tm_putstring((UB*)"panic: "); 108: 109: va_start(list, format); 110: log_output(format, list); 111: va_end(list); 112: 113: tm_putstring((UB*)"\n" ); 114: 115: /* display register */ 116: tm_command((UB*)"R C"); 117: 118: for (;;) tm_monitor(); /* stop the system */ 119: } 120: #endif