示例#1
0
 static string
 formatMessage ( const Logger::Level level, const char *msg ) {
     ostringstream formatted_msg;
     formatted_msg << setw( 7 ) << left <<
             logLevelToString( level ) << "| " << msg;
     return formatted_msg.str( );
 }
示例#2
0
 void PrivateConsoleLogHandler::header(const qi::LogLevel verb, bool verbose) const
 {
   // display log level
   textColorAttr(reset);
   textColorFG(colorForHeader(verb));
   printf("%s ", logLevelToString(verb, verbose));
   textColorAttr(reset);
 }
示例#3
0
int Log_Writer::premakestr(char* m_buffer, LogLevel l)
{
    time_t now;
	now = time(&now);;
	struct tm vtm; 
    localtime_r(&now, &vtm);
    return snprintf(m_buffer, _LOG_BUFFSIZE, "%s: %02d-%02d %02d:%02d:%02d ", logLevelToString(l),
            vtm.tm_mon + 1, vtm.tm_mday, vtm.tm_hour, vtm.tm_min, vtm.tm_sec);
}
示例#4
0
文件: Logging.cpp 项目: vishnur/ufora
void Logger::logToStream(std::ostream& stream, LogLevel level, const char* filename, 
        int lineNumber, const std::string& message)
    {
    indentLogOstream(
        message,
        getMessagePrefix(logLevelToString(level), filename, lineNumber), 
        stream
        );
    }
示例#5
0
void
NotificationScreen::logMessage (const char   *component,
			  	CompLogLevel level,
			  	const char   *message)
{
    NotifyNotification *n;
    char               *logLevel, *homeDir;
    CompString         iconUri;
    int                timeout;
    NotifyUrgency      urgency;

    if (level > optionGetMaxLogLevel ())
    {
	screen->logMessage (component, level, message);
	return;
    }

    homeDir = getenv ("HOME");
    if (!homeDir)
	return;

    /* FIXME: when not installing manually, the image will likely reside
              in $PREFIX/share/compiz, not in the home dir */
    iconUri   = "file://";
    iconUri += homeDir;
    iconUri += "/" IMAGE_DIR "/compiz.png";
    logLevel = (char *) logLevelToString (level);

    n = notify_notification_new (logLevel, message,
				 iconUri.c_str ()
#ifndef HAVE_LIBNOTIFY_0_6_1
				 , NULL
#endif				 
				 );

    timeout = optionGetTimeout ();
    if (timeout > 0)
	timeout *= 1000;

    notify_notification_set_timeout (n, timeout);

    if (level == CompLogLevelFatal || level == CompLogLevelError)
	urgency = NOTIFY_URGENCY_CRITICAL;
    else if (level == CompLogLevelWarn)
	urgency = NOTIFY_URGENCY_NORMAL;
    else
	urgency = NOTIFY_URGENCY_LOW;

    notify_notification_set_urgency (n, urgency);

    notify_notification_show (n, NULL);
    g_object_unref (G_OBJECT (n));

    screen->logMessage (component, level, message);
}
示例#6
0
文件: main.c 项目: zmike/compiz
void
logMessage(const char *componentName,
           CompLogLevel level,
           const char *message)
{
   if (!debugOutput && level >= CompLogLevelDebug)
     return;

   fprintf(stderr, "%s (%s) - %s: %s\n",
           programName, componentName,
           logLevelToString(level), message);
}
 void PrivateConsoleLogHandler::header(const LogLevel verb) const
 {
   //display log level
   textColorAttr(reset);
   if (verb == fatal)
     textColorFG(magenta);
   if (verb == error)
     textColorFG(red);
   if (verb == warning)
     textColorFG(yellow);
   if (verb == info)
     textColorAttr(reset);
   if (verb == verbose)
     textColorAttr(dim);
   if (verb == debug)
     textColorAttr(dim);
   printf("%s ", logLevelToString(verb));
   textColorAttr(reset);
 }
void TailFileLogHandler::log(const qi::log::LogLevel verb,
                             const qi::os::timeval   date,
                             const char              *category,
                             const char              *msg,
                             const char              *file,
                             const char              *fct,
                             const int               line)
{
    if (verb > qi::log::verbosity() || _private->_file == NULL)
    {
        return;
    }
    else
    {
        fseek(_private->_file, 0, SEEK_END);

        std::string logline = qi::detail::logline(date, category, msg, file, fct, line);
        _private->_writeSize += fprintf(_private->_file, "%s %s", logLevelToString(verb), logline.c_str());
        fflush(_private->_file);
    }

    if (_private->_writeSize > FILESIZEMAX)
    {
        fclose(_private->_file);
        boost::filesystem::path filePath(_private->_fileName);
        boost::filesystem::path oldFilePath(_private->_fileName + ".old");

        boost::filesystem::copy_file(filePath,
                                     oldFilePath,
                                     boost::filesystem::copy_option::overwrite_if_exists);

        FILE* file = qi::os::fopen(filePath.make_preferred().string().c_str(), "w+");

        _private->_file = file;
        _private->_writeSize = 0;
    }
}
示例#9
0
std::ostream& operator<<(std::ostream& os, LogLevel level) {
  os << logLevelToString(level);
  return os;
}
示例#10
0
    void Logstream::flush(Tee *t) {
        const size_t MAX_LOG_LINE = 1024 * 10;

        // this ensures things are sane
        if ( doneSetup == 1717 ) {
            string msg = ss.str();
            
            string threadName = getThreadName();
            const char * type = logLevelToString(logLevel);

            size_t msgLen = msg.size();
            if ( msgLen > MAX_LOG_LINE )
                msgLen = MAX_LOG_LINE;

            const int spaceNeeded = (int)( msgLen + 64 /* for extra info */ + threadName.size());
            int bufSize = 128;
            while ( bufSize < spaceNeeded )
                bufSize += 128;

            BufBuilder b(bufSize);
            char* dateStr = b.grow(24);
            curTimeString(dateStr);
            dateStr[23] = ' '; // change null char to space

            if (!threadName.empty()) {
                b.appendChar( '[' );
                b.appendStr( threadName , false );
                b.appendChar( ']' );
                b.appendChar( ' ' );
            }

            for ( int i=0; i<indent; i++ )
                b.appendChar( '\t' );

            if ( type[0] ) {
                b.appendStr( type , false );
                b.appendStr( ": " , false );
            }

            if ( msg.size() > MAX_LOG_LINE ) {
                stringstream sss;
                sss << "warning: log line attempted (" << msg.size() / 1024 << "k) over max size(" << MAX_LOG_LINE / 1024 << "k)";
                sss << ", printing beginning and end ... ";
                b.appendStr( sss.str(), false );
                const char * xx = msg.c_str();
                b.appendBuf( xx , MAX_LOG_LINE / 3 );
                b.appendStr( " .......... ", false );
                b.appendStr( xx + msg.size() - ( MAX_LOG_LINE / 3 ) );
            }
            else {
                b.appendStr( msg );
            }

            string out( b.buf() , b.len() - 1);
            verify( b.len() < spaceNeeded );

            scoped_lock lk(mutex);

            if( t ) t->write(logLevel,out);
            if ( globalTees ) {
                for ( unsigned i=0; i<globalTees->size(); i++ )
                    (*globalTees)[i]->write(logLevel,out);
            }
#if defined(_WIN32)
            int fd = fileno( logfile );
            if ( _isatty( fd ) ) {
                fflush( logfile );
                writeUtf8ToWindowsConsole( out.data(), out.size() );
            }
#else
            if ( isSyslog ) {
                syslog( logLevelToSysLogLevel(logLevel) , "%s" , out.data() );
            }
#endif
            else if ( fwrite( out.data(), out.size(), 1, logfile ) ) {
                fflush(logfile);
            }
            else {
                int x = errno;
                cout << "Failed to write to logfile: " << errnoWithDescription(x) << ": " << out << endl;
            }
#ifdef POSIX_FADV_DONTNEED
            // This only applies to pages that have already been flushed
            RARELY posix_fadvise(fileno(logfile), 0, 0, POSIX_FADV_DONTNEED);
#endif
        }
        _init();
    }
示例#11
0
int LogWriter::premakestr(char* buffer, LogLevel l) {
    time_t now;
	now = time(&now);;
	struct tm vtm;
    localtime_r(&now, &vtm);
    return snprintf(buffer, M_LOG_BUFFSIZE, "[%d-%02d-%02d %02d:%02d:%02d] %s ",
            1900+vtm.tm_year, vtm.tm_mon + 1, vtm.tm_mday, vtm.tm_hour, vtm.tm_min, vtm.tm_sec, logLevelToString(l));
}
void ConsoleAppender::log(const LogLevel logLevel, const string loggerName, const string logMessage)
{
	if(logLevel <= this->logLevel)
		cout << getCurrentTime() << ' ' << logLevelToString(logLevel) << ' ' << "[" << loggerName << "] " << logMessage << std::endl;
}
static void
notifyLogMessage (const char   *component,
                  CompLogLevel level,
                  const char   *message)
{
    NotifyNotification *n;
    char               *logLevel, iconFile[256], *iconUri, *homeDir;
    int                maxLevel;

    NOTIFY_CORE (&core);
    NOTIFY_DISPLAY (core.displays);

    maxLevel = nd->opt[NOTIFY_DISPLAY_OPTION_MAX_LEVEL].value.i;
    if (level > maxLevel)
    {
        UNWRAP (nc, &core, logMessage);
        (*core.logMessage) (component, level, message);
        WRAP (nc, &core, logMessage, notifyLogMessage);

        return;
    }

    homeDir = getenv ("HOME");
    if (!homeDir)
        return;

    snprintf (iconFile, 256, "%s/%s/%s", homeDir, IMAGE_DIR, "compiz.png");

    iconUri = malloc (sizeof (char) * strlen (iconFile) + 8);
    if (!iconUri)
        return;

    sprintf (iconUri, "file://%s", iconFile);

    logLevel = (char *) logLevelToString (level);

    n = notify_notification_new (logLevel,
                                 message,
                                 iconUri
#if !defined (HAVE_LIBNOTIFY_0_6_1)
                                 , NULL
#endif
                                );

    notify_notification_set_timeout (n, nd->timeout);

    switch (level)
    {
    case CompLogLevelFatal:
    case CompLogLevelError:
        notify_notification_set_urgency (n, NOTIFY_URGENCY_CRITICAL);
        break;
    case CompLogLevelWarn:
        notify_notification_set_urgency (n, NOTIFY_URGENCY_NORMAL);
        break;
    default:
        notify_notification_set_urgency (n, NOTIFY_URGENCY_LOW);
        break;
    }

    if (!notify_notification_show (n, NULL))
        fprintf (stderr, "failed to send notification\n");

    g_object_unref (G_OBJECT (n));
    free (iconUri);

    UNWRAP (nc, &core, logMessage);
    (*core.logMessage) (component, level, message);
    WRAP (nc, &core, logMessage, notifyLogMessage);
}
示例#14
0
文件: Log.cpp 项目: nob13/jxvm
std::ostream & logStreamPreformat (const char * file, int line, LogLevel level) {
    return logStream (level) << "[" << logLevelToString (level) << "]" << threadName() << " " << countLogLevel(level) <<  " " << myBaseName(file) << ":" << line <<  " ";
}