Exemplo n.º 1
0
void LogFactory::setAllLogLevel(LOGLEVEL level) {
	setDefaultLevel(level);
	map<string, Log>::iterator it;

	for ( it=logs.begin() ; it != logs.end(); it++ ) {
		(*it).second.setLevel(level);
		printf("Setting loglevel to %s for log %s\n", levelToChar(level), (*it).first.c_str());
	}

}
Exemplo n.º 2
0
//uses printf-style formatting
void Log::log(LOGLEVEL level, const char* msg, ...) {
	if (level > _level)
		return;
	
	va_list argp;
	va_start(argp, msg);
	printf("%s: %s ", levelToChar(level), _className.c_str());
	fflush(stdout);
	vfprintf(stderr, msg, argp);
	va_end(argp);	
}
Exemplo n.º 3
0
Arquivo: Log.cpp Projeto: KAlO2/Pea
void Log::write(Level level, const char* tag, const char* text)
{
    if(level < LEVEL_VERBOSE || level > LEVEL_FATAL)
        slog.w(TAG, "Log level %d not in range [%d-%d], ignored.",
               level, LEVEL_VERBOSE, LEVEL_FATAL);

    if(!tag)
        tag = "";

    if(level < this->level)
        return;  // silence

    char ch = levelToChar(level);
    if(colorful)
    {
#ifdef _WIN32
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), COLOR[level]);
#else
        printf("\e[1;%im%c/%s: %s\n", static_cast<int>(COLOR[level]), ch, tag, text);
#endif
    }
Exemplo n.º 4
0
std::ostream& Logging::getLog(LogLevel level, const char* file, int line) {
#ifdef WIN32
  SYSTEMTIME st, lt;
  GetSystemTime(&st);
  GetLocalTime(&lt);
#else
  timeval current_time;
  gettimeofday(&current_time, 0);
  struct tm* tm = localtime(&current_time.tv_sec);
#endif

  log_stream_
      << "[ " << levelToChar(level) << " | "
      // NOTE(mberlin): Disabled output of __FILE__ and __LINE__ since they are
      // not used in the current (3/2012) code base.
//      << file << ":" << line << " | "

      << setiosflags(ios::dec)
#ifdef WIN32
      << setw(2) << lt.wMonth << "/" << setw(2) << lt.wDay << " "
      << setfill('0') << setw(2) << lt.wHour << ":"
      << setfill('0') << setw(2) << lt.wMinute << ":"
      << setfill('0') << setw(2) << lt.wSecond << "."
      << setfill('0') << setw(3) << lt.wMilliseconds << " | "
#else
      << setw(2) << (tm->tm_mon + 1) << "/" << setw(2) << tm->tm_mday << " "
      << setfill('0') << setw(2) << tm->tm_hour << ":"
      << setfill('0') << setw(2) << tm->tm_min << ":"
      << setfill('0') << setw(2) << tm->tm_sec << "."
      << setfill('0') << setw(3) << (current_time.tv_usec / 1000) << " | "
#endif
      << left << setfill(' ') << setw(14)
      << boost::this_thread::get_id() << " ] "
      // Reset modifiers.
      << setfill(' ') << resetiosflags(ios::hex | ios::left);
  return log_stream_;
}