Giter Site home page Giter Site logo

log4z's Introduction

Welcome to the log4z wiki!

Introduction:

Build Status

Log4z is an open source C++ lightweight & cross platform log library.   
It provides in a C++ application log and trace debug function for 7*24h service program.  
Support 64/32 of windows/linux/mac/android/iOS.   
Log4z是一款开源的轻量级高性能的跨平台日志库 主要针对7*24小时服务器程序的日志输出与跟踪调试,   
支持64/32位的windows/linux/mac/android/iOS等操作系统.  

note!!

log4z has next iteration fnlog: https://github.com/zsummer/fn-log . used c++11. It's more beautiful than log4z.

Feature:

1. MIT open source license,very liberal.  
   MIT开源授权 授权的限制非常小.  
2. Cross Platform Linux & Windows & mac, Lightweight  only one cpp sourse file one header file.  
   跨平台支持linux & windows & mac, 轻量级 只有一个头文件和一个cpp文件.  
3. 不需要关心创建和销毁等问题 全部自动化.  
4. Multi-Logger Output, Rolling File, Priority Filter, Thread Safe.  
   支持多日志分流,滚动日志记录, 优先级过滤, 多线程安全.
5. Screen Display Log with Different Color.  
   屏显日志彩色输出.  
6. Support format-style and stream-style write log.  
   支持格式化形式和流形式输入日志.    
7. Support configure from file and hot update, or can direct fast work without any config.  
   可通过配置文件配置并进行配置热更新,也可以不做任何配置直接快速使用.   
8. High-performance, 800k lines/sec complex log input/output, 2M lines/sec single string input/output.  
   非常高的吞吐和序列化性能, 针对单线程和多线程下的指令级调优. 80万/sec的复杂类型的日志写入速度,和200万/sec的单一字符串写入速度.    

File Name Format:

LogName_YearMonthDayHourMinute_ProcessID_BlockNumber.log
日志名_年月日时分_进程ID_文件滚动分块编号.log

E:\GITHUB\LOG4Z\PROJECT\BIN  
│──advanced_test.exe  
│──config.cfg  
│──fast_test.exe  
│──stress_test.exe  
│  
├─log  
│──│──advanced_test_2013100921_003852_000.log  
│──│──advanced_test_2013101313_005920_000.log    
│──│──fast_test_2013100921_003855_000.log  
│──│  
│──└─2013_10  
│─────│────Dynamic_2013100921_003852_000.log  
│  
└─Stress  
───│────NetWork_2013101313_007196_000.log  
───│────NetWork_2013101313_007196_001.log  
───│────NetWork_2013101313_007196_002.log  

日志内容[Log Content]

fast_output_linux.png
fast_output_windows.png

2015-12-15 14:36:43.453 LOG_ALARM -----------------  log4z thread started!   ----------------------------
2015-12-15 14:36:43.453 LOG_ALARM logger id=0 key=Main name=a.out path=./log/ level=1 display=1
2015-12-15 14:36:43.503 LOG_DEBUG stream input *** LOGD LOGD LOGD LOGD ***  (main.cpp):10
2015-12-15 14:36:43.503 LOG_INFO  stream input *** LOGI LOGI LOGI LOGI ***  (main.cpp):11
2015-12-15 14:36:43.503 LOG_WARN  stream input *** LOGW LOGW LOGW LOGW ***  (main.cpp):12
2015-12-15 14:36:43.503 LOG_ERROR stream input *** LOGE LOGE LOGE LOGE ***  (main.cpp):13
2015-12-15 14:36:43.503 LOG_ALARM stream input *** LOGA LOGA LOGA LOGA ***  (main.cpp):14
2015-12-15 14:36:43.503 LOG_FATAL stream input *** LOGF LOGF LOGF LOGF ***  (main.cpp):15
2015-12-15 14:36:43.503 LOG_DEBUG format input *** LOGFMTD *** 123456 *** (main.cpp):20
2015-12-15 14:36:43.503 LOG_INFO  format input *** LOGFMTI *** 123456 *** (main.cpp):21
2015-12-15 14:36:43.503 LOG_WARN  format input *** LOGFMTW *** 123456 *** (main.cpp):22
2015-12-15 14:36:43.503 LOG_ERROR format input *** LOGFMTE *** 123456 *** (main.cpp):23
2015-12-15 14:36:43.503 LOG_ALARM format input *** LOGFMTA *** 123456 *** (main.cpp):24
2015-12-15 14:36:43.503 LOG_FATAL format input *** LOGFMTF *** 123456 *** (main.cpp):25
2015-12-15 14:36:43.503 LOG_ALARM main quit ... (main.cpp):27

Example

  #include "log4z.h"  
  using namespace zsummer::log4z;  
  int main(int argc, char *argv[])  
  {  
      //start log4z  
      ILog4zManager::getRef().start();  
      
      //begin test stream log input....  
      LOGT("stream input *** " << "LOGT LOGT LOGT LOGT" << " *** ");  
      LOGD("stream input *** " << "LOGD LOGD LOGD LOGD" << " *** ");  
      LOGI("stream input *** " << "LOGI LOGI LOGI LOGI" << " *** ");  
      LOGW("stream input *** " << "LOGW LOGW LOGW LOGW" << " *** ");  
      LOGE("stream input *** " << "LOGE LOGE LOGE LOGE" << " *** ");  
      LOGA("stream input *** " << "LOGA LOGA LOGA LOGA" << " *** ");  
      LOGF("stream input *** " << "LOGF LOGF LOGF LOGF" << " *** ");  
  
      // cannot support VC6 or VS2003  
      //begin test format log input....  
      LOGFMTT("format input *** %s *** %d ***", "LOGFMTT", 123456);  
      LOGFMTD("format input *** %s *** %d ***", "LOGFMTD", 123456);  
      LOGFMTI("format input *** %s *** %d ***", "LOGFMTI", 123456);  
      LOGFMTW("format input *** %s *** %d ***", "LOGFMTW", 123456);  
      LOGFMTE("format input *** %s *** %d ***", "LOGFMTE", 123456);  
      LOGFMTA("format input *** %s *** %d ***", "LOGFMTA", 123456);  
      LOGFMTF("format input *** %s *** %d ***", "LOGFMTF", 123456);  
  
      LOGA("main quit ...");  
      return 0;  
  }  

How to compile

Directly Using The Way 直接使用:

Add files log4z.cpp log4z.h and compile together in the existing projects
把文件 log4z.cpp log4z.h添加到已有项目中并一起编译.

Make Library To Use

In Windows:

Open and compile log4z/vc2005/log4z.vcproj

In Linux :

cd log4z/g++   
cmake .   
make   

#About The Author
Author: YaweiZhang
Mail: [email protected]
GitHub: https://github.com/zsummer/log4z

log4z's People

Contributors

asummersday avatar coofly avatar debrouxl avatar franramirez688 avatar n506 avatar starwing avatar zsummer 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

log4z's Issues

async behavior of setLoggerLevel

hello
i consider this behavior as a bug

f.e.
LOG_INFO(id, "info1");
ILog4zManager::getPtr()->setLoggerLevel(id, LOG_LEVEL_TRACE);
LOG_TRACE(id, "trace");
LOG_INFO(id, "info2");

will result in
info1
info2

trace message are lost
if we add some sleep after setLoggerLevel - ok , message is displayed

behavior is active with LOG4Z_ALL_SYNCHRONOUS_OUTPUT = false
with LOG4Z_ALL_SYNCHRONOUS_OUTPUT = true - all goes as it should

'isnan' was not declared in this scope if (isnan(t)) ;这样的问题怎么解决?

H:\vcpkg\downloads\log4z-master\g++>cmake -Dlog4z_SOURCE_DIR=".." -G "MinGW Makefiles"
CMake Error: Error: generator : MinGW Makefiles
Does not match the generator used previously: Visual Studio 15 2017
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

H:\vcpkg\downloads\log4z-master\g++>cmake -Dlog4z_SOURCE_DIR=".." -G "MinGW Makefiles"
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/Qt/Qt5.9.2/Tools/mingw530_32/bin/gcc.exe
-- Check for working C compiler: C:/Qt/Qt5.9.2/Tools/mingw530_32/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Qt/Qt5.9.2/Tools/mingw530_32/bin/g++.exe
-- Check for working CXX compiler: C:/Qt/Qt5.9.2/Tools/mingw530_32/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: H:/vcpkg/downloads/log4z-master/g++

H:\vcpkg\downloads\log4z-master\g++>mingw32-make
Scanning dependencies of target log4z
[ 50%] Building CXX object CMakeFiles/log4z.dir/H_/vcpkg/downloads/log4z-master/log4z.cpp.obj
In file included from H:\vcpkg\downloads\log4z-master\log4z.cpp:37:0:
H:\vcpkg\downloads\log4z-master\log4z.h: In member function 'zsummer::log4z::Log4zStream& zsummer::log4z::Log4zStream::writeDouble(double, bool)':
H:\vcpkg\downloads\log4z-master\log4z.h:810:16: error: 'isnan' was not declared in this scope
if (isnan(t))
^
H:\vcpkg\downloads\log4z-master\log4z.h:810:16: note: suggested alternative:
In file included from H:\vcpkg\downloads\log4z-master\log4z.h:193:0,
from H:\vcpkg\downloads\log4z-master\log4z.cpp:37:
C:/Qt/Qt5.9.2/Tools/mingw530_32/i686-w64-mingw32/include/c++/cmath:862:5: note: 'std::isnan'
isnan(_Tp __f)
^
In file included from H:\vcpkg\downloads\log4z-master\log4z.cpp:37:0:
H:\vcpkg\downloads\log4z-master\log4z.h:815:21: error: 'isinf' was not declared in this scope
else if (isinf(t))
^
H:\vcpkg\downloads\log4z-master\log4z.h:815:21: note: suggested alternative:
In file included from H:\vcpkg\downloads\log4z-master\log4z.h:193:0,
from H:\vcpkg\downloads\log4z-master\log4z.cpp:37:
C:/Qt/Qt5.9.2/Tools/mingw530_32/i686-w64-mingw32/include/c++/cmath:853:5: note: 'std::isinf'
isinf(_Tp __f)
^
H:\vcpkg\downloads\log4z-master\log4z.cpp: In member function 'virtual zsummer::log4z::LogData* zsummer::log4z::LogerManager::makeLogData(LoggerId, int)':
H:\vcpkg\downloads\log4z-master\log4z.cpp:1262:38: warning: 'thread' attribute directive ignored [-Wattributes]
static __declspec(thread) tm g_tt = { 0 };
^
H:\vcpkg\downloads\log4z-master\log4z.cpp:1263:42: warning: 'thread' attribute directive ignored [-Wattributes]
static declspec(thread) time_t g_curDayTime = 0 ;
^
CMakeFiles\log4z.dir\build.make:61: recipe for target 'CMakeFiles/log4z.dir/H
/vcpkg/downloads/log4z-master/log4z.cpp.obj' failed
mingw32-make[2]: *** [CMakeFiles/log4z.dir/H
/vcpkg/downloads/log4z-master/log4z.cpp.obj] Error 1
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/log4z.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/log4z.dir/all] Error 2
Makefile:128: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

H:\vcpkg\downloads\log4z-master\g++>g++
g++: fatal error: no input files
compilation terminated.

H:\vcpkg\downloads\log4z-master\g++>mingw32-make -version
GNU Make 4.1
Built for i686-w64-mingw32
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

H:\vcpkg\downloads\log4z-master\g++>

VS2005下日志路径不支持中文

bool OpenLogger(LoggerId id)
{
...
setlocale(LC_ALL, "");
pLogger->_handle.open(path.c_str(), std::ios::app|std::ios::out|std::ios::binary); // std::fstream 在VS2005下打开中文路径的文件会出问题
setlocale(LC_ALL, "C");//还原
...
}
这是我目前的解决方法

控制台日志等级区分打印

你好,我目前正在使用log4z,很喜欢,非常感谢你的帮助!不过我发现,目前控制台打印日志只有一个开关,而不支持分等级打印,请问是这样的吗?如果是的,建议考虑这个功能,谢谢!:)

Log4z难道不支持MFC?

我在但文档项目中,增加了log4z ,退出时就会有内存泄漏,而注释掉log4z就不会有泄漏了。

其中我什么日志都不写只调用ILog4zManager::getRef().start();就会有泄漏。


Dumping objects ->
{367} normal block at 0x009D9440, 8224 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00
{362} normal block at 0x009D73E0, 8224 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00
Object dump complete.

大小都是 8224,固定的。

麻烦大牛帮忙看看。。。。

是否支持中文路径?

有一个工程使用了log4z作为日志库, 目前发现日志路径中如果含中文, 输出不成功. 目前是否支持中文路径?

系统平台: Windows.

请问一下libproc.h找不着的问题

image
同事在ios上编译我把log4z.cpp整合进去的工程,具体编译环境我也不太清楚。。不过会报找不着libproc.h的错误;libproc.h上边的dispatch.h没问题能找着;请问libproc.h这个文件的路径对吗??或者需要配置什么编译参数吗??

两个建议

1 .日志名字设置可调节
2.mac系统proc_name函数会对程序名进行15字节的截断,导致mac与linux运行结果不一致

请问单条日志容量如何设定?

从Http接收回的Json数据,由于数据量较大,如何完整的打印出来?
因为在Debug模式下,能看到的内容有限,想着log是专门做这个的,目前使用Log4z,当jons内容较大时,结果为
pid=10520 tid=10400 2021-04-22 14:39:25.018 DEBUG Test.exe "屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯蚿
这样的,而对于比较短的,就不会乱码,请问是因为容量有限制吗?

File Logger and SYNC mode

In current apparoch, if we enable both file logger and SYNC write, the following code will be run:

if (_loggers[pLog->_id]._outfile && LOG4Z_ALL_SYNCHRONOUS_OUTPUT) { if (openLogger(pLog)) { _loggers[pLog->_id]._handle.write(pLog->_content, pLog->_contentLen); closeLogger(pLog->_id); } }

The file handle will be opened before writing each log, and be closed after writing completed. This is not a problem, but I do meet an issue to keep writing logs into same log file. Looking into openLogger()

if (!pLogger->_handle.isOpen()) { pLogger->_curFileCreateTime = pLog->_time; pLogger->_curWriteLen = 0; tm t = timeToTm(pLogger->_curFileCreateTime); sprintf(buf, "%s_%s_%04d%02d%02d%02d%02d_%s_%03u.log", _proName.c_str(), name.c_str(), t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, _pid.c_str(), pLogger->_curFileIndex);

The logger will compose the target log filename based on current log's creation date, it means the logs will be wrote into two different log files, if we run the software for 2 minutes, is it the expected behavior?

Any suggestions if I want to keep writing logs into same log file, and only rolling logs when it exceeded the file size limitation (e.g. 100MB)?

what these code for ?

if (str.length() >= 3
&& (unsigned char)str[0] == 0xef
&& (unsigned char)str[1] == 0xbb
&& (unsigned char)str[2] == 0xbf)
{
posBegin = 3;
}

Log4zFileHandler::open不支持单个2GB以上的文件

ftell 和fseek只支持返回 long ,就是32位,最大2GB文件,超过2GB的文件会返回-1。

inline long open(const char *path, const char * mod)
    {
        if (_file != NULL){fclose(_file);_file = NULL;}
        _file = fopen(path, mod);
        if (_file)
        {
            long tel = 0;
            long cur = ftell(_file);
            fseek(_file, 0L, SEEK_END);
            tel = ftell(_file);
            fseek(_file, cur, SEEK_SET);
            return tel;
        }
        return -1;
    }

可以改成:
同时要修改相关变量的数据类型 int型到int64_t

	inline int64_t open64(const char *path, const char * mod)
	{
		if (_file != NULL) { fclose(_file); _file = NULL; }
		_file = fopen(path, mod);
		if (_file)
		{
			
#ifdef WIN32
#define ftell64  _ftelli64 
#define fseek64  _fseeki64
#else
#define ftell64  ftello64 
#define fseek64  fseeko64
#endif
			//along 支持2G以上的文件
			int64_t tel = 0;
			auto cur = ftell64(_file);
			fseek64(_file, 0L, SEEK_END);
			tel = ftell64(_file);
			fseek64(_file, cur, SEEK_SET);
			return tel;
		}
		return -1;
	}

程序爆掉

随便开两个线程一直写,半分钟吃掉2g内存.看了一下代码每次申请80k,设计的比较暴力

当日志队列满了之后再输出的日志会被丢弃

测试场景:
3个线程,每个线程输出10000条数据,使用LOGFMTD输出。并且关闭console输出,只写文件。
测试环境:
win10 64bit, i5, 8G
测试结果:
原本应该在日志文件里有30000条记录,结果只有2万多条(每次结果不一样)。
原因分析:
定位了一下,发现是prePushLog函数里会判断_logs队列的大小,如果超过LOG4Z_LOG_QUEUE_LIMIT_SIZE就会返回false,这条日志就被丢弃了。
解决方案:
把LOG4Z_LOG_QUEUE_LIMIT_SIZE这个值设置大一点,就能输出全部30000条。不过,到底设置多大才算够大,在实际使用过程中不好确定,只能是尽量设置的大一点,保证日志不丢失吧。

android compile err.error: 'gcvt' was not declared in this scope.

anroid-ndk stdlib.h not surpport gcvt.

[armeabi] Compile++ thumb: log4z <= log4z.cpp
In file included from ./log4z.cpp:37:
./log4z.h:829:13: error: use of undeclared identifier 'gcvt'
gcvt(t, isSimple ? 7 : 16, _cur);
^
./log4z.cpp:163:41: error: use of undeclared identifier 'POSIX_FADV_DONTNEED'
posix_fadvise(fd, index, len, POSIX_FADV_DONTNEED);
^
./log4z.cpp:1254:49: error: use of undeclared identifier 'SYS_gettid'
pLog->_threadID = (unsigned int)syscall(SYS_gettid);
^
3 errors generated.
make: *** [obj/local/armeabi/objs/log4z/log4z.o] Error 1

建议封装成动态库

单例模式,如果在跨库的使用过程当中(如 DLL库A依赖ILog4zManager,而exe同样依赖ILog4zManager)容易产生两个实例,这样就需要初始化两次(虽然在linux下可以使用rdynamic导出所有符号,确保整个进程中只有一个ILog4zManager符号,但是在windows还没找到解决办法),目前我ILog4zManager改成了动态库,确保在调用工程中只有一个实例在使用

Delete Old Log File automatically

In Log folder, after hours many log file created and may full free space on hard drive.
These old log file should be delete to avoid memory full in hard drive.
we can save only for example last 4 log files and delete others. and when a new log is created delete oldest file in these 4 files.

DynamicCreateLogger 接口缺失

在 FAQ( https://github.com/zsummer/log4z/wiki/LOG4Z-1.2.1-FAQ )中提到:

  1. 我想添加一个额外的日志记录器 怎么做?

回答: 调用接口DynamicCreateLogger, 然后使用日志输出的时候指定该接口返回的LoggerId. 具体使用参见源代码中提供的advance例子.

然而实际上,在当前(现在是2018年6月11日)的 log4z.h 中,并没有 DynamicCreateLogger 的定义,而且 advance例子中也没有DynamicCreateLogger的例子/

实际上在我的应用中,非常需要DynamicCreateLogger,因为我需要动态地加载一组动态链接库,然后每一个动态链接库都需要创建它自己的loggerId。主程序实现并不知道会加载哪些动态链接库,完全通过用户行为动态决定。(但动态链接库的个数肯定在20个以内)

我尝试着假如不用DynamicCreateLogger,在在决定加载哪些动态链接库时,执行
ILog4zManager::getRef().stop();

然后再通过createLogger创建我需要的所有logger,然后再执行 ILog4zManager::getRef().start();

可是我发现 ILog4zManager 一旦 stop 就无法再 start。

所以我还真是必须要用DynamicCreateLogger。

error

(gdb) where
#0 0x00007f5e0273b5d7 in raise () from /lib64/libc.so.6
#1 0x00007f5e0273ccc8 in abort () from /lib64/libc.so.6
#2 0x00007f5e0277be07 in __libc_message () from /lib64/libc.so.6
#3 0x00007f5e02781c67 in malloc_printerr () from /lib64/libc.so.6
#4 0x00007f5e0278328a in _int_free () from /lib64/libc.so.6
#5 0x0000000000425fa4 in zsummer::log4z::LogerManager::run (

this=0x647440 <zsummer::log4z::ILog4zManager::getInstance()::m>)
at ../src/log4z.cpp:1806

#6 0x000000000042176f in zsummer::log4z::threadProc (

pParam=0x647440 <zsummer::log4z::ILog4zManager::getInstance()::m>)
at ../src/log4z.cpp:277

#7 0x00007f5e035ffdf5 in start_thread () from /lib64/libpthread.so.0
#8 0x00007f5e027fc1ad in clone () from /lib64/libc.so.6

存在内存泄露问题

valgrind测试存在内存泄露,makeLogData 内存没有释放,测试代码如下:

  1. ILog4zManager::getRef().start();
  2. LOGD("stream input *** " <<1 );

log中文件定位信息

VS下debug模式会输出log在文件(为绝对路径)的具体位置,release是相对路径。在Linux下cmake的debug、release均是完整路径,请问可以设置在Linux release下输出相对路径吗?
绝对路径:2014-12-02 13:42:09.694 LOG_ALARM main quit .. ( h:\thirdlib\log4z\test\advanced_test.cpp ) : 84
相对路径:2014-11-27 11:12:33.184 LOG_ALARM main quit .. ( .\advanced_test.cpp ) : 84

error C3861: 'isnan': identifier not found

inline Log4zStream & Log4zStream::writeDouble(double t, bool isSimple)
{

#if __cplusplus >= 201103L
using std::isnan;
using std::isinf;
#endif
if (isnan(t))
{
writeString("nan", 3);
return *this;
}
else if (isinf(t))
{
writeString("inf", 3);
return *this;
}

你好,上述这段代码在vs2008下编译不通过,我觉得是不是应该把#endif放在最后。

日志自动清除

你好,可以自动清除日志吗,或者能循环记录,避免日志文件占用空间无限增长,setLoggerReserveTime似乎,只对本次运行的进程有效,程序重新启动,并不检查过往的日志文件是否已经超过保留时间。请问还有其他解决方法吗

Does log4z clear old logs in the logfolder?

Hi.

Good work! Just wondering if the logger clears old logs in the logfolder when files are getting too big and too many, or them being too old? Is it something we need to clean up ourselves from time to time or through a flag in the config file somewhere?

Really appreciate the work! :-)

Thanks.

可以指定文件名格式和文件夹格式吗

您好,这个库用得很舒服,可否再舒服点~
就是,可以在通过在配置文件中使用通配符来自定义文件夹和文件名的格式吗,
比如
[Main]
path=./Log/CusModle_%DateTime/
fileName= Main_%DateTime{%Y_%M_%D}.log

目前支持吗,如果支持的话需要怎么做来的,谢谢啊~

如何限制日志的大小呢?

日志可以按月份存储,但是如何限制日志文件大小,以免造成占用的空间无法释放,无需手动删除。

why lock here ?

    std::string name;
    std::string path;
    _hotLock.lock();
    name = pLogger->_name;
    path = pLogger->_path;
    _hotLock.unLock();

why use lock here ? the value of name and path is not change

Log4zFileHandler::readContent中fread可能失败

if (fread(&content[0], 1, filelen, _file) != (size_t)filelen)
{
content.clear();
return content;
}

fread函数在读取filelen长度数据时,可能少于filelen
此时不一定是文件错误或者遇到文件尾
测试发现,使用rb模式打开文件时,fread返回的长度才等于文件长度
可能是因为r模式下,控制字符被转义了。

hello

hello ,why code like this? i don't know your purpose?Can you say in detailed?

inline Log4zStream & Log4zStream::writeBinary(const Log4zBinary & t)
{
writeData("%s", "\r\n\t[");
for (int i = 0; i < t._len; i++)
{
if (i % 16 == 0)
{
writeData("%s", "\r\n\t");
this << (void)(t._buf + i);
writeData("%s", ": ");
}
writeData("%02x ", (unsigned char)t._buf[i]);
}
writeData("%s", "\r\n\t]\r\n\t");
return *this;
}

Linker Fail


log4z.h:153:9: warning: #pragma once in main file [enabled by default]
#pragma once
^
/tmp/ccXVXlM7.o:在函数‘zsummer::log4z::CLock::CLock()’中:
log4z.cpp:(.text+0x165c):对‘pthread_mutexattr_init’未定义的引用
log4z.cpp:(.text+0x166d):对‘pthread_mutexattr_settype’未定义的引用
log4z.cpp:(.text+0x1690):对‘pthread_mutexattr_destroy’未定义的引用
/tmp/ccXVXlM7.o:在函数‘zsummer::log4z::CSem::~CSem()’中:
log4z.cpp:(.text+0x179f):对‘sem_destroy’未定义的引用
/tmp/ccXVXlM7.o:在函数‘zsummer::log4z::CSem::Create(int)’中:
log4z.cpp:(.text+0x1812):对‘sem_init’未定义的引用
/tmp/ccXVXlM7.o:在函数‘zsummer::log4z::CSem::Wait(int)’中:
log4z.cpp:(.text+0x1857):对‘sem_wait’未定义的引用
log4z.cpp:(.text+0x18cc):对‘sem_trywait’未定义的引用
/tmp/ccXVXlM7.o:在函数‘zsummer::log4z::CSem::Post()’中:
log4z.cpp:(.text+0x1968):对‘sem_post’未定义的引用
/tmp/ccXVXlM7.o:在函数‘zsummer::log4z::CThread::Start()’中:
log4z.cpp:(.text+0x199a):对‘pthread_create’未定义的引用
/tmp/ccXVXlM7.o:在函数‘zsummer::log4z::CThread::Wait()’中:
log4z.cpp:(.text+0x19ef):对‘pthread_join’未定义的引用
collect2: error: ld returned 1 exit status


直接使用头文件和源文件在同一目录下编译:

g++ -std=c++11 -o freebird main.cpp log4z.cpp make_x86_64_sysv_elf_gas.S jump_x86_64_sysv_elf_gas.S

g++ --version
g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2

配置文件中解析问题

1、log4z.cpp的671行应该是iter->second._level = LOG_LEVEL_ALARM吧;
2、读取utf-8带BOM编码的配置文件时控制台会提示“log4z configure warning: unresolved line”错误,读取ANSI、utf-8无BOM编码的配置文件正常,可否添加对utf8带BOM的支持;
3、可否添加对bool Config(const char * strCfgPath)中参数指定的配置文件不存在时进行警告提示(因为这个问题我还以为log4z有重大bug呢,囧);
4、谢谢!

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.