奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

C語言

c語言中log的用法指導

時間:2024-10-23 04:12:25 C語言 我要投稿
  • 相關推薦

c語言中log的用法指導

  C語言是一門實踐性和動手能力要求很高的大學主干課程,但是C語言實驗課的教學一直不受重視,教學效果也不太理想。下面小編就跟你們詳細介紹下c語言中log的用法的用法,希望對你們有用。

  c語言中log的用法指導 1

  Log4c中有三個重要的概念, Category, Appender, Layout。

  Category用于區分不同的Logger, 其實它就是個logger。在一個程序中我們可以通過Category來指定很多的Logger,用于不同的目的。

  Appdender用于描述輸出流,通過為Category來指定一個Appdender,可以決定將log信息來輸出到什么地方去,比如stdout, stderr, 文件, 或者是socket等等

  Layout用于指定日志信息的格式,通過為Appender來指定一個Layout,可以決定log信息以何種格式來輸出,比如是否有帶有時間戳, 是否包含文件位置信息等,以及他們在一條log信息中的輸出格式的等。

  例子:

  系統:ubuntu12.10 .

  準備:

  安裝log4c庫, sudo apt-get install liblog4c-dev liblog4c-doc

  別的系統請百度/GOOGLE找相關編譯安裝當。

  文件:

  log.h log.c 自己將log4c重新封裝的函數

  test-log.c 測試用的主函數

  log4crc 配置文件(xml,照著寫就行)

  //log.h

  [cpp] view plain copy

  01.#ifndef _LOG_H_

  02.#define _LOG_H_

  03.

  04.#include

  05.#include

  06.

  07.#ifdef __cplusplus

  08.extern "C"

  09.{

  10.#endif

  11.

  12.#include "log4c.h"

  13.

  14.#ifdef __cplusplus

  15.}

  16.#endif

  17.

  18.#define LOG_PRI_ERROR LOG4C_PRIORITY_ERROR

  19.#define LOG_PRI_WARN LOG4C_PRIORITY_WARN

  20.#define LOG_PRI_NOTICE LOG4C_PRIORITY_NOTICE

  21.#define LOG_PRI_DEBUG LOG4C_PRIORITY_DEBUG

  22.#define LOG_PRI_TRACE LOG4C_PRIORITY_TRACE

  23.

  24.extern int log_open(const char *category);

  25.extern void log_message(int priority ,const char* fmt, ...);

  26.extern void log_trace(const char *file , int line , const char *func, const char *fmt ,...);

  27.extern int log_close();

  28.

  29.#define LOG_ERROR(fmt , args...)

  30. log_message(LOG_PRI_ERROR, fmt, ##args)

  31.#define LOG_WARN(fmt, args...)

  32. log_message(LOG_PRI_WARN, fmt , ##args)

  33.#define LOG_NOTICE(fmt , args...)

  34. log_message(LOG_PRI_NOTICE, fmt , ##args)

  35.#define LOG_DEBUG(fmt , args...)

  36. log_message(LOG_PRI_DEBUG, fmt , ##args)

  37.#define LOG_TRACE(fmt,args...)

  38. log_trace(__FILE__ , __LINE__ , __FUNCTION__ , fmt ,## args)

  39.

  40.

  41.#endif

  //log.c

  [cpp] view plain copy 在CODE上查看代碼片派生到我的'代碼片

  01.#include

  02.#include

  03.#include "log.h"

  04.

  05.

  06.static log4c_category_t *log_category = NULL;

  07.

  08.int log_open(const char *category)

  09.{

  10. if (log4c_init() == 1)

  11. {

  12. return -1;

  13. }

  14. log_category = log4c_category_get(category);

  15. return 0 ;

  16.}

  17.

  18.void log_message(int priority , const char *fmt , ...)

  19.{

  20. va_list ap;

  21.

  22. assert(log_category != NULL);

  23.

  24. va_start(ap, fmt);

  25. log4c_category_vlog(log_category , priority , fmt , ap);

  26. va_end(ap);

  27.}

  28.

  29.void log_trace(const char *file, int line, const char *fun,

  30. const char *fmt , ...)

  31.{

  32. char new_fmt[2048];

  33. const char *head_fmt = "[file:%s, line:%d, function:%s]";

  34. va_list ap;

  35. int n;

  36.

  37. assert(log_category != NULL);

  38. n = sprintf(new_fmt, head_fmt , file , line , fun);

  39. strcat(new_fmt + n , fmt);

  40.

  41. va_start(ap , fmt);

  42. log4c_category_vlog(log_category , LOG4C_PRIORITY_TRACE, new_fmt , ap);

  43. va_end(ap);

  44.}

  45.

  46.

  47.int log_close()

  48.{

  49. return (log4c_fini());

  50.}

  //test-log.c

  [cpp] view plain copy 在CODE上查看代碼片派生到我的代碼片

  01.#include

  02.#include "log.h"

  03.

  04.int main(void)

  05.{

  06. log_open("mycat");

  07. LOG_TRACE("trace");

  08. LOG_ERROR("error");

  09. LOG_WARN("warn");

  10. LOG_NOTICE("notice");

  11. LOG_DEBUG("hello log4c!");

  12. log_close();

  13. return 0;

  14.}

  //配置文件,默認名為log4crc

  [html] view plain copy 在CODE上查看代碼片派生到我的代碼片

  01.

  02.

  03.

  04.

  05.

  06.

  07.0

  08.

  09.0

  10.1

  11.

  12.

  13.

  14.

  15.

  16.

  17.

  18.

  19.

  20.

  21.

  22.

  23.

  24.

  25.

  26.

  編譯命令:

  [python] view plain copy 在CODE上查看代碼片派生到我的代碼片

  01.gcc test-log.c log.c -o test-log -llog4c

  運行效果

  ./test-log

  [stdout] TRACE mycat - [file:test-log.c, line:7, function:main]trace

  [stdout] ERROR mycat - error

  [stdout] WARN mycat - warn

  [stdout] NOTICE mycat - notice

  [stdout] DEBUG mycat - hello log4c!

  講解:

  關于log.h ,log.c封裝的內容大家可以看看,用到了可變參數宏,可變參數這些。百度一下,就有很多人講解了。這里就不說了。

  log.h與log.c里面用法也很簡單

  log_open("category_name"); //category_name一定得是log4crc里面已經定義的category.

  關于配置文件log4crc

  配置文件的搜索是由LOG4C_RCPATH環境變量決定。搜索的配置文件名為log4crc(不知道能否改變,沒研究過)

  配置文件中category的priority不知道是什么意思,反正好像沒什么用。不管設置成什么,好像都不影響。

  環境變量:

  ?LOG4C_RCPATH holds the path to the main log4crc configuration file #環境變量若未設置,則在工作目錄(一般為運行目錄)搜索log4crc配置文件. 如果設置了此變量,則所以用log4c庫的程序都會使用此路徑下的log4c配置文件(可根據category區分).

  ?LOG4C_PRIORITY holds the "root" category priority #改變root的priority,,

  ?LOG4C_APPENDER holds the "root" category appender #改變root的appender,,因為root默認沒設置appender.

  c語言中log的用法指導 2

  1、C語言中,有兩個log函數,分別為log10和log函數,具體用法如下:

  2、函數名: log10

  功 能: 對數函數log,以10為底

  用 法: double log10(double x);

  程序示例:

  #include <math.h>

  #include <stdio.h>int main(void)

  {

  double result;

  double x = 800.6872;

  result = log10(x);

  printf("The common log of %lf is %lf ", x, result);

  return 0;

  }

  3、函數名: log

  功 能: 對數函數log,以e(2.71828)為底

  用 法: double log(double x);

  程序示例:

  #include <math.h>

  #include <stdio.h>int main(void)

  {

  double result;

  double x = 800.6872;

  result = log(x);

  printf("The common log of %lf is %lf ", x, result);

  return 0;

  }

【c語言中log的用法指導】相關文章:

C語言中strpbr()函數的用法07-25

c語言中time函數的用法08-27

c語言位運算符的用法指導06-02

C語言中volatile的含義08-14

C 語言中宏的使用08-02

C語言中的鏈接編寫05-26

html語言中URL的用法06-20

php語言中session用法07-02

C語言中指針的概念03-16

c語言中邏輯或怎么用07-05

主站蜘蛛池模板: 无为县| 海门市| 胶州市| 定结县| 海伦市| 柳河县| 汉川市| 凤冈县| 明水县| 墨玉县| 金秀| 济源市| 台州市| 蒙城县| 绥中县| 公主岭市| 绥滨县| 小金县| 大新县| 旺苍县| 留坝县| 黄骅市| 大田县| 故城县| 望谟县| 北安市| 弥渡县| 从化市| 长兴县| 抚宁县| 庆阳市| 叶城县| 达州市| 上饶县| 南陵县| 博湖县| 太康县| 如东县| 新龙县| 通辽市| 仪陇县|