VirtualBox

source: vbox/trunk/src/VBox/Main/glue/VBoxLogRelCreate.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 KB
Line 
1/* $Id: VBoxLogRelCreate.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * MS COM / XPCOM Abstraction Layer - VBoxLogRelCreate.
4 */
5
6/*
7 * Copyright (C) 2005-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <VBox/com/utils.h>
33
34#include <iprt/buildconfig.h>
35#include <iprt/param.h>
36#include <iprt/string.h>
37#include <iprt/system.h>
38#include <iprt/process.h>
39#include <iprt/time.h>
40
41#include <iprt/errcore.h>
42#include <VBox/log.h>
43#include <VBox/version.h>
44#include "package-generated.h"
45
46
47
48namespace com
49{
50
51static const char *g_pszLogEntity = NULL;
52
53static DECLCALLBACK(void) vboxHeaderFooter(PRTLOGGER pReleaseLogger, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog)
54{
55 /* some introductory information */
56 static RTTIMESPEC s_TimeSpec;
57 char szTmp[256];
58 if (enmPhase == RTLOGPHASE_BEGIN)
59 RTTimeNow(&s_TimeSpec);
60 RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp));
61
62 switch (enmPhase)
63 {
64 case RTLOGPHASE_BEGIN:
65 {
66 bool fOldBuffered = RTLogSetBuffering(pReleaseLogger, true /*fBuffered*/);
67 pfnLog(pReleaseLogger,
68 "VirtualBox %s %s r%u %s (%s %s) release log\n"
69#ifdef VBOX_BLEEDING_EDGE
70 "EXPERIMENTAL build " VBOX_BLEEDING_EDGE "\n"
71#endif
72 "Log opened %s\n",
73 g_pszLogEntity, VBOX_VERSION_STRING, RTBldCfgRevision(),
74 RTBldCfgTargetDotArch(), __DATE__, __TIME__, szTmp);
75
76 pfnLog(pReleaseLogger, "Build Type: %s\n", KBUILD_TYPE);
77 int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
78 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
79 pfnLog(pReleaseLogger, "OS Product: %s\n", szTmp);
80 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
81 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
82 pfnLog(pReleaseLogger, "OS Release: %s\n", szTmp);
83 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
84 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
85 pfnLog(pReleaseLogger, "OS Version: %s\n", szTmp);
86 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp));
87 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
88 pfnLog(pReleaseLogger, "OS Service Pack: %s\n", szTmp);
89
90 vrc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szTmp, sizeof(szTmp));
91 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
92 pfnLog(pReleaseLogger, "DMI Product Name: %s\n", szTmp);
93 vrc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_VERSION, szTmp, sizeof(szTmp));
94 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
95 pfnLog(pReleaseLogger, "DMI Product Version: %s\n", szTmp);
96
97 RTSYSFWTYPE enmType;
98 vrc = RTSystemQueryFirmwareType(&enmType);
99 if (RT_SUCCESS(vrc))
100 {
101 pfnLog(pReleaseLogger, "Firmware type: %s\n", RTSystemFirmwareTypeName(enmType));
102 if (enmType == RTSYSFWTYPE_UEFI)
103 {
104 bool fValue;
105 vrc = RTSystemQueryFirmwareBoolean(RTSYSFWBOOL_SECURE_BOOT, &fValue);
106 if (RT_SUCCESS(vrc))
107 pfnLog(pReleaseLogger, "Secure Boot: %s\n", fValue ? "Enabled" : "Disabled");
108 else
109 pfnLog(pReleaseLogger, "Secure Boot: %Rrc\n", vrc);
110 }
111 }
112 else
113 pfnLog(pReleaseLogger, "Firmware type: failed - %Rrc\n", vrc);
114
115 uint64_t cbHostRam = 0, cbHostRamAvail = 0;
116 vrc = RTSystemQueryTotalRam(&cbHostRam);
117 if (RT_SUCCESS(vrc))
118 vrc = RTSystemQueryAvailableRam(&cbHostRamAvail);
119 if (RT_SUCCESS(vrc))
120 {
121 pfnLog(pReleaseLogger, "Host RAM: %lluMB", cbHostRam / _1M);
122 if (cbHostRam > _2G)
123 pfnLog(pReleaseLogger, " (%lld.%lldGB)",
124 cbHostRam / _1G, (cbHostRam % _1G) / (_1G / 10));
125 pfnLog(pReleaseLogger, " total, %lluMB", cbHostRamAvail / _1M);
126 if (cbHostRamAvail > _2G)
127 pfnLog(pReleaseLogger, " (%lld.%lldGB)",
128 cbHostRamAvail / _1G, (cbHostRamAvail % _1G) / (_1G / 10));
129 pfnLog(pReleaseLogger, " available\n");
130 }
131
132 /* the package type is interesting for Linux distributions */
133 char szExecName[RTPATH_MAX];
134 char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
135 pfnLog(pReleaseLogger,
136 "Executable: %s\n"
137 "Process ID: %u\n"
138 "Package type: %s"
139#ifdef VBOX_OSE
140 " (OSE)"
141#endif
142 "\n",
143 pszExecName ? pszExecName : "unknown",
144 RTProcSelf(),
145 VBOX_PACKAGE_STRING);
146 RTLogSetBuffering(pReleaseLogger, fOldBuffered);
147 break;
148 }
149
150 case RTLOGPHASE_PREROTATE:
151 pfnLog(pReleaseLogger, "Log rotated - Log started %s\n", szTmp);
152 break;
153
154 case RTLOGPHASE_POSTROTATE:
155 pfnLog(pReleaseLogger, "Log continuation - Log started %s\n", szTmp);
156 break;
157
158 case RTLOGPHASE_END:
159 pfnLog(pReleaseLogger, "End of log file - Log started %s\n", szTmp);
160 break;
161
162 default:
163 /* nothing */;
164 }
165}
166
167int VBoxLogRelCreate(const char *pcszEntity, const char *pcszLogFile,
168 uint32_t fFlags, const char *pcszGroupSettings,
169 const char *pcszEnvVarBase, uint32_t fDestFlags,
170 uint32_t cMaxEntriesPerGroup, uint32_t cHistory,
171 uint32_t uHistoryFileTime, uint64_t uHistoryFileSize,
172 PRTERRINFO pErrInfo)
173{
174 return VBoxLogRelCreateEx(pcszEntity, pcszLogFile,
175 fFlags, pcszGroupSettings,
176 pcszEnvVarBase, fDestFlags,
177 cMaxEntriesPerGroup, cHistory,
178 uHistoryFileTime, uHistoryFileSize,
179 NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/,
180 pErrInfo);
181}
182
183int VBoxLogRelCreateEx(const char *pcszEntity, const char *pcszLogFile,
184 uint32_t fFlags, const char *pcszGroupSettings,
185 const char *pcszEnvVarBase, uint32_t fDestFlags,
186 uint32_t cMaxEntriesPerGroup, uint32_t cHistory,
187 uint32_t uHistoryFileTime, uint64_t uHistoryFileSize,
188 const void *pOutputIf, void *pvOutputIfUser,
189 PRTERRINFO pErrInfo)
190{
191 /* create release logger */
192 PRTLOGGER pReleaseLogger;
193 static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
194#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
195 fFlags |= RTLOGFLAGS_USECRLF;
196#endif
197 g_pszLogEntity = pcszEntity;
198 int vrc = RTLogCreateEx(&pReleaseLogger, pcszEnvVarBase, fFlags, pcszGroupSettings, RT_ELEMENTS(s_apszGroups), s_apszGroups,
199 cMaxEntriesPerGroup, 0 /*cBufDescs*/, NULL /*paBufDescs*/, fDestFlags,
200 vboxHeaderFooter, cHistory, uHistoryFileSize, uHistoryFileTime,
201 (PCRTLOGOUTPUTIF)pOutputIf, pvOutputIfUser,
202 pErrInfo, pcszLogFile ? "%s" : NULL, pcszLogFile);
203 if (RT_SUCCESS(vrc))
204 {
205 /* explicitly flush the log, to have some info when buffering */
206 RTLogFlush(pReleaseLogger);
207
208 /* register this logger as the release logger */
209 RTLogRelSetDefaultInstance(pReleaseLogger);
210 }
211 return vrc;
212}
213
214} /* namespace com */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use