1 | /* $Id: logrel.cpp 69111 2017-10-17 14:26:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Runtime VBox - Release Logger.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-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 | * 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 <iprt/log.h>
|
---|
32 | #include "internal/iprt.h"
|
---|
33 |
|
---|
34 | #ifndef IN_RC
|
---|
35 | # include <iprt/alloc.h>
|
---|
36 | # include <iprt/process.h>
|
---|
37 | # include <iprt/semaphore.h>
|
---|
38 | # include <iprt/thread.h>
|
---|
39 | # include <iprt/mp.h>
|
---|
40 | #endif
|
---|
41 | #ifdef IN_RING3
|
---|
42 | # include <iprt/file.h>
|
---|
43 | # include <iprt/path.h>
|
---|
44 | #endif
|
---|
45 | #include <iprt/time.h>
|
---|
46 | #include <iprt/asm.h>
|
---|
47 | #include <iprt/assert.h>
|
---|
48 | #include <iprt/err.h>
|
---|
49 | #include <iprt/param.h>
|
---|
50 |
|
---|
51 | #include <iprt/stdarg.h>
|
---|
52 | #include <iprt/string.h>
|
---|
53 | #include <iprt/ctype.h>
|
---|
54 | #ifdef IN_RING3
|
---|
55 | # include <iprt/alloca.h>
|
---|
56 | # include <stdio.h>
|
---|
57 | #endif
|
---|
58 |
|
---|
59 |
|
---|
60 | /*********************************************************************************************************************************
|
---|
61 | * Global Variables *
|
---|
62 | *********************************************************************************************************************************/
|
---|
63 | #ifdef IN_RC
|
---|
64 | /** Default release logger instance. */
|
---|
65 | extern "C" DECLIMPORT(RTLOGGERRC) g_RelLogger;
|
---|
66 | #else /* !IN_RC */
|
---|
67 | /** Default release logger instance. */
|
---|
68 | static PRTLOGGER g_pRelLogger;
|
---|
69 | #endif /* !IN_RC */
|
---|
70 |
|
---|
71 |
|
---|
72 | RTDECL(PRTLOGGER) RTLogRelGetDefaultInstance(void)
|
---|
73 | {
|
---|
74 | #ifdef IN_RC
|
---|
75 | return &g_RelLogger;
|
---|
76 | #else /* !IN_RC */
|
---|
77 | return g_pRelLogger;
|
---|
78 | #endif /* !IN_RC */
|
---|
79 | }
|
---|
80 | RT_EXPORT_SYMBOL(RTLogRelGetDefaultInstance);
|
---|
81 |
|
---|
82 |
|
---|
83 | RTDECL(PRTLOGGER) RTLogRelGetDefaultInstanceEx(uint32_t fFlagsAndGroup)
|
---|
84 | {
|
---|
85 | #ifdef IN_RC
|
---|
86 | PRTLOGGER pLogger = &g_RelLogger;
|
---|
87 | #else /* !IN_RC */
|
---|
88 | PRTLOGGER pLogger = g_pRelLogger;
|
---|
89 | #endif /* !IN_RC */
|
---|
90 | if (pLogger)
|
---|
91 | {
|
---|
92 | if (pLogger->fFlags & RTLOGFLAGS_DISABLED)
|
---|
93 | pLogger = NULL;
|
---|
94 | else
|
---|
95 | {
|
---|
96 | uint16_t const fFlags = RT_LO_U16(fFlagsAndGroup);
|
---|
97 | uint16_t const iGroup = RT_HI_U16(fFlagsAndGroup);
|
---|
98 | if ( iGroup != UINT16_MAX
|
---|
99 | && ( (pLogger->afGroups[iGroup < pLogger->cGroups ? iGroup : 0] & (fFlags | (uint32_t)RTLOGGRPFLAGS_ENABLED))
|
---|
100 | != (fFlags | (uint32_t)RTLOGGRPFLAGS_ENABLED)))
|
---|
101 | pLogger = NULL;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | return pLogger;
|
---|
105 | }
|
---|
106 | RT_EXPORT_SYMBOL(RTLogRelGetDefaultInstanceEx);
|
---|
107 |
|
---|
108 |
|
---|
109 | #ifndef IN_RC
|
---|
110 | /**
|
---|
111 | * Sets the default logger instance.
|
---|
112 | *
|
---|
113 | * @returns iprt status code.
|
---|
114 | * @param pLogger The new default release logger instance.
|
---|
115 | */
|
---|
116 | RTDECL(PRTLOGGER) RTLogRelSetDefaultInstance(PRTLOGGER pLogger)
|
---|
117 | {
|
---|
118 | return ASMAtomicXchgPtrT(&g_pRelLogger, pLogger, PRTLOGGER);
|
---|
119 | }
|
---|
120 | RT_EXPORT_SYMBOL(RTLogRelSetDefaultInstance);
|
---|
121 | #endif /* !IN_RC */
|
---|
122 |
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Write to a logger instance, defaulting to the release one.
|
---|
126 | *
|
---|
127 | * This function will check whether the instance, group and flags makes up a
|
---|
128 | * logging kind which is currently enabled before writing anything to the log.
|
---|
129 | *
|
---|
130 | * @param pLogger Pointer to logger instance. If NULL the default release instance is attempted.
|
---|
131 | * @param fFlags The logging flags.
|
---|
132 | * @param iGroup The group.
|
---|
133 | * The value ~0U is reserved for compatibility with RTLogLogger[V] and is
|
---|
134 | * only for internal usage!
|
---|
135 | * @param pszFormat Format string.
|
---|
136 | * @param args Format arguments.
|
---|
137 | */
|
---|
138 | RTDECL(void) RTLogRelLoggerV(PRTLOGGER pLogger, unsigned fFlags, unsigned iGroup, const char *pszFormat, va_list args)
|
---|
139 | {
|
---|
140 | /*
|
---|
141 | * A NULL logger means default instance.
|
---|
142 | */
|
---|
143 | if (!pLogger)
|
---|
144 | {
|
---|
145 | pLogger = RTLogRelGetDefaultInstance();
|
---|
146 | if (!pLogger)
|
---|
147 | return;
|
---|
148 | }
|
---|
149 | RTLogLoggerExV(pLogger, fFlags, iGroup, pszFormat, args);
|
---|
150 | }
|
---|
151 | RT_EXPORT_SYMBOL(RTLogRelLoggerV);
|
---|
152 |
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * vprintf like function for writing to the default release log.
|
---|
156 | *
|
---|
157 | * @param pszFormat Printf like format string.
|
---|
158 | * @param args Optional arguments as specified in pszFormat.
|
---|
159 | *
|
---|
160 | * @remark The API doesn't support formatting of floating point numbers at the moment.
|
---|
161 | */
|
---|
162 | RTDECL(void) RTLogRelPrintfV(const char *pszFormat, va_list args)
|
---|
163 | {
|
---|
164 | RTLogRelLoggerV(NULL, 0, ~0U, pszFormat, args);
|
---|
165 | }
|
---|
166 | RT_EXPORT_SYMBOL(RTLogRelPrintfV);
|
---|
167 |
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Changes the buffering setting of the default release logger.
|
---|
171 | *
|
---|
172 | * This can be used for optimizing longish logging sequences.
|
---|
173 | *
|
---|
174 | * @returns The old state.
|
---|
175 | * @param fBuffered The new state.
|
---|
176 | */
|
---|
177 | RTDECL(bool) RTLogRelSetBuffering(bool fBuffered)
|
---|
178 | {
|
---|
179 | PRTLOGGER pLogger = RTLogRelGetDefaultInstance();
|
---|
180 | if (pLogger)
|
---|
181 | return RTLogSetBuffering(pLogger, fBuffered);
|
---|
182 | return false;
|
---|
183 | }
|
---|
184 | RT_EXPORT_SYMBOL(RTLogRelSetBuffering);
|
---|
185 |
|
---|