Giter Club home page Giter Club logo

c-log's Introduction

C-LOG

Release Version

What is c-log

a fast ,stable and thread-safe log lib(logger) for C/C++ language

How to Use

you can use "sh build.sh" to build the testing application and also i suggest you to run "./bench_test" (single_thread)to see the performance

you can use this log module by the follow guiding:

    log_init(LL_TRACE, "mysql", "./log/");
	LOG_NOTICE("%s [time:%d]", "test calling log", time(NULL));
	LOG_DEBUG("debug msg,only write to log when the loglevel bigger than or equal to debug [time:%d]", time(NULL));
	LOG_WARN("warnning msg will be writing to the error files [time:%d]", time(NULL));
	LOG_ERROR("you also can change  number of output files by rewrite the macro_define.h");

and also you don't need to call close befor your application exit if you insist to calling close,please use WARN_W.log_close() INFO_W.log_close() and so so.

this module also provide some convenient macro, you can use it in the following scene

    int function()
	{
		int ret;
		if()
		{
			ret = function_call();
			MACRO_RET(ret != 0, -1);
			MACRO_WARN(ret != 0, "function call failed  [ret:%d]", ret);
			MACRO_WARN_RET(ret != 0, -1, "function call failed  [ret:%d]", ret)
			
		}
	}

The performance of this log module is really depend on how fast your disk is. here is test result:

case 1
    Record Size: 280kb
	Cost Time: 42 seconds
	Data File Size: 20GB
	yes. we write 20GB file in 102s,that's means we write 200MB per second.and
	also this is the limitation of SATA.

case 2 
    Record Size: 56byte
	Record Write per Senconds:200,000
	yes,in it's general useage,you can gain high qps from this log module

what will be the next?

About Author

  var 0xmalloc = {
    nickName  : "zealot yin",
    email : '[email protected]',
    site : "http://www.cnblogs.com/Creator/"
    weibo : "http://www.weibo.com/zealotyin"
  }

c-log's People

Contributors

0xmalloc avatar surgeping avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

c-log's Issues

一个bug报告与问一些问题。

大神,你好。
多次init有什么特殊作用吗?一个线程中init,其它线程都可以用了?似乎没有对log文件大小进行限制啊?

bug:
在linux 创建的目录不可写,导致init时的路径有目录就失败。
c文件中25行左右:
原文:if (mkdir (p_logdir, S_IREAD | S_IWRITE ) < 0)
改为:S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH
就可以了。

Is c-log friendly to C?

I have a project written in C, while trying to compile the project mixed with c-log, I got this error:

unknown type name "class"

fwrite() is thread_safe?

Hello,有两个问题想请教一下

  1. 我看到代码中的fwrite()函数调用是没有加锁的,是否意味着fwrite()函数是线程安全的?
  2. 关于代码
 if(0 != access(m_filelocation, W_OK))                                                                                                    
    {                                                                                                                                        
        pthread_mutex_lock(&m_mutex);                                                                                                        
        //锁内校验 access 看是否在等待锁过程中被其他线程loginit了  避免多线程多次close 和init                                                
        if(0 != access(m_filelocation, W_OK))                                                                                                
        {                                                                                                                                    
            logclose();                                                                                                                      
            loginit(m_system_level, m_filelocation, m_isappend, m_issync);                                                                   
        }                                                                                                                                    
        pthread_mutex_unlock(&m_mutex);                                                                                                      
    }              

线程中执行access(m_filelocaltion,W_OK)什么时候会失败呢?貌似主线程已经做了loginit,说明对该文件时有写的权限的,后面执行为什么会失败呢?

如有问的不合理之处,还请见谅,谢谢~

一些改进

我用QT 编译成功,
不过有些问题。

  1. 要把log.c 改为log.cpp,不然QT的编译其报错。
    2.build.sh里 rm少了bench_test

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.