mturk       2004/11/13 10:52:10

  Modified:    daemon/src/native/nt/procrun/apps/prunsrv prunsrv.c
               daemon/src/native/nt/procrun/include log.h
               daemon/src/native/nt/procrun/src log.c
  Log:
  Add 'auto' option for StdError and StdOutput.
  When set to auto the log file will be appended and
  formated as $LogPath\stderr_YYYYMMDD.log
  
  Revision  Changes    Path
  1.11      +27 -18    
jakarta-commons/daemon/src/native/nt/procrun/apps/prunsrv/prunsrv.c
  
  Index: prunsrv.c
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/daemon/src/native/nt/procrun/apps/prunsrv/prunsrv.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- prunsrv.c 25 Sep 2004 14:25:30 -0000      1.10
  +++ prunsrv.c 13 Nov 2004 18:52:10 -0000      1.11
  @@ -36,7 +36,7 @@
   #define STDERR_FILENO 2
   
   typedef struct APX_STDWRAP {
  -    BOOL    bAppend;
  +    LPCWSTR szLogPath;
       LPCWSTR szStdOutFilename;
       LPCWSTR szStdErrFilename;
       HANDLE  hStdOutFile;
  @@ -197,8 +197,13 @@
    * If stderrfile is not specified it will
    * go to stdoutfile.
    */
  +
  +
  +
   static BOOL redirectStdStreams(APX_STDWRAP *lpWrapper)
   {
  +    BOOL aErr = FALSE;
  +    BOOL aOut = FALSE;
   
       /* Clear up the handles */    
       lpWrapper->fpStdErrFile = NULL;
  @@ -210,14 +215,17 @@
   
       /* redirect to file or console */
       if (lpWrapper->szStdOutFilename) {
  -        if (*lpWrapper->szStdOutFilename == L'+') {
  -            ++lpWrapper->szStdOutFilename;
  -            lpWrapper->bAppend = TRUE;
  +        if (lstrcmpiW(lpWrapper->szStdOutFilename, PRSRV_AUTO) == 0) {
  +            aOut = TRUE;
  +            lpWrapper->szStdOutFilename = apxLogFile(gPool,
  +                                                     lpWrapper->szLogPath,
  +                                                     NULL,
  +                                                     L"stdout_");
           }
           /* Delete the file if not in append mode
            * XXX: See if we can use the params instead of that.
            */
  -        if (!lpWrapper->bAppend)
  +        if (!aOut)
               DeleteFileW(lpWrapper->szStdOutFilename);
           lpWrapper->hStdOutFile = CreateFileW(lpWrapper->szStdOutFilename,
                                                GENERIC_WRITE | GENERIC_READ,
  @@ -243,12 +251,15 @@
               return FALSE;
       }
       if (lpWrapper->szStdErrFilename) {
  -        if (*lpWrapper->szStdErrFilename == L'+') {
  -            ++lpWrapper->szStdErrFilename;
  -            lpWrapper->bAppend = TRUE;
  +        if (lstrcmpiW(lpWrapper->szStdErrFilename, PRSRV_AUTO) == 0) {
  +            aErr = TRUE;
  +            lpWrapper->szStdErrFilename = apxLogFile(gPool,
  +                                                     lpWrapper->szLogPath,
  +                                                     NULL,
  +                                                     L"stderr_");
           }
  -        if (!lpWrapper->bAppend)
  -            DeleteFileW(lpWrapper->szStdOutFilename);
  +        if (!aErr)
  +            DeleteFileW(lpWrapper->szStdErrFilename);
           lpWrapper->hStdErrFile = CreateFileW(lpWrapper->szStdErrFilename,
                                                GENERIC_WRITE | GENERIC_READ,
                                                FILE_SHARE_READ | 
FILE_SHARE_WRITE,
  @@ -1193,15 +1204,13 @@
       apxLogWrite(APXLOG_MARK_DEBUG "Procrun log initialized");
   
       AplZeroMemory(&gStdwrap, sizeof(APX_STDWRAP));
  -
  -    gStdwrap.szStdErrFilename = SO_STDERROR;
  -    if (lpCmdline->dwCmdIndex == 1) {
  -        /* In debug mode allways use console */
  -        gStdwrap.szStdOutFilename = NULL;
  -    }
  -    else
  +    
  +    gStdwrap.szLogPath = SO_LOGPATH;
  +    /* In debug mode allways use console */
  +    if (lpCmdline->dwCmdIndex != 1) {
           gStdwrap.szStdOutFilename = SO_STDOUTPUT;
  -
  +        gStdwrap.szStdErrFilename = SO_STDERROR;
  +    }
       redirectStdStreams(&gStdwrap);
       switch (lpCmdline->dwCmdIndex) {
           case 1: /* Run Service as console application */
  
  
  
  1.2       +6 -0      
jakarta-commons/daemon/src/native/nt/procrun/include/log.h
  
  Index: log.h
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/daemon/src/native/nt/procrun/include/log.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- log.h     7 Apr 2004 11:23:46 -0000       1.1
  +++ log.h     13 Nov 2004 18:52:10 -0000      1.2
  @@ -49,6 +49,12 @@
   #define APXLOG_MARK_RAW     NULL, APXLOG_LEVEL_INFO,  FALSE, NULL, 0,
   #define APXLOG_MARK_SYSERR  NULL, APXLOG_LEVEL_ERROR, TRUE,  __FILE__, 
__LINE__, NULL
   
  +LPWSTR apxLogFile(
  +    APXHANDLE hPool,
  +    LPCWSTR szPath,
  +    LPCWSTR szPrefix,
  +    LPCWSTR szName
  +);
   
   HANDLE apxLogOpen(
       APXHANDLE hPool,
  
  
  
  1.2       +49 -0     jakarta-commons/daemon/src/native/nt/procrun/src/log.c
  
  Index: log.c
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/daemon/src/native/nt/procrun/src/log.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- log.c     7 Apr 2004 11:24:47 -0000       1.1
  +++ log.c     13 Nov 2004 18:52:10 -0000      1.2
  @@ -39,6 +39,55 @@
   static apx_logfile_st *_st_sys_loghandle = NULL;
   
   static apx_logfile_st  _st_sys_errhandle = { NULL, APXLOG_LEVEL_WARN, FALSE};
  +
  +
  +LPWSTR apxLogFile(
  +    APXHANDLE hPool,
  +    LPCWSTR szPath,
  +    LPCWSTR szPrefix,
  +    LPCWSTR szName)
  +{
  +    LPWSTR sRet;
  +    WCHAR sPath[MAX_PATH+1];
  +    WCHAR sName[MAX_PATH+1];
  +    SYSTEMTIME sysTime;
  +
  +    GetLocalTime(&sysTime);
  +    if (!szPath) {
  +        if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
  +            return INVALID_HANDLE_VALUE;
  +        lstrcatW(sPath, L"\\LogFiles\\");
  +        if (!szPrefix)
  +            lstrcatW(sPath, L"Apache");
  +        else
  +            lstrcatW(sPath, szPrefix);
  +        wsprintfW(sName, L"\\%s%04d%02d%02d.log",
  +                  szName,
  +                  sysTime.wYear,
  +                  sysTime.wMonth,
  +                  sysTime.wDay);
  +    }
  +    else {
  +        lstrcpyW(sPath, szPath);
  +        if (szPrefix)
  +            wsprintfW(sName, L"\\%s", szPrefix);
  +        else
  +            wsprintfW(sName, L"\\%s%04d%02d%02d.log",
  +                      szName,
  +                      sysTime.wYear,
  +                      sysTime.wMonth,
  +                      sysTime.wDay);
  +    }
  +    sRet = apxPoolAlloc(hPool, (MAX_PATH + 1) * sizeof(WCHAR));
  +    /* Set default level to info */
  +    CreateDirectoryW(sPath, NULL);
  +    
  +    lstrcpyW(sRet, sPath);
  +    lstrcatW(sRet, sName);
  +
  +    return sRet;
  +}
  +
   /* Open the log file 
    * TODO: format like standard apache error.log
    * Add the EventLogger
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to