I wrote a qt small console utility for testing database connectivity, the code block is:
db.setHostName("hostIP");
db.setDatabaseName("name");
db.setUserName("uid");
db.setPassword("pw");
db.setPort(1521);
while(true)
{
if (db.open())
{
qDebug()<<"OPEN";
db.close();
}
else
{
qDebug()<<"YOU MESSED UP "<<db.lastError().text();
}
}
the console output when the database is down or cannot be connected can be seen in the console output, what I want is to tee the timestamp also.
Is there a way to print the event timestamp on the console along with the qDebug messages ???
You could install a message handler and print out the timestamp before every message. See the documentation of qInstallMessageHandler
for this.
With this solution you don't have to add QTimer::currentTime()
on every call of qDebug()
.
Sure you can. For doing so you can use QTime class, i.e.:
qDebug() << QTime::currentTime().toString() << "YOU MESSED UP "<< db.lastError().text();
Or, in the same way you can print out the date and time information with using QDateTime::currentDateTime()
function.
If you are on linux, you can set QT_MESSAGE_PATTERN
environment variable,as explained here:
QT_MESSAGE_PATTERN="[%{type}] %{appname} (%{file}:%{line}) - %{message}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With