VirtualBox

Changeset 35559 in vbox for trunk/src/VBox/Main/webservice


Ignore:
Timestamp:
Jan 14, 2011 1:33:47 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
69443
Message:

Main/webservice: when daemonized use a release logger, default log destination is .VirtualBox/vboxwebsrv.log

Location:
trunk/src/VBox/Main/webservice
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/webservice/Makefile.kmk

    r35440 r35559  
    290290        $(VBOXWEB_OUT_DIR)/methodmaps.cpp \
    291291        $(VBOXWEB_OUT_DIR)/soapServer.cpp
     292
     293 vboxweb.cpp_DEFS = \
     294        VBOX_BUILD_TARGET=\"$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)\" \
     295        $(if $(VBOX_BLEEDING_EDGE),VBOX_BLEEDING_EDGE=\"$(VBOX_BLEEDING_EDGE)\",)
    292296
    293297 vboxwebsrv_ORDERDEPS = $(VBOXWEB_OUT_DIR)/gsoap_copy_all_ts
  • trunk/src/VBox/Main/webservice/vboxweb.cpp

    r35458 r35559  
    2929#include <VBox/VBoxAuth.h>
    3030#include <VBox/version.h>
     31
     32#include <package-generated.h>
    3133
    3234#include <iprt/buildconfig.h>
     
    4244#include <iprt/thread.h>
    4345#include <iprt/time.h>
     46#include <iprt/path.h>
     47#include <iprt/system.h>
    4448
    4549// workaround for compile problems on gcc 4.1
     
    107111
    108112bool                    g_fVerbose = false;             // be verbose
     113bool                    g_fStdOutLogging = true;        // log to stdout
    109114PRTSTREAM               g_pStrmLog = NULL;
    110115
     
    261266               const struct soap *soap)
    262267        : m_u(u),
    263           m_strThread(com::Utf8StrFmt("SoapQWrk%02d", m_u)),
     268          m_strThread(com::Utf8StrFmt("SQW%02d", m_u)),
    264269          m_pQ(&q)
    265270    {
     
    566571    va_end(args);
    567572
    568     const char *pcszPrefix = "[   ]";
    569     util::AutoReadLock thrLock(g_pThreadsLockHandle COMMA_LOCKVAL_SRC_POS);
    570     ThreadsMap::iterator it = g_mapThreads.find(RTThreadSelf());
    571     if (it != g_mapThreads.end())
    572         pcszPrefix = it->second.c_str();
    573     thrLock.release();
    574 
    575     // make a timestamp
    576     RTTIMESPEC ts;
    577     RTTimeLocalNow(&ts);
    578     RTTIME t;
    579     RTTimeExplode(&t, &ts);
    580 
    581     com::Utf8StrFmt strPrefix("%04d-%02d-%02d %02d:%02d:%02d %s",
    582                               t.i32Year, t.u8Month, t.u8MonthDay,
    583                               t.u8Hour, t.u8Minute, t.u8Second,
    584                               pcszPrefix);
    585 
    586     // synchronize the actual output
    587     util::AutoWriteLock logLock(g_pWebLogLockHandle COMMA_LOCKVAL_SRC_POS);
    588     // terminal
    589     RTPrintf("%s %s", strPrefix.c_str(), psz);
    590 
    591     // log file
    592     if (g_pStrmLog)
    593     {
    594         RTStrmPrintf(g_pStrmLog, "%s %s", strPrefix.c_str(), psz);
    595         RTStrmFlush(g_pStrmLog);
    596     }
     573    if (g_fStdOutLogging || g_pStrmLog)
     574    {
     575        const char *pcszPrefix = "[   ]";
     576        util::AutoReadLock thrLock(g_pThreadsLockHandle COMMA_LOCKVAL_SRC_POS);
     577        ThreadsMap::iterator it = g_mapThreads.find(RTThreadSelf());
     578        if (it != g_mapThreads.end())
     579            pcszPrefix = it->second.c_str();
     580        thrLock.release();
     581
     582        // make a timestamp
     583        RTTIMESPEC ts;
     584        RTTimeLocalNow(&ts);
     585        RTTIME t;
     586        RTTimeExplode(&t, &ts);
     587
     588        com::Utf8StrFmt strPrefix("%04d-%02d-%02d %02d:%02d:%02d %s",
     589                                  t.i32Year, t.u8Month, t.u8MonthDay,
     590                                  t.u8Hour, t.u8Minute, t.u8Second,
     591                                  pcszPrefix);
     592
     593        // synchronize the actual output
     594        util::AutoWriteLock logLock(g_pWebLogLockHandle COMMA_LOCKVAL_SRC_POS);
     595        // terminal
     596        if (g_fStdOutLogging)
     597            RTPrintf("%s %s", strPrefix.c_str(), psz);
     598
     599        // log file
     600        if (g_pStrmLog)
     601        {
     602            RTStrmPrintf(g_pStrmLog, "%s %s", strPrefix.c_str(), psz);
     603            RTStrmFlush(g_pStrmLog);
     604        }
    597605
    598606#ifdef DEBUG
    599     // logger instance
    600     RTLogLoggerEx(LOG_INSTANCE, RTLOGGRPFLAGS_DJ, LOG_GROUP, "%s %s", pcszPrefix, psz);
     607        // debug logger instance
     608        RTLogLoggerEx(LOG_INSTANCE, RTLOGGRPFLAGS_DJ, LOG_GROUP, "%s %s", pcszPrefix, psz);
    601609#endif
    602     logLock.release();
     610
     611        logLock.release();
     612    }
     613
     614    LogRel(("%s", psz));
    603615
    604616    RTStrFree(psz);
     
    799811    if (g_fDaemonize)
    800812    {
     813        /* prepare release logging */
     814        char szLogFile[RTPATH_MAX];
     815
     816        rc = com::GetVBoxUserHomeDirectory(szLogFile, sizeof(szLogFile));
     817        if (RT_FAILURE(rc))
     818             return RTMsgErrorExit(RTEXITCODE_FAILURE, "could not get base directory for logging: %Rrc", rc);
     819        rc = RTPathAppend(szLogFile, sizeof(szLogFile), "vboxwebsrv.log");
     820        if (RT_FAILURE(rc))
     821             return RTMsgErrorExit(RTEXITCODE_FAILURE, "could not construct logging path: %Rrc", rc);
     822
    801823        rc = RTProcDaemonizeUsingFork(false /* fNoChDir */, false /* fNoClose */, pszPidFile);
    802824        if (RT_FAILURE(rc))
    803825            return RTMsgErrorExit(RTEXITCODE_FAILURE, "failed to daemonize, rc=%Rrc. exiting.", rc);
     826
     827        /* From now on it's a waste of CPU cycles to send logging to stdout. */
     828        g_fStdOutLogging = false;
     829
     830        /* create release logger */
     831        PRTLOGGER loggerRelease;
     832        static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
     833        RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG;
     834#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
     835        fFlags |= RTLOGFLAGS_USECRLF;
     836#endif
     837        char szError[RTPATH_MAX + 128] = "";
     838        int vrc = RTLogCreateEx(&loggerRelease, fFlags, "all",
     839                                "VBOXWEBSRV_RELEASE_LOG", RT_ELEMENTS(s_apszGroups), s_apszGroups,
     840                                RTLOGDEST_FILE, szError, sizeof(szError), szLogFile);
     841        if (RT_SUCCESS(vrc))
     842        {
     843            /* some introductory information */
     844            RTTIMESPEC timeSpec;
     845            char szTmp[256];
     846            RTTimeSpecToString(RTTimeNow(&timeSpec), szTmp, sizeof(szTmp));
     847            RTLogRelLogger(loggerRelease, 0, ~0U,
     848                           "VirtualBox web service %s r%u %s (%s %s) release log\n"
     849#ifdef VBOX_BLEEDING_EDGE
     850                           "EXPERIMENTAL build " VBOX_BLEEDING_EDGE "\n"
     851#endif
     852                           "Log opened %s\n",
     853                           VBOX_VERSION_STRING, RTBldCfgRevision(), VBOX_BUILD_TARGET,
     854                           __DATE__, __TIME__, szTmp);
     855
     856            vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
     857            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
     858                RTLogRelLogger(loggerRelease, 0, ~0U, "OS Product: %s\n", szTmp);
     859            vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
     860            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
     861                RTLogRelLogger(loggerRelease, 0, ~0U, "OS Release: %s\n", szTmp);
     862            vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
     863            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
     864                RTLogRelLogger(loggerRelease, 0, ~0U, "OS Version: %s\n", szTmp);
     865            if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
     866                RTLogRelLogger(loggerRelease, 0, ~0U, "OS Service Pack: %s\n", szTmp);
     867
     868            /* the package type is interesting for Linux distributions */
     869            char szExecName[RTPATH_MAX];
     870            char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
     871            RTLogRelLogger(loggerRelease, 0, ~0U,
     872                           "Executable: %s\n"
     873                           "Process ID: %u\n"
     874                           "Package type: %s"
     875#ifdef VBOX_OSE
     876                           " (OSE)"
     877#endif
     878                           "\n",
     879                           pszExecName ? pszExecName : "unknown",
     880                           RTProcSelf(),
     881                           VBOX_PACKAGE_STRING);
     882
     883            /* register this logger as the release logger */
     884            RTLogRelSetDefaultInstance(loggerRelease);
     885
     886            /* Explicitly flush the log in case of VBOXWEBSRV_RELEASE_LOG=buffered. */
     887            RTLogFlush(loggerRelease);
     888        }
     889        else
     890            return RTMsgErrorExit(RTEXITCODE_FAILURE, "failed to open release log (%s, %Rrc)", szError, vrc);
    804891    }
    805892#endif
     
    857944                        RTTHREADTYPE_MAIN_WORKER,
    858945                        0,           // flags
    859                         "SoapQPumper");
     946                        "SQPmp");
    860947    if (RT_FAILURE(rc))
    861948        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Cannot start SOAP queue pumper thread: %Rrc", rc);
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