導航:首頁 > 編程語言 > pythonglog使用

pythonglog使用

發布時間:2022-07-17 21:31:53

『壹』 如何解決使用glog和gflags時遇到的錯誤

錯誤是這樣的:

/usr/local/lib/libgflags.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status
glog是通過下面方式安裝的:
sudo apt-get install build-essential
sudo apt-get install vim cmake git
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
在上面的安裝中同時安裝了gflags,不僅如此,我還在git上下載了gflags的源碼也進行了安裝。
解決方法:
我對下載的gflags源碼進行編譯,在cmake時候加入了expor CXXFLAGS="-fPIC"、make VERBOSE=1就可以正常使用gflags和glog了。
即:
export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
make && make install

『貳』 安裝caffe一定要用cuda嗎

如果你的caffe需要使用GPU計算,就一定要按照cuda,cuda相當於是專門用於GPU的語言。如果你只使用CPU計算,則不需要GPU,同理也就不需要cuda

『叄』 linux下無cuda怎麼pip安裝pytorch

linux下安裝caffe(無cuda)以及python介面
caffe(8)
主要過程稍微記錄一下:
1.安裝BLAS
sudo apt-get install libatlas-base-dev

2.安裝依賴項
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev protobuf-compiler liblmdb-dev
3.安裝glog
這個要FQ,我放在我的網路雲上了。
tar zxvf glog-0.3.3.tar.gz
cd glog-0.3.3
./configure
make
sudo make install

4.安裝gflags

wget https://github.com/schuhschuh/gflags/archive/master.zip
unzip master.zip
cd gflags-master
mkdir build && cd build
export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
make
sudo make install

這一步需要cmake,如果沒有安裝可以用 sudo apt-get install cmake 安裝。
5.安裝lmdb
git clone https://gitorious.org/mdb/mdb.git
cd mdb/libraries/liblmdb
make
sudo make install

如果沒有安裝Git,也要用 sudo apt-get install git 來安裝。
註:如果可以FQ,只用下面一句就可以安裝gflags,glog和lmdb了,省了3,4,5這三步。
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler

6.下載Caffe
git clone git://github.com/BVLC/caffe.git

7.安裝Caffe
cd caffe
cp Makefile.config.example Makefile.config

因為這里沒有gpu,所以需要設置Makefile.config文件中的CPU_ONLY:= 1,把這句的注釋去掉就可以了。
然後編譯
make all
make test
make runtest

安裝好以後我們就可以試著在mnist上跑一下lenet了。
1.首先獲取mnist數據
cd caffe
./data/mnist/get_mnist.sh

2.然後創建lenet
./examples/mnist/create_mnist.sh

注意一定要在caffe的根目錄下運行以下命令,否則會報「 build/examples/mnist/convert_mnist_data.bin: not found」的錯誤,參見這里。
3.訓練cnn
沒有gpu的話要記得把caffe/examples/mnist/lenet_solver.prototxt中的solver_mode設置成solver_mode: CPU。然後在根目錄下執行:
./examples/mnist/train_lenet.sh

准確率可以達到0.9912

因為caffe的tutorial上有很大一部分是Python的,所以後來又安裝了一下python的介面。
1.首先安裝python
2.安裝pip
sudo apt-get install python-pip python-dev build-essential

3.運行以下代碼安裝必要的依賴項:
sudo pip install -r ./python/requirements.txt

4.這里我運行了make clean以及其他編譯的caffe的命令,重新編譯了一次caffe,但我不確定是不是必須的。
5.在caffe的根目錄下運行:
make pycaffe

這里遇到了一個問題:
virtual memory exhausted: Cannot allocate memory
make: *** [python/caffe/_caffe.so] Error 1

按照這里的方法增加Linux虛擬機的內存就可以解決了。
6.把caffe/python的路徑加到python路徑中:
運行python進入python shell,然後運行下列命令:
import sys
sys.path.append("path/to/caffe/python/")
exit()

7. 這時候再次進入python shell,運行import caffe就沒有報錯了。

『肆』 如何使用Google 的Cartographer SLAM演算法

0.安裝所依賴項
sudo apt-get install -y google-mock libboost-all-dev libeigen3-dev libgflags-dev libgoogle-glog-dev liblua5.2-dev libprotobuf-dev libsuitesparse-dev libwebp-dev ninja-build protobuf-compiler Python-sphinx ros-indigo-tf2-eigen libatlas-base-dev libsuitesparse-dev liblapack-dev
1.首先安裝ceres solver選擇版本1.11,路徑隨意
Git clone
cd ceres-solver-1.11.0/build
cmake ..
make –j
sudo make install

2.安裝 cartographer,路徑隨意
git clone
cd cartographer/build
cmake .. -G Ninja
ninja
ninja test
sudo ninja install

3.安裝cartographer_ros
谷歌官提供安裝比較繁瑣我原文件進行少許修改核代碼變修改編譯文件
載catkin_ws面src文件夾
git clone
catkin_ws面運行catkin_make即

4.數據載測試
2d數據概500M用迅雷載

3d數據8G左右同用迅雷載

運行launch文件即
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/cartographer_3d_deutsches_museum.bag
圖左側2d,右側3d

『伍』 ubuntu14.04搭建caffe要做哪些工作

首先吐槽一下本屌的筆記本,我現在的筆記本還是大一時候買的Dell INSPIRON 4010,沒有Nvidia,沒有Nvidia,沒有Nvidia,沒有Nvidia,重要的事情說四遍,呵呵。

操作系統: Ubuntu 14.04

是否使用PYTHON API: 是, 目標是安裝後CAFFE能作為PYTHON MODULE來使用

硬體: 低端筆記本, 只使用CPU模式

1.安裝依賴

1 sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
2 sudo apt-get install --no-install-recommends libboost-all-dev
3 sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
4 sudo apt-get install libatlas-base-dev

PYTHON需要2.7版本,這是操作系統本身已經安裝好的. 輸入python2.7 --version 會顯示具體的版本號說明安裝了.

但是還需要sudo apt-get install python-dev

2.下載Caffe
使用Git直接下載Caffe非常簡單,或者去https://github.com/BVLC/caffe下載。由於我習慣去github上找代碼,所以就直接去下載的源碼。

下載完成後,會在家目錄下的下載里找到caffe-master.zip,用unzip命令解壓到家目錄下,然後重命名為caffe.

3.編譯Caffe
(1)切換到Caffe所在目錄

cp Makefile.config.example Makefile.config

(2)修改配置文件Makefile.config

CPU_ONLY := 1
配置一些引用文件(增加部分主要是解決新版本下,HDF5的路徑問題)

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
BLAS := atlas

計算能力 mkl > openlas >atlas

(3)編譯 Caffe

make all
make test
make runtest

另外, 這個make默認是用CPU單核運算,如果想要快一點, 比如我想使用四核, 在make後面加上-j4標簽。

如果上面4行某一行報錯之後想要重試,建議先make clean再重新開始。

4.編譯Python介面
Caffe擁有python\C++\shell介面,在Caffe使用python特別方便,在實例中都有介面的說明。

確保pip已經安裝

sudo apt-get install python-pip

執行安裝依賴

在caffe根目錄的python文件夾下,有一個requirements.txt的清單文件,上面列出了需要的依賴庫,按照這個清單安裝就可以了。

在安裝scipy庫的時候,需要fortran編譯器(gfortran),如果沒有這個編譯器就會報錯,因此,我們可以先安裝一下。

首先回到caffe的根目錄,然後執行安裝代碼:

cd ~/caffe
sudo apt-get install gfortran
cd ./python
for req in $(cat requirements.txt); do pip install $req; done

安裝完成以後,再次回到caffe根目錄我們可以執行:

sudo pip install -r python/requirements.txt

就會看到,安裝成功的,都會顯示Requirement already satisfied, 沒有安裝成功的,會繼續安裝。

編譯python介面

make pycaffe

--結果顯示ALL TESTS PASSED就安裝好了!

運行python結構

$ python2.7
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "right", "credits" or "license" for more information.
>>> import caffe
>>>

如果沒有報錯,說明caffe安裝全部完成!

5.在Mnist運行Lenet

獲取數據源

./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh

因為是CPU運行,所以修改在examples文件下的Mnist下的lenet_solver.prototxt中的solver_mode:CPU

solver_mode: CPU

訓練模型

./examples/mnist/train_lenet.sh

整個訓練時間會持續很久,這是因為本屌的筆記本還是i3處理器,且沒有啟用GPU,並且默認是單核,所以本屌足足等了3個小時 =。= ..... 自動腦補我心裡的萬馬奔騰吧
6.最後,我的文章是基於各位前輩大神們的文章,雖然按他們的過程走我都報錯了,但是最終還是幫助我安裝成功。

『陸』 imagenet是基於什麼模型的

1、准備數據。
假設已經下載好數據集和驗證集,存儲路徑為:
/path/to/imagenet/train/n01440764/n01440764_10026.JPEG
/path/to/imagenet/val/ILSVRC2012_val_00000001.JPEG
首選需要創建一個txt文件,列舉出所有圖像以及對應的lable,caffe包「Python/caffe/imagenet/ilsvrc_2012_train.txt」和「ilsvrc_2012_val.txt」兩個文件分別是標好的訓練集和驗證集的文件,共分為1000類。
還需要注意的是,所有的圖像都需要歸一到同樣的尺寸。

2、轉化生成訓練集。
運行下面的命令:
GLOG_logtostderr=1 examples/convert_imageset.bin /path/to/imagenet/train/ python/caffe/imagenet/ilsvrc_2012_train.txt /path/to/imagenet-train-leveldb
生成文件存儲在「/path/to/imagenet-train_leveldb」路徑下。

3、計算圖像均值。
執行命令:
examples/demo_compute_image_mean.bin /path/to/imagenet-train-leveldb /path/to/mean.binaryproto
第一個參數是執行腳本代碼,第二個參數是上一步生成的數據集,第三個參數是存儲圖像均值的目錄路徑。

4、定義網路。
ImageNet的網路定義在「examples/imagenet.prototxt」文件中,使用時需要修改裡面source和meanfile變數的值,指向自己文件的路徑。
仔細觀察imagenet.prototxt和imagenet_val.prototxt文件可以發現,訓練和驗證的參數大部分都相同,不同之處在於初始層和最後一層。訓練時,使用softmax_loss層來計算損失函數和初始化後向傳播,驗證時,使用accuracy層來預測精確度。
在文件「examples/imagenet_solver.prototxt」中定義solver協議,同樣需要修改train_net和test_net的路徑。

5、訓練網路。
執行命令:
GLOG_logtostderr=1 examples/train_net.bin examples/imagenet_solver.prototxt

6、在python中使用已經訓練好的模型。
Caffe只提供封裝好的imagenet模型,給定一副圖像,直接計算出圖像的特徵和進行預測。首先需要下載模型文件。

『柒』 如何使用Google日誌庫

如何使用Google日誌庫 (glog)

介紹
Google glog是一個應用層的庫. 它提供基於C++風格的流和多種宏介面.例如:
#include <glog/logging.h>

int main(int argc, char* argv[]) {
// Initialize Google's logging library.
google::InitGoogleLogging(argv[0]);

// ...
LOG(INFO) << "Found " << num_cookies << " cookies";
}
Google glog定義了一系列的宏處理普通的日誌工作. 你可以分級記錄, control loggingbehavior from the command line, 按條件記錄, abort theprogram when expected conditions are not met, introce your ownverbose logging levels, 及其它. 文本只是簡單的介紹了常用的glog功能而不是所有的細節.沒介紹到的,自己讀代碼去吧.

嚴重等級
嚴重等級包括(按嚴重程度排序): INFO, WARNING,ERROR,和FATAL.記錄一個FATAL級的錯誤後會自動終止程序執行(其實就是_asm int 3).一個嚴重等級高的記錄不但記錄在它自己的文件,也記錄在比它低等的文件里.例如, 一個FATAL級的記錄將會記在FATAL, ERROR,WARNING, 和INFO等級的日誌里.
在debug狀態下FATAL級記錄也可以用DFATAL(當沒定義NDEBUG宏的時候),發給客戶的程序最好不要用FATAL小心客戶對你使用_asm int 3,這時ERROR是個不錯的選擇.
glog默認把日誌文件命名為"/tmp/...log...."(例如, "/tmp/hello_world.example.com.hamaji.log.INFO.20080709-222411.10474").glog默認把ERROR 和 FATAL 級的記錄發送一份到stderr.

設置標志
標志可以改變glog的輸出行為.如果你安裝了Googlegflags library, configure 腳本 (具體請參考它的INSTALL文件)會自動檢測並使用標志,這時你可以通過命令行使用標志.例如, 若你想發送 --logtostderr 標志,像下面這樣:
./your_application --logtostderr=1
如果你沒裝Google gflags library,你就只能用帶GLOG_的環境變數實現,例如.
GLOG_logtostderr=1 ./your_application (貌似在Windows里不能這樣用吧?)
常用的標志有:
logtostderr (bool, default=false)
寫日誌到stderr而不是日誌文件.
Note: you can set binary flags to true by specifying1, true, or yes (caseinsensitive).Also, you can set binary flags to false by specifying0, false, or no (again, caseinsensitive).

stderrthreshold (int, default=2, whichis ERROR)
將某級及以上級別的記錄同時發送到stderr和日誌文件. 嚴重等級INFO, WARNING, ERROR, FATAL 分別對應 0, 1, 2, 3.

minloglevel (int, default=0, whichis INFO)
只記錄某級及以上級別的記錄.

log_dir (string, default="")
指定日誌保存的目錄.

v (int, default=0)
Show all VLOG(m) messages for m less orequal the value of this flag. Overridable by --vmole.See the section about verbose logging for moredetail.

vmole (string, default="")
Per-mole verbose level. The argument has to contain acomma-separated list of =.is a glob pattern (e.g., gfs* for all moles whose namestarts with "gfs"), matched against the filename base(that is, name ignoring .cc/.h./-inl.h). overrides any value given by --v.See also the section about verbose logging.
還有一些其它的標志,自己去logging.cc裡面搜索"DEFINE_",爺就不多說了.

你也可以在程序里修改FLAGS_* 開頭的全局變數. 通常設置FLAGS_*開頭的變數會立即生效,和日誌文件名或路徑相關的變數例外.例如FLAGS_log_dir就不能放在google::InitGoogleLogging後面.例子代碼:
LOG(INFO) << "file";
// Most flags work immediately after updating values.
FLAGS_logtostderr = 1;
LOG(INFO) << "stderr";
FLAGS_logtostderr = 0;
// This won't change the log destination. If you want to set this
// value, you should do this before google::InitGoogleLogging .
FLAGS_log_dir = "/some/log/directory";
LOG(INFO) << "the same file";
條件/ Occasional Logging
下面的宏用於根據條件寫日誌:
LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
只有當num_cookies > 10的時候才會記錄"Got lots of cookies"
如果有的代碼執行非常頻繁,你肯定不會希望每次都寫入日誌.這時,你可以使用下面的方法:
LOG_EVERY_N(INFO, 10) < Got the googleCOUNTER th cookiepre>
上面的代碼只有當第1次,第11次,第21次....執行時才寫入日誌.Note that the specialgoogle::COUNTER value is used to identify which repetition ishappening.
條件和計次可以混合使用,例如:
LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER
<< "th big cookie";
除了間隔N次輸出,還可以只輸出前M次,例如:
LOG_FIRST_N(INFO, 20) < Got the googleCOUNTER th cookiepre>
只輸出前20次.

Debug mode支持
"debug mode"的宏只在調試模式有效,其他模式不生效.上栗子:
DLOG(INFO) << "Found cookies";

DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";

DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
CHECK宏
經常檢查是否會出錯而不是等著程序執行出錯是個不錯的習慣.CHECK宏就是干這個滴,它的功能和assert一樣,條件不符合時終止程序.
與assert不同的是它*不*受NDEBUG的限制,無論是不是debug編譯它都執行.所以下面的fp-<Write(x)會被執行:
CHECK(fp->Write(x) == 4) << "Write failed!";
有各種各樣的宏用於CHECK相等/不相等,包括: CHECK_EQ,CHECK_NE, CHECK_LE, CHECK_LT,CHECK_GE,和CHECK_GT.它們會記錄一個FATAL級的記錄到日誌,牛X的是他們還會把對比的兩個值也一起記錄.(那兩個值必須定義了 operator< ostreamcode> ).例如:
CHECK_NE(1, 2) << ": The world must be ending!";
We are very careful to ensure that each argument is evaluated exactlyonce, and that anything which is legal to pass as a function argument islegal here. In particular, the arguments may be temporary expressionswhich will end up being destroyed at the end of the apparent statement,for example:
CHECK_EQ(string("abc")[1], 'b');
The compiler reports an error if one of the arguments is apointer and the other is NULL. To work around this, simply static_castNULL to the type of the desired pointer.
CHECK_EQ(some_ptr, static_cast(NULL));
還有個好辦法:用CHECK_NOTNULL宏:
CHECK_NOTNULL(some_ptr); some_ptr-<DoSomething();
這宏也常用於構造函數中.
struct S {
S(Something* ptr) : ptr_(CHECK_NOTNULL(ptr)) {}
Something* ptr_;
};
這宏的缺點是不能跟C++流一起用.這時就得用CHECK_EQ了.
如果你要對比一個C字元串(char *)可以用:CHECK_STREQ, CHECK_STRNE,CHECK_STRCASEEQ,和CHECK_STRCASENE.帶CASE的區分大小寫. 這個宏參數可以用NULL指針.NULL與non-NULL比不等.兩個NULL是相等的.
Note that both arguments may be temporary strings which aredestructed at the end of the current "full expression"(e.g., CHECK_STREQ(Foo().c_str(), Bar().c_str()) whereFoo and Bar return C++'sstd::string).
CHECK_DOUBLE_EQ 用於對比浮點數,會有小小的誤差.CHECK_NEAR 可以接受一個浮點數作為誤差.
詳細日誌
用VLOG宏,你還可以定義自己的嚴重等級. The --v command line option controlswhich verbose messages are logged:
VLOG(1) << "I'm printed when you run the program with --v=1 or higher";
VLOG(2) << "I'm printed when you run the program with --v=2 or higher";
With VLOG, the lower the verbose level, the morelikely messages are to be logged. For example, if--v==1, VLOG(1) will log, butVLOG(2) will not log. This is opposite of the severitylevel, where INFO is 0, and ERROR is 2.--minloglevel of 1 will log WARNING andabove. Though you can specify any integers for both VLOGmacro and --v flag, the common values for them are smallpositive integers. For example, if you write VLOG(0),you should specify --v=-1 or lower to silence it. Thisis less useful since we may not want verbose logs by default in mostcases. The VLOG macros always log at theINFO log level (when they log at all).
Verbose logging can be controlled from the command line on aper-mole basis:
--vmole=maprece=2,file=1,gfs*=3 --v=0
will:
a. Print VLOG(2) and lower messages from maprece.{h,cc}
b. Print VLOG(1) and lower messages from file.{h,cc}
c. Print VLOG(3) and lower messages from files prefixed with "gfs"
d. Print VLOG(0) and lower messages from elsewhere
The wildcarding functionality shown by (c) supports both '*'(matches 0 or more characters) and '?' (matches any single character)wildcards. Please also check the section about command line flags.
There's also VLOG_IS_ON(n) "verbose level" conditionmacro. This macro returns true when the --v is equal orgreater than n. To be used as
if (VLOG_IS_ON(2)) {
// do some logging preparation and logging
// that can't be accomplished with just VLOG(2) << ...;
}
Verbose level condition macros VLOG_IF,VLOG_EVERY_N and VLOG_IF_EVERY_N behaveanalogous to LOG_IF, LOG_EVERY_N,LOF_IF_EVERY, but accept a numeric verbosity level asopposed to a severity level.
VLOG_IF(1, (size > 1024))
<< "I'm printed when size is more than 1024 and when you run the "
"program with --v=1 or more";
VLOG_EVERY_N(1, 10)
<< "I'm printed every 10th occurrence, and when you run the program "
"with --v=1 or more. Present occurence is " << google::COUNTER;
VLOG_IF_EVERY_N(1, (size > 1024), 10)
<< "I'm printed on every 10th occurence of case when size is more "
" than 1024, when you run the program with --v=1 or more. ";
"Present occurence is " << google::COUNTER;
Failure Signal Handler
The library provides a convenient signal handler that will mp usefulinformation when the program crashes on certain signals such as SIGSEGV.The signal handler can be installed bygoogle::InstallFailureSignalHandler(). The following is an example of outputfrom the signal handler.
*** Aborted at 1225095260 (unix time) try "date -d @1225095260" if you are using GNU date ***
*** SIGSEGV (@0x0) received by PID 17711 (TID 0x7f893090a6f0) from PID 0; stack trace: ***
PC: @ 0x412eb1 TestWaitingLogSink::send()
@ 0x7f892fb417d0 (unknown)
@ 0x412eb1 TestWaitingLogSink::send()
@ 0x7f89304f7f06 google::LogMessage::SendToLog()
@ 0x7f89304f35af google::LogMessage::Flush()
@ 0x7f89304f3739 google::LogMessage::~LogMessage()
@ 0x408cf4 TestLogSinkWaitTillSent()
@ 0x4115de main
@ 0x7f892f7ef1c4 (unknown)
@ 0x4046f9 (unknown)
By default, the signal handler writes the failure mp to the standarderror. You can customize the destination by InstallFailureWriter().
Miscellaneous Notes
Performance of Messages
The conditional logging macros provided by glog (e.g.,CHECK, LOG_IF, VLOG, ...) arecarefully implemented and don't execute the right hand sideexpressions when the conditions are false. So, the following checkmay not sacrifice the performance of your application.
CHECK(obj.ok) << obj.();
User-defined Failure Function
FATAL severity level messages or unsatisfiedCHECK condition terminate your program. You can changethe behavior of the termination byInstallFailureFunction.
void YourFailureFunction() {
// Reports something...
exit(1);
}

int main(int argc, char* argv[]) {
google::InstallFailureFunction(&YourFailureFunction);
}
By default, glog tries to mp stacktrace and makes the programexit with status 1. The stacktrace is proced only when you run theprogram on an architecture for which glog supports stack tracing (asof September 2008, glog supports stack tracing for x86 and x86_64).
Raw Logging
The header file can beused for thread-safe logging, which does not allocate any memory oracquire any locks. Therefore, the macros defined in thisheader file can be used by low-level memory allocation andsynchronization code.Please check src/glog/raw_logging.h.in for detail.
Google Style perror()
PLOG() and PLOG_IF() andPCHECK() behave exactly like their LOG* andCHECK equivalents with the addition that they append adescription of the current state of errno to their output lines.E.g.
PCHECK(write(1, NULL, 2) <= 0) < Write NULL failedpre>
This check fails with the following error message.
F0825 185142 test.cc:22] Check failed: write(1, NULL, 2) <= 0 Write NULL failed: Bad address [14]
Syslog
SYSLOG, SYSLOG_IF, andSYSLOG_EVERY_N macros are available.These log to syslog in addition to the normal logs. Be aware thatlogging to syslog can drastically impact performance, especially ifsyslog is configured for remote logging! Make sure you understand theimplications of outputting to syslog before you use these macros. Ingeneral, it's wise to use these macros sparingly.
Strip Logging Messages
Strings used in log messages can increase the size of your binaryand present a privacy concern. You can therefore instruct glog toremove all strings which fall below a certain severity level by usingthe GOOGLE_STRIP_LOG macro:
If your application has code like this:
#define GOOGLE_STRIP_LOG 1 // this must go before the #include!
#include <glog/logging.h>
The compiler will remove the log messages whose severities are lessthan the specified integer value. SinceVLOG logs at the severity level INFO(numeric value 0),setting GOOGLE_STRIP_LOG to 1 or greater removesall log messages associated with VLOGs as well asINFO log statements.
對於Windows用戶
glog的ERROR級錯誤與windows.h沖突. You can make glog not defineINFO, WARNING, ERROR,and FATAL by definingGLOG_NO_ABBREVIATED_SEVERITIES beforeincluding glog/logging.h . Even with this macro, you canstill use the iostream like logging facilities:
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include <windows.h>
#include <glog/logging.h>

// ...

LOG(ERROR) << "This should work";
LOG_IF(ERROR, x > y) << "This should be also OK";
However, you cannotuse INFO, WARNING, ERROR,and FATAL anymore for functions definedin glog/logging.h .
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include <windows.h>
#include <glog/logging.h>

// ...

// This won't work.
// google::FlushLogFiles(google::ERROR);

// Use this instead.
google::FlushLogFiles(google::GLOG_ERROR);
If you don't need ERROR definedby windows.h, there are a couple of more workaroundswhich sometimes don't work:
#define WIN32_LEAN_AND_MEAN or NOGDIbefore you #include windows.h .
#undef ERRORafter you #include windows.h .
See this issue for more detail.

閱讀全文

與pythonglog使用相關的資料

熱點內容
李采潭蘑菇 瀏覽:225
紫軒小說手打版下載 瀏覽:55
電腦pdf閱讀器下載 瀏覽:770
30G電影下載 瀏覽:440
電影孝順女兒觀影問卷 瀏覽:470
怎麼自己造一個伺服器手機版 瀏覽:165
程序員製作連線題目 瀏覽:186
女人被精神控制後被侵犯電影 瀏覽:495
安卓開機鍵壞了怎麼開機重啟 瀏覽:796
染島貢作品簡介 瀏覽:801
哥的電影的 瀏覽:899
狼狽電影百度雲 瀏覽:478
dos命令如何跳過程序 瀏覽:619
編譯器沒有游標怎麼辦 瀏覽:871
在天貓app怎麼看天貓積分 瀏覽:224
安卓手機怎麼下載gba電玩之家 瀏覽:771
周三多管理學pdf 瀏覽:463
一部美國電影講的是幾個小孩子 瀏覽:415
用手機怎麼把圖片放到一個文件夾 瀏覽:591
吃奶的電影照片 瀏覽:360