aix中错误日志编程

本文介绍了一种在AIX操作系统中使用C语言查询错误日志的方法。通过具体实例展示了如何设置时间范围、错误类型等筛选条件,并给出了关键API如errlog_open、errlog_find_first等的使用方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

aix中错误:常由命令errpt获得:

常用:errlog_open,errlog_close, errlog_find_first, errlog_find_next, errlog_find_sequence, errlog_write, and errlog subroutines 获得:

实现例子如下:

#include <stdio.h>
#include <fcntl.h>
#include <sys/errlog.h>

int mode=0;
unsigned int magic;

errlog_handle_t errlog_va;
errlog_handle_t *hdl=&errlog_va;

int begintime=0710000007,endtime=0727000007;

/*MMDDHHMMYY (month, day, hour, minute, and year).*/

main()
{

magic=LE_MAGIC;
int rc;
rc=errlog_open(NULL,mode,magic,hdl);
if (rc==0)
{
printf("/nopen errlog sucessful!/n";
}
else
{
printf("/nopen errlog failed!/n";
}




extern int begintime, endtime;


errlog_match_t beginstamp, endstamp, andstamp;

errlog_match_t hardclass, softclass, orclass;

errlog_match_t andtop;
errlog_match_t *p=&andtop;

int ret;

errlog_entry_t result;


/* * Select begin and end times */

beginstamp.em_op = LE_OP_GT; /* Expression ¡¯A¡¯ */
beginstamp.em_field = LE_MATCH_TIMESTAMP;
beginstamp.em_intvalue=begintime;
endstamp.em_op = LE_OP_LT; /* Expression ¡¯B¡¯ */
endstamp.em_field = LE_MATCH_TIMESTAMP;
endstamp.em_intvalue=endtime;
andstamp.em_op = LE_OP_AND; /* ¡¯A¡¯ and ¡¯B¡¯ */
andstamp.em_left = &beginstamp;
andstamp.em_right = &endstamp; /* * Select the classes we¡¯re interested in. */
hardclass.em_op = LE_OP_EQUAL; /* Expression ¡¯C¡¯ */
hardclass.em_field = LE_MATCH_CLASS;
hardclass.em_strvalue = "H";
softclass.em_op = LE_OP_EQUAL; /* Expression ¡¯D¡¯ */
softclass.em_field = LE_MATCH_CLASS;
softclass.em_strvalue = "S";
orclass.em_op = LE_OP_OR; /* ¡¯C¡¯ or ¡¯D¡¯ */


orclass.em_left = &hardclass;
orclass.em_right = &softclass;
andtop.em_op = LE_OP_AND; /* (¡¯A¡¯ and ¡¯B¡¯ and (¡¯C¡¯ or ¡¯D¡¯ */
andtop.em_left = &andstamp;
andtop.em_right = &orclass;

int direction=LE_REVERSE;
rc=errlog_set_direction(hdl, direction);
if (rc==0)
{
printf("/ndirection errlog sucessful!/n";
}
else
{
printf("/ndirection errlog failed!/n";
}

ret = errlog_find_first(hdl,&andtop,&result);


if (ret==0)
{
printf("/nfind errlog sucessful!/n";
}
else
{
printf("/nfind errlog failed!/n";
}



if (LE_ERR_INVARG == ret)
printf("/n/n return LE_ERR_INVARG /n";

if (LE_ERR_NOMEM == ret)
printf("/n/n return LE_ERR_NOMEM /n";
if (LE_ERR_IO == ret)
printf("/n/n return LE_ERR_IO /n");
if (LE_ERR_DONE == ret)
printf("/n/n return LE_ERR_INVFILE /n");

}

 

链接程序时请使用 liberrlog.a 库


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值