VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/err/errinfolog.cpp@ 78052

Last change on this file since 78052 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/* $Id: errinfolog.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * IPRT - Error Info, Setters with logging.
4 */
5
6/*
7 * Copyright (C) 2010-2019 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "internal/iprt.h"
32#include <iprt/errcore.h>
33
34#include <iprt/assert.h>
35#include <iprt/string.h>
36#include <iprt/log.h>
37
38
39RTDECL(int) RTErrInfoLogAndSet(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszMsg)
40{
41 /* The logging: */
42 if (fFlags & RTERRINFO_LOG_F_RELEASE)
43 {
44 PRTLOGGER pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
45 if (pLogger)
46 RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoSet(%Rrc): %s\n", rc, pszMsg);
47 }
48
49 PRTLOGGER pLogger = RTLogGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
50 if (pLogger)
51 RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoSet(%Rrc): %s\n", rc, pszMsg);
52
53 /* The setting: */
54 if (pErrInfo)
55 {
56 AssertPtr(pErrInfo);
57 Assert((pErrInfo->fFlags & RTERRINFO_FLAGS_MAGIC_MASK) == RTERRINFO_FLAGS_MAGIC);
58
59 RTStrCopy(pErrInfo->pszMsg, pErrInfo->cbMsg, pszMsg);
60 pErrInfo->rc = rc;
61 pErrInfo->fFlags |= RTERRINFO_FLAGS_SET;
62 }
63 return rc;
64}
65
66
67RTDECL(int) RTErrInfoLogAndSetF(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, ...)
68{
69 va_list va;
70 va_start(va, pszFormat);
71 RTErrInfoLogAndSetV(pErrInfo, rc, iLogGroup, fFlags, pszFormat, va);
72 va_end(va);
73 return rc;
74}
75
76
77RTDECL(int) RTErrInfoLogAndSetV(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, va_list va)
78{
79 /* The logging: */
80 if (fFlags & RTERRINFO_LOG_F_RELEASE)
81 {
82 PRTLOGGER pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
83 if (pLogger)
84 RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoSet(%Rrc): %N\n", rc, pszFormat, &va);
85 }
86
87 PRTLOGGER pLogger = RTLogGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
88 if (pLogger)
89 RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoSet(%Rrc): %N\n", rc, pszFormat, &va);
90
91 /* The setting: */
92 if (pErrInfo)
93 {
94 AssertPtr(pErrInfo);
95 Assert((pErrInfo->fFlags & RTERRINFO_FLAGS_MAGIC_MASK) == RTERRINFO_FLAGS_MAGIC);
96
97 RTStrPrintfV(pErrInfo->pszMsg, pErrInfo->cbMsg, pszFormat, va);
98 pErrInfo->rc = rc;
99 pErrInfo->fFlags |= RTERRINFO_FLAGS_SET;
100 }
101 return rc;
102}
103
104
105RTDECL(int) RTErrInfoLogAndAdd(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszMsg)
106{
107 if (pErrInfo)
108 {
109 AssertPtr(pErrInfo);
110 if (pErrInfo->fFlags & RTERRINFO_FLAGS_SET)
111 RTStrCat(pErrInfo->pszMsg, pErrInfo->cbMsg, pszMsg);
112 else
113 {
114 while (*pszMsg == ' ')
115 pszMsg++;
116 return RTErrInfoSet(pErrInfo, rc, pszMsg);
117 }
118 }
119
120 /* The logging: */
121 if (fFlags & RTERRINFO_LOG_F_RELEASE)
122 {
123 PRTLOGGER pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
124 if (pLogger)
125 RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoAdd(%Rrc): %s\n", rc, pszMsg);
126 }
127
128 PRTLOGGER pLogger = RTLogGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
129 if (pLogger)
130 RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoAdd(%Rrc): %s\n", rc, pszMsg);
131
132 return rc;
133}
134
135
136RTDECL(int) RTErrInfoLogAndAddF(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, ...)
137{
138 va_list va;
139 va_start(va, pszFormat);
140 RTErrInfoLogAndAddV(pErrInfo, rc, iLogGroup, fFlags, pszFormat, va);
141 va_end(va);
142 return rc;
143}
144
145
146RTDECL(int) RTErrInfoLogAndAddV(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, va_list va)
147{
148 if (pErrInfo)
149 {
150 AssertPtr(pErrInfo);
151 Assert((pErrInfo->fFlags & RTERRINFO_FLAGS_MAGIC_MASK) == RTERRINFO_FLAGS_MAGIC);
152 if (pErrInfo->fFlags & RTERRINFO_FLAGS_SET)
153 {
154 char *pszOut = (char *)memchr(pErrInfo->pszMsg, '\0', pErrInfo->cbMsg - 2);
155 if (pszOut)
156 {
157 va_list va2;
158 va_copy(va2, va);
159 RTStrPrintfV(pszOut, &pErrInfo->pszMsg[pErrInfo->cbMsg] - pszOut, pszFormat, va2);
160 va_end(va2);
161 }
162 }
163 else
164 {
165 while (*pszFormat == ' ')
166 pszFormat++;
167 return RTErrInfoSetV(pErrInfo, rc, pszFormat, va);
168 }
169 }
170
171 /* The logging: */
172 if (fFlags & RTERRINFO_LOG_F_RELEASE)
173 {
174 PRTLOGGER pLogger = RTLogRelGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
175 if (pLogger)
176 RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoAdd(%Rrc): %N\n", rc, pszFormat, &va);
177 }
178
179 PRTLOGGER pLogger = RTLogGetDefaultInstanceEx(RT_MAKE_U32(RTLOGGRPFLAGS_LEVEL_1, iLogGroup));
180 if (pLogger)
181 RTLogLoggerEx(pLogger, RTLOGGRPFLAGS_LEVEL_1, iLogGroup, "RTErrInfoAdd(%Rrc): %N\n", rc, pszFormat, &va);
182
183 return rc;
184}
185
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