spice日志提取
来源:互联网 发布:java文本相似度 tfidf 编辑:程序博客网 时间:2024/05/19 12:38
编写其他工程,可以借鉴。
#include <stdarg.h>#include <stdio.h>#include <glib.h>#define spice_info(format, ...) G_STMT_START { \ spice_log(G_LOG_LEVEL_INFO, __FUNCTION__, "" format, ## __VA_ARGS__); \} G_STMT_END#define spice_debug(format, ...) G_STMT_START { \ spice_log(G_LOG_LEVEL_DEBUG, __FUNCTION__, "" format, ## __VA_ARGS__); \} G_STMT_END#define spice_warning(format, ...) G_STMT_START { \ spice_log(G_LOG_LEVEL_WARNING, __FUNCTION__, "" format, ## __VA_ARGS__); \} G_STMT_END#define spice_critical(format, ...) G_STMT_START { \ spice_log(G_LOG_LEVEL_CRITICAL, __FUNCTION__, "" format, ## __VA_ARGS__); \} G_STMT_END#define spice_error(format, ...) G_STMT_START { \ spice_log(G_LOG_LEVEL_ERROR, __FUNCTION__, "" format, ## __VA_ARGS__); \} G_STMT_ENDstatic int glib_debug_level = INT_MAX;static int abort_mask = 0;static void spice_logv(const char *log_domain, GLogLevelFlags log_level, const char *function, const char *format, va_list args){ GString *log_msg; if ((log_level & G_LOG_LEVEL_MASK) > glib_debug_level) { return; // do not print anything } log_msg = g_string_new(NULL); if ( function) { g_string_append_printf(log_msg, "%s: ", function); } if (format) { g_string_append_vprintf(log_msg, format, args); } g_log(log_domain, log_level, "%s", log_msg->str); g_string_free(log_msg, TRUE); /* if ((abort_mask & log_level) != 0) { spice_backtrace(); abort(); } */}void spice_log(GLogLevelFlags log_level, const char *function, const char *format, ...){ va_list args; va_start (args, format); spice_logv (G_LOG_DOMAIN, log_level, function, format, args); va_end (args);}int main(){ spice_info("this is info"); spice_debug("this is debug"); spice_warning("this is warning"); spice_critical("this is critical"); //spice_error("this is error"); return 0;}
编译&运行结果
[root@net test]# gcc log.c -o log -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -lglib-2.0
[root@allinone01 test]# ./log
* (process:15224): WARNING *: main: this is warning
* (process:15224): CRITICAL *: main: this is critical
[root@net test]#
阅读全文
0 0
- spice日志提取
- spice
- powershell提取日志内容
- python提取格式化日志
- nginx日志数据提取
- 日志提取程序
- log4j perl 错误日志提取
- 日志字段提取优化方案
- 使用mysqlbinlog提取二进制日志
- 提取mysql binlog日志内容
- 自动提取Android Crash 日志
- Spice project
- spice vdagent
- spice debug
- SPICE 小计
- SPICE简史
- 用SVNKit提取SVN日志时报错
- Python 定时提取实时日志的程序
- 寻找最长区域
- 计蒜客-灌溉(java-prim算法)
- JavaEE体系结构分为哪几层?
- 深度学习优化器 optimizer 的选择__转自雷锋网
- 2017/12/5工作总结
- spice日志提取
- redis 客户端 jedis的使用
- 安装 onnx_coreml on OSX
- 字符串排序(指针)
- Linux中的常用操作命令
- elasticsearch-java api之搜索(二)——聚合
- eclipse启动卡死的问题
- 最小划分-LintCode
- php 后台返回[ ],使用 Gson解析成 Object 报错的解决