Code Monkey home page Code Monkey logo

easylog's Introduction

Linux下简单的日志库

你可以只需要写两三行代码就完成配置,然后就可以轻快记录日志了。

一个小例子examples/main.c :

#include <stdio.h>
#include "easylog.h"

int main(int argc, char* argv[]) {
    easylog_file("test.log");
    easylog_flag_add(EASYLOG_DATE |
            EASYLOG_TIME |
            EASYLOG_FILE |
            EASYLOG_LINE);
    easylog_flag_add(EASYLOG_FUNC); // 在日志中增加函数名称

    easylog("hello 我的");
    easylog_flag_rm(EASYLOG_DATE);  //在日志中删除日期
    easylog("hello 你的");

    return 0;
}

编译examples 目录中的示例代码 main.c

make -C examples

运行main程序

./examples/main

main 程序会在当前目录下生成 test.log 文件, 查看 test.log 里面的内容:

$ cat test.log
2017-06-10 04:42:42.996 main.c 12 main() -- hello 我的
04:42:42.997 main.c 14 main() -- hello 你的

其中各个选项的作用如下:

  • EASYLOG_DATE : 在日志中添加日期
  • EASYLOG_TIME : 在日志中添加时间
  • EASYLOG_FILE : 在日志中添加本日志语句所在的文件名
  • EASYLOG_LINE : 在日志中添加本日志语句所在的文件中的行
  • EASYLOG_FUNC : 在日志中添加本日志语句所在的函数
  • EASYLOG_FLUSH : 每次记录日志都对文件进行flush操作(会导致性能下降)

easylog's People

Contributors

fengbohello avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.