static void processBuffer(log_device_t* dev, struct log_msg *buf)
{
    int bytesWritten = 0;
    int err;
    AndroidLogEntry entry;
    char binaryMsgBuf[1024];

    if (dev->binary) {
        static bool hasOpenedEventTagMap = false;
        static EventTagMap *eventTagMap = NULL;

        if (!eventTagMap && !hasOpenedEventTagMap) {
            eventTagMap = android_openEventTagMap(EVENT_TAG_MAP_FILE);
            hasOpenedEventTagMap = true;
        }
        err = android_log_processBinaryLogBuffer(&buf->entry_v1, &entry,
                                                 eventTagMap,
                                                 binaryMsgBuf,
                                                 sizeof(binaryMsgBuf));
        //printf(">>> pri=%d len=%d msg='%s'\n",
        //    entry.priority, entry.messageLen, entry.message);
    } else {
        err = android_log_processLogBuffer(&buf->entry_v1, &entry);
    }
    if (err < 0) {
        goto error;
    }

    if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority)) {
        bool match = regexOk(entry);

        g_printCount += match;
        if (match || g_printItAnyways) {
            bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry);

            if (bytesWritten < 0) {
                logcat_panic(false, "output error");
            }
        }
    }

    g_outByteCount += bytesWritten;

    if (g_logRotateSizeKBytes > 0
        && (g_outByteCount / 1024) >= g_logRotateSizeKBytes
    ) {
        rotateLogs();
    }

error:
    //fprintf (stderr, "Error processing record\n");
    return;
}
static void processBuffer(log_device_t* dev, struct log_msg *buf)
{
    int bytesWritten = 0;
    int err;
    AndroidLogEntry entry;
    char binaryMsgBuf[1024];

    if (dev->binary) {
        err = android_log_processBinaryLogBuffer(&buf->entry_v1, &entry,
                                                 g_eventTagMap,
                                                 binaryMsgBuf,
                                                 sizeof(binaryMsgBuf));
        //printf(">>> pri=%d len=%d msg='%s'\n",
        //    entry.priority, entry.messageLen, entry.message);
    } else {
        err = android_log_processLogBuffer(&buf->entry_v1, &entry);
    }
    if (err < 0) {
        goto error;
    }

    if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority)) {
        if (false && g_devCount > 1) {
            binaryMsgBuf[0] = dev->label;
            binaryMsgBuf[1] = ' ';
            bytesWritten = write(g_outFD, binaryMsgBuf, 2);
            if (bytesWritten < 0) {
                perror("output error");
                exit(-1);
            }
        }

        bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry);

        if (bytesWritten < 0) {
            perror("output error");
            exit(-1);
        }
    }

    g_outByteCount += bytesWritten;

    if (g_logRotateSizeKBytes > 0
        && (g_outByteCount / 1024) >= g_logRotateSizeKBytes
    ) {
        rotateLogs();
    }

error:
    //fprintf (stderr, "Error processing record\n");
    return;
}
Exemple #3
0
 void signalProcessingThread() {
     while (true) {
         int actualSignal = 0;
         int status = sigwait( &asyncSignals, &actualSignal );
         fassert(16779, status == 0);
         switch (actualSignal) {
         case SIGUSR1:
             // log rotate signal
             fassert(16780, rotateLogs());
             break;
         default:
             // no one else should be here
             fassertFailed(16778);
             break;
         }
     }
 }
Exemple #4
0
void CBoostLog::openLog(const std::string& logfile, int numBackups,
                        int maxLogSize, LogLevel outLevel)
{
   {
      boost::mutex::scoped_lock guard(m_lock);
      delete m_log; m_log = NULL; // if there's an active log, close it

      m_logLevel = outLevel;
      m_filename = logfile;
      m_maxLogSize = maxLogSize;
      m_numBackups = numBackups;

      rotateLogs();

      // Open the log file (for appending if it exists)
      openFile(std::ios_base::app);
   }
   start();
}
Exemple #5
0
static void processBuffer(struct logger_entry *buf)
{
    int bytesWritten;
    int err;
    AndroidLogEntry entry;
    char binaryMsgBuf[1024];

    if (g_isBinary) {
        err = android_log_processBinaryLogBuffer(buf, &entry, g_eventTagMap,
                binaryMsgBuf, sizeof(binaryMsgBuf));
        //printf(">>> pri=%d len=%d msg='%s'\n",
        //    entry.priority, entry.messageLen, entry.message);
    } else {
        err = android_log_processLogBuffer(buf, &entry);
    }
    if (err < 0)
        goto error;

    bytesWritten = android_log_filterAndPrintLogLine(
                        g_logformat, g_outFD, &entry);

    if (bytesWritten < 0) {
        perror("output error");
        exit(-1);
    }

    g_outByteCount += bytesWritten;

    if (g_logRotateSizeKBytes > 0 
        && (g_outByteCount / 1024) >= g_logRotateSizeKBytes
    ) {
        rotateLogs();
    }

error:
    //fprintf (stderr, "Error processing record\n");
    return;
}
Exemple #6
0
void CBoostLog::writeMsg(const std::string& msg)
{
   bool rotateOk = true;

   // rotate the logs if the log file gets too big
   if (m_maxLogSize > 0 && 
      boost::filesystem::file_size(m_filename) > m_maxLogSize) {
         delete m_log; m_log = NULL;
         rotateOk = rotateLogs();
   }

   // note: always create a new file when we rotate for size
   if (!m_log) { 
      openFile(); 
   }

   if (m_log) {
      if (!rotateOk) {
         (*m_log) << "Log file could not be rotated, truncated instead." << std::endl;
      }
      (*m_log) << msg << std::endl;
   }
}
Exemple #7
0
		void setOutputFile(const QString & file,bool rotate,bool handle_qt_messages)
		{
			QMutexLocker lock(&mutex);
			
			if (handle_qt_messages)
				qInstallMsgHandler(QtMessageOutput);

			cleanup();
			
			if (bt::Exists(file) && rotate)
				rotateLogs(file);

			fptr = new QFile(file);
			if (!fptr->open(QIODevice::WriteOnly))
			{
				QString err = fptr->errorString();
				std::cout << "Failed to open log file " << file.toLocal8Bit().constData() << ": " 
						  << err.toLocal8Bit().constData() << std::endl;
				cleanup();
				return;
			}

			out = new QTextStream(fptr);
		}
Exemple #8
0
 virtual bool run(const string& ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
     rotateLogs();
     return 1;
 }        
 virtual bool run(const string& ns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
     bool didRotate = rotateLogs();
     if (didRotate)
         logProcessDetailsForLogRotate();
     return didRotate;
 }
Exemple #10
0
 virtual bool run(const string& ns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
     fassert(16175, rotateLogs());
     return 1;
 }
 virtual bool run(OperationContext* txn, const string& ns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
     bool didRotate = rotateLogs(serverGlobalParams.logRenameOnRotate);
     if (didRotate)
         logProcessDetailsForLogRotate();
     return didRotate;
 }
Exemple #12
0
 static void rotateLogsOrDie(int sig) {
     fassert(16176, rotateLogs());
 }