VirtualBox

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

Last change on this file since 76542 was 76474, checked in by vboxsync, 6 years ago

scm --fix-err-h src/ (bugref:9344)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: VBoxLogRelCreate.cpp 76474 2018-12-25 07:21:57Z vboxsync $ */
2/** @file
3 * MS COM / XPCOM Abstraction Layer - VBoxLogRelCreate.
4 */
5
6/*
7 * Copyright (C) 2005-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include <VBox/com/com.h>
23
24#include <iprt/buildconfig.h>
25#include <iprt/param.h>
26#include <iprt/string.h>
27#include <iprt/system.h>
28#include <iprt/process.h>
29#include <iprt/time.h>
30
31#include <iprt/errcore.h>
32#include <VBox/log.h>
33#include <VBox/version.h>
34#include "package-generated.h"
35
36
37
38namespace com
39{
40
41static const char *g_pszLogEntity = NULL;
42
43static DECLCALLBACK(void) vboxHeaderFooter(PRTLOGGER pReleaseLogger, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog)
44{
45 /* some introductory information */
46 static RTTIMESPEC s_TimeSpec;
47 char szTmp[256];
48 if (enmPhase == RTLOGPHASE_BEGIN)
49 RTTimeNow(&s_TimeSpec);
50 RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp));
51
52 switch (enmPhase)
53 {
54 case RTLOGPHASE_BEGIN:
55 {
56 bool fOldBuffered = RTLogSetBuffering(pReleaseLogger, true /*fBuffered*/);
57 pfnLog(pReleaseLogger,
58 "VirtualBox %s %s r%u %s (%s %s) release log\n"
59#ifdef VBOX_BLEEDING_EDGE
60 "EXPERIMENTAL build " VBOX_BLEEDING_EDGE "\n"
61#endif
62 "Log opened %s\n",
63 g_pszLogEntity, VBOX_VERSION_STRING, RTBldCfgRevision(),
64 RTBldCfgTargetDotArch(), __DATE__, __TIME__, szTmp);
65
66 pfnLog(pReleaseLogger, "Build Type: %s\n", KBUILD_TYPE);
67 int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
68 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
69 pfnLog(pReleaseLogger, "OS Product: %s\n", szTmp);
70 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
71 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
72 pfnLog(pReleaseLogger, "OS Release: %s\n", szTmp);
73 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
74 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
75 pfnLog(pReleaseLogger, "OS Version: %s\n", szTmp);
76 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp));
77 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
78 pfnLog(pReleaseLogger, "OS Service Pack: %s\n", szTmp);
79
80 vrc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szTmp, sizeof(szTmp));
81 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
82 pfnLog(pReleaseLogger, "DMI Product Name: %s\n", szTmp);
83 vrc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_VERSION, szTmp, sizeof(szTmp));
84 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
85 pfnLog(pReleaseLogger, "DMI Product Version: %s\n", szTmp);
86
87 uint64_t cbHostRam = 0, cbHostRamAvail = 0;
88 vrc = RTSystemQueryTotalRam(&cbHostRam);
89 if (RT_SUCCESS(vrc))
90 vrc = RTSystemQueryAvailableRam(&cbHostRamAvail);
91 if (RT_SUCCESS(vrc))
92 {
93 pfnLog(pReleaseLogger, "Host RAM: %lluMB", cbHostRam / _1M);
94 if (cbHostRam > _2G)
95 pfnLog(pReleaseLogger, " (%lld.%lldGB)",
96 cbHostRam / _1G, (cbHostRam % _1G) / (_1G / 10));
97 pfnLog(pReleaseLogger, " total, %lluMB", cbHostRamAvail / _1M);
98 if (cbHostRamAvail > _2G)
99 pfnLog(pReleaseLogger, " (%lld.%lldGB)",
100 cbHostRamAvail / _1G, (cbHostRamAvail % _1G) / (_1G / 10));
101 pfnLog(pReleaseLogger, " available\n");
102 }
103
104 /* the package type is interesting for Linux distributions */
105 char szExecName[RTPATH_MAX];
106 char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
107 pfnLog(pReleaseLogger,
108 "Executable: %s\n"
109 "Process ID: %u\n"
110 "Package type: %s"
111#ifdef VBOX_OSE
112 " (OSE)"
113#endif
114 "\n",
115 pszExecName ? pszExecName : "unknown",
116 RTProcSelf(),
117 VBOX_PACKAGE_STRING);
118 RTLogSetBuffering(pReleaseLogger, fOldBuffered);
119 break;
120 }
121 case RTLOGPHASE_PREROTATE:
122 pfnLog(pReleaseLogger, "Log rotated - Log started %s\n", szTmp);
123 break;
124
125 case RTLOGPHASE_POSTROTATE:
126 pfnLog(pReleaseLogger, "Log continuation - Log started %s\n", szTmp);
127 break;
128
129 case RTLOGPHASE_END:
130 pfnLog(pReleaseLogger, "End of log file - Log started %s\n", szTmp);
131 break;
132
133 default:
134 /* nothing */;
135 }
136}
137
138int VBoxLogRelCreate(const char *pcszEntity, const char *pcszLogFile,
139 uint32_t fFlags, const char *pcszGroupSettings,
140 const char *pcszEnvVarBase, uint32_t fDestFlags,
141 uint32_t cMaxEntriesPerGroup, uint32_t cHistory,
142 uint32_t uHistoryFileTime, uint64_t uHistoryFileSize,
143 PRTERRINFO pErrInfo)
144{
145 /* create release logger */
146 PRTLOGGER pReleaseLogger;
147 static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
148#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
149 fFlags |= RTLOGFLAGS_USECRLF;
150#endif
151 g_pszLogEntity = pcszEntity;
152 int vrc = RTLogCreateEx(&pReleaseLogger, fFlags, pcszGroupSettings,
153 pcszEnvVarBase, RT_ELEMENTS(s_apszGroups), s_apszGroups, fDestFlags,
154 vboxHeaderFooter, cHistory, uHistoryFileSize, uHistoryFileTime,
155 pErrInfo, pcszLogFile ? "%s" : NULL, pcszLogFile);
156 if (RT_SUCCESS(vrc))
157 {
158 /* make sure that we don't flood logfiles */
159 RTLogSetGroupLimit(pReleaseLogger, cMaxEntriesPerGroup);
160
161 /* explicitly flush the log, to have some info when buffering */
162 RTLogFlush(pReleaseLogger);
163
164 /* register this logger as the release logger */
165 RTLogRelSetDefaultInstance(pReleaseLogger);
166 }
167 return vrc;
168}
169
170} /* namespace com */
Note: See TracBrowser for help on using the repository browser.

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