glog


glog always create two files, which has nearly the same content


My test code as blow:
std::string strLogPath = "d:/logtest/";
google::InitGoogleLogging("test1");
FLAGS_log_dir = strLogPath;
FLAGS_stderrthreshold = google::GLOG_INFO;
FLAGS_minloglevel = google::GLOG_INFO;
//FLAGS_colorlogtostderr = true;
std::string strLogPath1 = "d:/logtest/L";
google::SetLogDestination(google::GLOG_INFO, strLogPath1.c_str());
google::SetLogDestination(google::GLOG_ERROR, strLogPath1.c_str());
google::SetLogDestination(google::GLOG_WARNING, strLogPath1.c_str());
google::SetLogDestination(google::GLOG_FATAL, strLogPath1.c_str());
LOG(INFO) << "infoinfo";
Sleep(1000);
LOG(WARNING) << "wwwww";
LOG(WARNING) << "wwwww";
LOG(ERROR) << "eeeeee";
Sleep(2000);
//LOG(FATAL) << "ffffff";
LOG(WARNING) << "wwwww";
LOG(WARNING) << "wwwww";
LOG(WARNING) << "wwwww";
google::ShutdownGoogleLogging();
I got two log files, one file contain all messages(INFO, WARNING and ERROR), and the other contain all WARNING and ERROR messages, but without INFO. This is quiet different from my expectation. I want all messages in one file, and don't like the WARNING and ERROR messages appear twice in different files.
It would be highly appreciated if someone can tell me the solution.
Thanks a lot in advance.
You probably already have a solution for your problem but I will post this anyway for other users.
glog is not designed for logging in one file as far as I know. Therefore you can't do what you want using only glog.
However there are other solutions for your problem.
First: Write your own little logging library. This isn't very complicated and is a great Programming training ;)
Second: For *nix only. Activate logging to stderr in glog using the logtostderr-Flag and redirect the output from stderr to the desired log file.
FLAGS_logtostderr=1;
LOG(INFO) << "Info";
LOG(WARNING) << "Warning";
LOG(ERROR) << "Error";
and on the shell: ./MyProg 2>logFile
Last: Keep everything as it is and delete the logfiles you don't need. Either within your program using c/c++ or with a call to system()

Related Links

glog always create two files, which has nearly the same content

Categories

HOME
model-view-controller
algolia
gsm
customization
arcgis
overrides
mingw
opengl-es
grid
localhost
sequence
wowza
ldap-query
adroitlogic
saucelabs
hql
sha1
orange
project-reactor
accordion
project-structure
ampscript
keystone
android-wifi
procedural-generation
handle
apdu
android-6.0-marshmallow
proof-general
launchd
javapns
semantic-ui-react
boost-log
tikz
keil
webclient
mkdir
sdl-2
android-databinding
dotnetnuke-module
iterm2
office-interop
server-side-swift
delphi-xe
google-cloud-powershell
definition
django-tables2
beanshell
bioperl
kendo-scheduler
try-catch-finally
reloaddata
acceleo
group
stripes
cedar-bdd
optional-parameters
firebase-polymer
access-violation
disconnect
gdi
django-celery
database-administration
razorengine
javapackager
biginsights
om
page-flipping
winforms-interop
dcg
gcc-warning
chrome-mobile
jad
xmla
quickfixn
go-gin
nest-initiative
rpt
msdropdown
atg-dynamo
debuggervisualizer
banana-pi
hotlinking
rssi
mahara
code-complete
xcode5.1
octokit
static-class
ojb
extensibility
android-library
asp.net-4.0
dd4t
string-length
ntdll
ncml
nsregularexpression
motordriver
diazo
animationdrawable
mvcmailer
mcpd
mismatch
n2
xcdatamodel
iphone-maps
ihtmldocument2
moores-law

Resources

Encrypt Message