Niaj hnub no, feem ntau cov ntawv thov thiab cov ntawv thov ua ntu zus khaws cov ntaub ntawv hais txog cov txheej txheem ntawm lawv cov haujlwm, ua yuam kev thiab ua tsis tiav hauv cov cav tshwj xeeb hu ua lub cav. Feem ntau ntawm cov laj thawj cov kev khiav hauj lwm muaj kev pabcuam uas tso cai rau koj sau cov cav siv tus txheej txheem sau ua ke.
Tsim nyog
- - C kev sau;
- - Windows Platform SDK;
- - Tsim pob rau glibc.
Cov Lus Qhia
Kauj ruam 1
Ntxiv kev txhawb nqa rau kev sau cav mus rau lub cav system los ntawm koj daim ntawv thov tsim los ua haujlwm hauv cov haujlwm ntawm Windows Windows.
Siv RegisterEventSource API ua haujlwm los sau npe rau daim ntawv thov ua qhov xwm txheej tshwm sim, ReportEvent muaj nuj nqi ntxiv rau kev nkag mus rau lub cav, thiab DeregisterEventSource muaj nuj nqi los kaw qhov kov rov qab los ntawm RegisterEventSource.
Nws ua rau kev nkag siab hu rau RegisterEventSource thaum lub sijhawm pib ua daim ntawv thov thiab khaws cia cov khoom xa rov qab txhua lub sijhawm, yog li ntawd cov lus nkag hauv lub cav tuaj yeem tso los ntawm qhov chaw sib txawv hauv qhov program. Qhov piv txwv yooj yim tshaj plaws ntawm kev sau ntawv rau lub cav Windows yuav zoo li no:
TES hLog = RegisterEventSource (NULL, "MyApplicationName");
yog (hLog! = NULL)
{
yog (ReportEvent (hLog, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, "Xov xov / 0", NULL))
{
/ / tau ua tiav log
}
DeregisterEventSource (hLog);
}
Muaj cov ntsiab lus ntxaws ntxiv ntawm cov ntsiab lus tseem ceeb ntawm Cov Haujlwm Ceeb Toom muaj nyob rau hauv MSDN ntawm https://msdn.microsoft.com/en-us/library/windows/desktop/aa363679%28v=vs.85%29.aspx. Ib qho ntxiv, koj yuav tsum tso qee cov ntaub ntawv hais txog daim ntawv thov qhov ua tiav ntawm cov txheej txheem nyob rau hauv qhov system sau npe, thiab ntxiv cov kev pab hauv hom ntawv tshwj xeeb rau tus qauv nws tus kheej lossis lub tsev qiv ntawv thib peb. Yog xav paub ntxiv txog kev sau npe yuam sij rau cov kev pabcuam log kev tshwm sim, saib
Kauj ruam 2
Logging nyob rau hauv Linux-tshaj operating system feem ntau yuav ua tau siv cov syslog daemon. Qhov kev pabcuam no muaj daim ntawv thov-qib interface hauv daim ntawv ntawm kev teeb tsa ua haujlwm, tshaj tawm ntawm cov uas tau muab tso rau hauv syslog.h header file.
Siv cov openlog muaj nuj nqi los tsim cov kev sib txuas rau cov kev pabcuam syslog los ntawm kev thov lossis tsev qiv ntawv. Hu rau syslog lossis vsyslog zog kom muab cov lus hauv lub cav. Tom qab cov ntaub ntawv kaw tseg kawg lossis thaum cov ntawv thov tawm, kaw txoj kev sib txuas mus rau cov kev pabcuam los ntawm hu rau qhov chaw kaw haujlwm. Tsis tas li ntawd, koj tuaj yeem tsim kho lub chaw mus rau tsis quav ntsej hu uas ntxiv cov ntaub ntawv kev tshwm sim nrog qhov tseem ceeb tshwj xeeb uas siv setlogmask muaj nuj nqi. Ib qho piv txwv ntawm kev sau cov lus rau lub cav yuav zoo li qhov no:
openlog ("MyApplication", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
syslog (LOG_NOTICE, "MyApplication yog pib nrog PID% d", getuid ());
syslog (LOG_INFO, "Cov ntaub ntawv xov!");
closelog ();
Yog xav paub ntau ntxiv ntawm cov kev txwv ntawm syslog API ua haujlwm, saib cov ntaub ntawv ntawm libc.
Kauj ruam 3
Sau cov cav rau cov ntaub ntawv tsis txaus siab siv koj tus kheej siv ntawm qhov kev tshwm sim ncua kev cai. Ib qho ntawm cov kev daws teeb meem yooj yim ntawm qhov teeb meem no yog los tsim ntau txoj haujlwm hauv ntiaj teb, ib qho yuav qhib cov ntaub ntawv nrog lub npe tshwj xeeb ntawm hom ntxiv cov ntaub ntawv, qhov thib ob kaw nws, thiab qhov thib peb ntxiv cov xov kab tau hla mus rau nws li parameter rau cov ntaub ntawv no. Conceptually, cov tshuaj no zoo ib yam li syslog programming interface hauv Linux.
Siv lub fopen thiab fclose lub luag haujlwm ntawm C tus qauv tsev qiv ntawv qhib thiab kaw ib cov ntaub ntawv, feem. Hu rau fwrite ntxiv cov ntaub ntawv rau daim ntawv. Koj tseem tuaj yeem siv platform-cov haujlwm tshwj xeeb (piv txwv li CreateFile hauv Windows) thiab cov hau kev ntawm cov khoom ntawm cov qauv siv uas encapsulate cov haujlwm ua haujlwm nrog cov ntaub ntawv.