Changeset 6444 in vbox for trunk/src/VBox/Main/ConsoleImpl.cpp
- Timestamp:
- Jan 22, 2008 2:16:09 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl.cpp
r6440 r6444 1157 1157 // IConsole methods 1158 1158 ///////////////////////////////////////////////////////////////////////////// 1159 1160 /* 1161 * Initialize the release logging facility. In case something 1162 * goes wrong, there will be no release logging. Maybe in the future 1163 * we can add some logic to use different file names in this case. 1164 * Note that the logic must be in sync with Machine::DeleteSettings(). 1165 */ 1166 static HRESULT consoleInitReleaseLog(const ComPtr <IMachine> machine, 1167 char szError[RTPATH_MAX + 128], int *pRc) 1168 { 1169 HRESULT hrc = S_OK; 1170 int vrc = VINF_SUCCESS; 1171 1172 Bstr logFolder; 1173 hrc = machine->COMGETTER(LogFolder) (logFolder.asOutParam()); 1174 CheckComRCReturnRC (hrc); 1175 1176 Utf8Str logDir = logFolder; 1177 1178 /* make sure the Logs folder exists */ 1179 Assert (!logDir.isEmpty()); 1180 if (!RTDirExists (logDir)) 1181 RTDirCreateFullPath (logDir, 0777); 1182 1183 Utf8Str logFile = Utf8StrFmt ("%s%cVBox.log", 1184 logDir.raw(), RTPATH_DELIMITER); 1185 Utf8Str pngFile = Utf8StrFmt ("%s%cVBox.png", 1186 logDir.raw(), RTPATH_DELIMITER); 1187 1188 /* 1189 * Age the old log files 1190 * Rename .(n-1) to .(n), .(n-2) to .(n-1), ..., and the last log file to .1 1191 * Overwrite target files in case they exist. 1192 */ 1193 ComPtr<IVirtualBox> virtualBox; 1194 machine->COMGETTER(Parent)(virtualBox.asOutParam()); 1195 ComPtr <ISystemProperties> systemProperties; 1196 virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); 1197 ULONG uLogHistoryCount = 3; 1198 systemProperties->COMGETTER(LogHistoryCount)(&uLogHistoryCount); 1199 if (uLogHistoryCount) 1200 { 1201 for (int i = uLogHistoryCount-1; i >= 0; i--) 1202 { 1203 Utf8Str *files[] = { &logFile, &pngFile }; 1204 Utf8Str oldName, newName; 1205 1206 for (unsigned int j = 0; j < ELEMENTS (files); ++ j) 1207 { 1208 if (i > 0) 1209 oldName = Utf8StrFmt ("%s.%d", files [j]->raw(), i); 1210 else 1211 oldName = *files [j]; 1212 newName = Utf8StrFmt ("%s.%d", files [j]->raw(), i + 1); 1213 /* If the old file doesn't exist, delete the new file (if it 1214 * exists) to provide correct rotation even if the sequence is 1215 * broken */ 1216 if (RTFileRename (oldName, newName, RTFILEMOVE_FLAGS_REPLACE) == 1217 VERR_FILE_NOT_FOUND) 1218 RTFileDelete (newName); 1219 } 1220 } 1221 } 1222 1223 PRTLOGGER loggerRelease; 1224 static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES; 1225 RTUINT fFlags = RTLOGFLAGS_PREFIX_TIME_PROG; 1226 #if defined (RT_OS_WINDOWS) || defined (RT_OS_OS2) 1227 fFlags |= RTLOGFLAGS_USECRLF; 1228 #endif 1229 vrc = RTLogCreateEx(&loggerRelease, fFlags, "all", 1230 "VBOX_RELEASE_LOG", ELEMENTS(s_apszGroups), s_apszGroups, 1231 RTLOGDEST_FILE, szError, sizeof(szError), logFile.raw()); 1232 if (VBOX_SUCCESS(vrc)) 1233 { 1234 /* some introductory information */ 1235 RTTIMESPEC timeSpec; 1236 char nowUct[64]; 1237 RTTimeSpecToString(RTTimeNow(&timeSpec), nowUct, sizeof(nowUct)); 1238 RTLogRelLogger(loggerRelease, 0, ~0U, 1239 "VirtualBox %s r%d %s (%s %s) release log\n" 1240 "Log opened %s\n", 1241 VBOX_VERSION_STRING, VBoxSVNRev (), VBOX_BUILD_TARGET, 1242 __DATE__, __TIME__, nowUct); 1243 1244 /* register this logger as the release logger */ 1245 RTLogRelSetDefaultInstance(loggerRelease); 1246 } 1247 *pRc = vrc; 1248 return RT_SUCCESS(vrc) ? hrc : E_FAIL; 1249 } 1159 1250 1160 1251 STDMETHODIMP Console::PowerUp (IProgress **aProgress) … … 1368 1459 task->mSavedStateFile = savedStateFile; 1369 1460 1370 int vrc = RTThreadCreate (NULL, Console::powerUpThread, (void *) task.get(), 1371 0, RTTHREADTYPE_MAIN_WORKER, 0, "VMPowerUp"); 1461 int vrc; 1462 char szError[RTPATH_MAX + 128] = ""; 1463 HRESULT hrc = consoleInitReleaseLog(mMachine, szError, &vrc); 1464 ComAssertMsgRCRet (SUCCEEDED (hrc), 1465 ("Failed to open release log (%s, %Vrc)", szError, vrc), 1466 hrc); 1467 vrc = RTThreadCreate (NULL, Console::powerUpThread, (void *) task.get(), 1468 0, RTTHREADTYPE_MAIN_WORKER, 0, "VMPowerUp"); 1372 1469 1373 1470 ComAssertMsgRCRet (vrc, ("Could not create VMPowerUp thread (%Vrc)\n", vrc), … … 5692 5789 do 5693 5790 { 5694 /*5695 * Initialize the release logging facility. In case something5696 * goes wrong, there will be no release logging. Maybe in the future5697 * we can add some logic to use different file names in this case.5698 * Note that the logic must be in sync with Machine::DeleteSettings().5699 */5700 5701 Bstr logFolder;5702 hrc = console->mMachine->COMGETTER(LogFolder) (logFolder.asOutParam());5703 CheckComRCBreakRC (hrc);5704 5705 Utf8Str logDir = logFolder;5706 5707 /* make sure the Logs folder exists */5708 Assert (!logDir.isEmpty());5709 if (!RTDirExists (logDir))5710 RTDirCreateFullPath (logDir, 0777);5711 5712 Utf8Str logFile = Utf8StrFmt ("%s%cVBox.log",5713 logDir.raw(), RTPATH_DELIMITER);5714 Utf8Str pngFile = Utf8StrFmt ("%s%cVBox.png",5715 logDir.raw(), RTPATH_DELIMITER);5716 5717 /*5718 * Age the old log files5719 * Rename .(n-1) to .(n), .(n-2) to .(n-1), ..., and the last log file to .15720 * Overwrite target files in case they exist.5721 */5722 ComPtr<IVirtualBox> virtualBox;5723 console->mMachine->COMGETTER(Parent)(virtualBox.asOutParam());5724 ComPtr <ISystemProperties> systemProperties;5725 virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());5726 ULONG uLogHistoryCount = 3;5727 systemProperties->COMGETTER(LogHistoryCount)(&uLogHistoryCount);5728 if (uLogHistoryCount)5729 {5730 for (int i = uLogHistoryCount-1; i >= 0; i--)5731 {5732 Utf8Str *files[] = { &logFile, &pngFile };5733 Utf8Str oldName, newName;5734 5735 for (unsigned int j = 0; j < ELEMENTS (files); ++ j)5736 {5737 if (i > 0)5738 oldName = Utf8StrFmt ("%s.%d", files [j]->raw(), i);5739 else5740 oldName = *files [j];5741 newName = Utf8StrFmt ("%s.%d", files [j]->raw(), i + 1);5742 /* If the old file doesn't exist, delete the new file (if it5743 * exists) to provide correct rotation even if the sequence is5744 * broken */5745 if (RTFileRename (oldName, newName, RTFILEMOVE_FLAGS_REPLACE) ==5746 VERR_FILE_NOT_FOUND)5747 RTFileDelete (newName);5748 }5749 }5750 }5751 5752 PRTLOGGER loggerRelease;5753 static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;5754 RTUINT fFlags = RTLOGFLAGS_PREFIX_TIME_PROG;5755 #if defined (RT_OS_WINDOWS) || defined (RT_OS_OS2)5756 fFlags |= RTLOGFLAGS_USECRLF;5757 #endif5758 char szError[RTPATH_MAX + 128] = "";5759 vrc = RTLogCreateEx(&loggerRelease, fFlags, "all",5760 "VBOX_RELEASE_LOG", ELEMENTS(s_apszGroups), s_apszGroups,5761 RTLOGDEST_FILE, szError, sizeof(szError), logFile.raw());5762 if (VBOX_SUCCESS(vrc))5763 {5764 /* some introductory information */5765 RTTIMESPEC timeSpec;5766 char nowUct[64];5767 RTTimeSpecToString(RTTimeNow(&timeSpec), nowUct, sizeof(nowUct));5768 RTLogRelLogger(loggerRelease, 0, ~0U,5769 "VirtualBox %s r%d %s (%s %s) release log\n"5770 "Log opened %s\n",5771 VBOX_VERSION_STRING, VBoxSVNRev (), VBOX_BUILD_TARGET,5772 __DATE__, __TIME__, nowUct);5773 5774 /* register this logger as the release logger */5775 RTLogRelSetDefaultInstance(loggerRelease);5776 }5777 else5778 {5779 hrc = setError (E_FAIL,5780 tr ("Failed to open release log (%s, %Vrc)"), szError, vrc);5781 break;5782 }5783 5784 5791 #ifdef VBOX_VRDP 5785 5792 if (VBOX_SUCCESS (vrc))
Note:
See TracChangeset
for help on using the changeset viewer.