VirtualBox

Changeset 28695 in vbox


Ignore:
Timestamp:
Apr 24, 2010 9:35:20 PM (15 years ago)
Author:
vboxsync
Message:

iprt/log: Added a write-through flag and a flush flag for file destination. Use RTFILE_O_APPEND (cleanup).

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/log.h

    r27615 r28695  
    324324    /** Show decimal timestamps with PREFIX_TSC and PREFIX_TS */
    325325    RTLOGFLAGS_DECIMAL_TS           = 0x00000080,
    326     /** Log flushing disabled. */
    327     RTLOGFLAGS_NO_FLUSH             = 0x00000100,
     326    /** Open the file in write through mode. */
     327    RTLOGFLAGS_WRITE_THROUGH        = 0x00000100,
     328    /** Flush the file to disk when flushing the buffer. */
     329    RTLOGFLAGS_FLUSH                = 0x00000200,
    328330    /** New lines should be prefixed with the write and read lock counts. */
    329331    RTLOGFLAGS_PREFIX_LOCK_COUNTS   = 0x00008000,
  • trunk/src/VBox/Runtime/common/log/log.cpp

    r28271 r28695  
    159159    { "dec",          sizeof("dec"         ) - 1,   RTLOGFLAGS_DECIMAL_TS,          false },
    160160    { "hex",          sizeof("hex"         ) - 1,   RTLOGFLAGS_DECIMAL_TS,          true  },
     161    { "writethru",    sizeof("writethru"   ) - 1,   RTLOGFLAGS_WRITE_THROUGH,       true  },
     162    { "writethrough", sizeof("writethrough") - 1,   RTLOGFLAGS_WRITE_THROUGH,       true  },
     163    { "flush",        sizeof("flush"       ) - 1,   RTLOGFLAGS_FLUSH,               true  },
    161164    { "lockcnts",     sizeof("lockcnts"    ) - 1,   RTLOGFLAGS_PREFIX_LOCK_COUNTS,  false },
    162165    { "cpuid",        sizeof("cpuid"       ) - 1,   RTLOGFLAGS_PREFIX_CPUID,        false },
     
    382385            if (pLogger->fDestFlags & RTLOGDEST_FILE)
    383386            {
    384                 if (!(pLogger->fFlags & RTLOGFLAGS_APPEND))
    385                     rc = RTFileOpen(&pLogger->File, pLogger->pszFilename,
    386                                     RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_WRITE);
     387                uint32_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_WRITE;
     388                if (pLogger->fFlags & RTLOGFLAGS_APPEND)
     389                    fOpen |= RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND;
    387390                else
    388                 {
    389                     /** @todo RTFILE_O_APPEND. */
    390                     rc = RTFileOpen(&pLogger->File, pLogger->pszFilename,
    391                                     RTFILE_O_WRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_WRITE);
    392                     if (RT_SUCCESS(rc))
    393                     {
    394                         rc = RTFileSeek(pLogger->File, 0, RTFILE_SEEK_END, NULL);
    395                         if (RT_FAILURE(rc))
    396                         {
    397                             RTFileClose(pLogger->File);
    398                             pLogger->File = NIL_RTFILE;
    399                         }
    400                     }
    401                 }
     391                    fOpen |= RTFILE_O_CREATE_REPLACE;
     392                if (pLogger->fFlags & RTLOGFLAGS_WRITE_THROUGH)
     393                    fOpen |= RTFILE_O_WRITE_THROUGH;
     394                rc = RTFileOpen(&pLogger->File, pLogger->pszFilename, fOpen);
    402395                if (RT_FAILURE(rc) && pszErrorMsg)
    403                     RTStrPrintf(pszErrorMsg, cchErrorMsg, "could not open file '%s'", pLogger->pszFilename);
     396                    RTStrPrintf(pszErrorMsg, cchErrorMsg, "could not open file '%s' (fOpen=%#x)", pLogger->pszFilename, fOpen);
    404397            }
    405398#endif  /* IN_RING3 */
     
    22082201# ifdef IN_RING3
    22092202    if (pLogger->fDestFlags & RTLOGDEST_FILE)
     2203    {
    22102204        RTFileWrite(pLogger->File, pLogger->achScratch, pLogger->offScratch, NULL);
     2205        if (pLogger->fFlags & RTLOGFLAGS_FLUSH)
     2206            RTFileFlush(pLogger->File);
     2207    }
    22112208# endif
    22122209
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette