1 /* $Id: logrel.cpp $ */
3 * Runtime VBox - Release Logger.
7 * Copyright (C) 2006-2016 Oracle Corporation
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.
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.
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.
28 /*********************************************************************************************************************************
30 *********************************************************************************************************************************/
32 #include "internal/iprt.h"
35 # include <iprt/alloc.h>
36 # include <iprt/process.h>
37 # include <iprt/semaphore.h>
38 # include <iprt/thread.h>
42 # include <iprt/file.h>
43 # include <iprt/path.h>
45 #include <iprt/time.h>
47 #include <iprt/assert.h>
49 #include <iprt/param.h>
51 #include <iprt/stdarg.h>
52 #include <iprt/string.h>
53 #include <iprt/ctype.h>
55 # include <iprt/alloca.h>
60 /*********************************************************************************************************************************
62 *********************************************************************************************************************************/
64 /** Default release logger instance. */
65 extern "C" DECLIMPORT(RTLOGGERRC
) g_RelLogger
;
67 /** Default release logger instance. */
68 static PRTLOGGER g_pRelLogger
;
72 RTDECL(PRTLOGGER
) RTLogRelGetDefaultInstance(void)
80 RT_EXPORT_SYMBOL(RTLogRelGetDefaultInstance
);
83 RTDECL(PRTLOGGER
) RTLogRelGetDefaultInstanceEx(uint32_t fFlagsAndGroup
)
86 PRTLOGGER pLogger
= &g_RelLogger
;
88 PRTLOGGER pLogger
= g_pRelLogger
;
92 if (pLogger
->fFlags
& RTLOGFLAGS_DISABLED
)
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
)))
106 RT_EXPORT_SYMBOL(RTLogRelGetDefaultInstanceEx
);
111 * Sets the default logger instance.
113 * @returns iprt status code.
114 * @param pLogger The new default release logger instance.
116 RTDECL(PRTLOGGER
) RTLogRelSetDefaultInstance(PRTLOGGER pLogger
)
118 return ASMAtomicXchgPtrT(&g_pRelLogger
, pLogger
, PRTLOGGER
);
120 RT_EXPORT_SYMBOL(RTLogRelSetDefaultInstance
);
125 * Write to a logger instance, defaulting to the release one.
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.
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.
138 RTDECL(void) RTLogRelLoggerV(PRTLOGGER pLogger
, unsigned fFlags
, unsigned iGroup
, const char *pszFormat
, va_list args
)
141 * A NULL logger means default instance.
145 pLogger
= RTLogRelGetDefaultInstance();
149 RTLogLoggerExV(pLogger
, fFlags
, iGroup
, pszFormat
, args
);
151 RT_EXPORT_SYMBOL(RTLogRelLoggerV
);
155 * vprintf like function for writing to the default release log.
157 * @param pszFormat Printf like format string.
158 * @param args Optional arguments as specified in pszFormat.
160 * @remark The API doesn't support formatting of floating point numbers at the moment.
162 RTDECL(void) RTLogRelPrintfV(const char *pszFormat
, va_list args
)
164 RTLogRelLoggerV(NULL
, 0, ~0U, pszFormat
, args
);
166 RT_EXPORT_SYMBOL(RTLogRelPrintfV
);
170 * Changes the buffering setting of the default release logger.
172 * This can be used for optimizing longish logging sequences.
174 * @returns The old state.
175 * @param fBuffered The new state.
177 RTDECL(bool) RTLogRelSetBuffering(bool fBuffered
)
179 PRTLOGGER pLogger
= RTLogRelGetDefaultInstance();
181 return RTLogSetBuffering(pLogger
, fBuffered
);
184 RT_EXPORT_SYMBOL(RTLogRelSetBuffering
);