[置頂] C++開源日誌庫--Glog的使用
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
[置頂] C++開源日誌庫--Glog的使用
分類: C/C++ 2013-07-16 11:31 1213人閱讀公司其他同事大多做C#的,公司內部暫時也沒用提供自己的C++日誌庫,由於專案較緊急,所以就準備選一個開源日誌庫使用,由於以前做過java,用的Log4j比較強大,但是查了下,其使用起來有點複雜。所以就想到最偉大的公司google了,其Glog使用還是比較簡單的,原始碼下下來直接用VS編譯生成lib和dll庫,原始碼檔案中都有現成的vs工程。
開源專案首頁:https://code.google.com/p/google-glog/
Glog專案路徑: https://code.google.com/p/google-glog/downloads/list
第一步,下載glog-0.3.3.tar.gz,解壓,直接開啟google-glog.sln工程檔案,如果vs版本不對,讓其自動轉換
第二步,編譯,在Debug下生成libglog.dll、 libglog.lib、libglog_static.lib
第三步,將標頭檔案和lib庫拷貝到自己的工程下,由於我暫時是window下使用,標頭檔案使用 \glog-0.3.3\src\windows\glog
第四步,引用到自己工程下,編譯發現報錯:
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> SessionMgr.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> SessionFactory.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> RealTimeStreamSession.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> main.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> GNumGenerator.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> DevicControlSession.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> CatalogSesssion.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
進入log_severity.h標頭檔案檢視,是一個巨集定義的地方出現了衝突: [cpp] view plain copy print ?
- #ifndef GLOG_NO_ABBREVIATED_SEVERITIES
- # ifdef ERROR
- # error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- # endif
- const int INFO = GLOG_INFO, WARNING = GLOG_WARNING,
- ERROR = GLOG_ERROR, FATAL = GLOG_FATAL;
- #endif
解決方法:
在工程加上預編譯巨集GLOG_NO_ABBREVIATED_SEVERITIES
C/C++ --> 前處理器 --> 前處理器定義 --> 加上GLOG_NO_ABBREVIATED_SEVERITIES巨集 儲存,編譯通過~
第五步,自己的專案中使用
- #include "glog/logging.h"
- int _tmain(int argc, _TCHAR* argv[])
- {
- google::InitGoogleLogging((const char *)argv[0]); //引數為自己的可執行檔名
- google::SetLogDestination(google::GLOG_INFO,"./myInfo");
- LOG(INFO) << "This is a <Warn> log message..." << ;
- .....................
- }
搞定,後面就是將這些日誌在工程中使用起來了。
給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow
公司其他同事大多做C#的,公司內部暫時也沒用提供自己的C++日誌庫,由於專案較緊急,所以就準備選一個開源日誌庫使用,由於以前做過java,用的Log4j比較強大,但是查了下,其使用起來有點複雜。所以就想到最偉大的公司google了,其Glog使用還是比較簡單的,原始碼下下來直接用VS編譯生成lib和dll庫,原始碼檔案中都有現成的vs工程。
開源專案首頁:https://code.google.com/p/google-glog/
Glog專案路徑: https://code.google.com/p/google-glog/downloads/list
第一步,下載glog-0.3.3.tar.gz,解壓,直接開啟google-glog.sln工程檔案,如果vs版本不對,讓其自動轉換
第二步,編譯,在Debug下生成libglog.dll、 libglog.lib、libglog_static.lib
第三步,將標頭檔案和lib庫拷貝到自己的工程下,由於我暫時是window下使用,標頭檔案使用 \glog-0.3.3\src\windows\glog
第四步,引用到自己工程下,編譯發現報錯:
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> SessionMgr.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> SessionFactory.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> RealTimeStreamSession.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> main.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> GNumGenerator.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> DevicControlSession.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- 1> CatalogSesssion.cpp
- 1>d:\workspace\video\videomanage\devicemgr\lib\glog\glog\log_severity.h(55): fatal error C1189: #error : ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
進入log_severity.h標頭檔案檢視,是一個巨集定義的地方出現了衝突: [cpp] view plain copy print ?
- #ifndef GLOG_NO_ABBREVIATED_SEVERITIES
- # ifdef ERROR
- # error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
- # endif
- const int INFO = GLOG_INFO, WARNING = GLOG_WARNING,
- ERROR = GLOG_ERROR, FATAL = GLOG_FATAL;
- #endif
解決方法:
在工程加上預編譯巨集GLOG_NO_ABBREVIATED_SEVERITIES
C/C++ --> 前處理器 --> 前處理器定義 --> 加上GLOG_NO_ABBREVIATED_SEVERITIES巨集 儲存,編譯通過~
第五步,自己的專案中使用
- #include "glog/logging.h"
- int _tmain(int argc, _TCHAR* argv[])
- {
- google::InitGoogleLogging((const char *)argv[0]); //引數為自己的可執行檔名
- google::SetLogDestination(google::GLOG_INFO,"./myInfo");
- LOG(INFO) << "This is a <Warn> log message..." << ;
- .....................
- }
搞定,後面就是將這些日誌在工程中使用起來了。