static QStringList allLogLevelStrings() { QStringList result; for (int i = static_cast<int>(LoggerMinLevel); i <= static_cast<int>(LoggerMaxLevel); ++i) result << logLevelName(static_cast<LoggerLevel>(i)); return result; }
QString LogLevelOption::description(CommandType command) const { Q_UNUSED(command); return Tr::tr("%1 <level>\n" "\tUse the specified log level.\n" "\tPossible values are '%2'.\n" "\tThe default is '%3'.\n").arg(longRepresentation(), allLogLevelStrings().join(QLatin1String("', '")), logLevelName(defaultLogLevel())); }
QString ShowProgressOption::description(CommandType command) const { Q_UNUSED(command); QString desc = Tr::tr("%1\n" "\tShow a progress bar. Implies '%2=%3'.\n").arg(longRepresentation(), loglevelLongRepresentation(), logLevelName(LoggerMinLevel)); return desc += Tr::tr("\tThis option is mutually exclusive with '%1'.\n") .arg(logTimeRepresentation()); }
QString LogTimeOption::description(CommandType command) const { Q_UNUSED(command); QString desc = Tr::tr("%1\n\tLog the time that the operations involved in this command take.\n") .arg(longRepresentation()); desc += Tr::tr("\tThis option is implied in log levels '%1' and higher.\n") .arg(logLevelName(LoggerDebug)); return desc += Tr::tr("\tThis option is mutually exclusive with '%1'.\n") .arg(showProgressRepresentation()); }
void LogLevelOption::doParse(const QString &representation, QStringList &input) { const QString levelString = getArgument(representation, input); const QList<LoggerLevel> levels = QList<LoggerLevel>() << LoggerError << LoggerWarning << LoggerInfo << LoggerDebug << LoggerTrace; foreach (LoggerLevel l, levels) { if (logLevelName(l) == levelString) { m_logLevel = l; return; } } throw ErrorInfo(Tr::tr("Invalid use of option '%1': Unknown log level '%2'.\nUsage: %3") .arg(representation, levelString, description(command()))); }
void CoutLogger::doWrite(const log::LogLevel level, const std::string& msg) { static boost::mutex writeMutex; boost::mutex::scoped_lock l(writeMutex); std::cout << '[' << boost::posix_time::second_clock::local_time() << " " << boost::this_thread::get_id() << " "<< logLevelName(level) << "] " << msg << std::endl; }