]> git.saurik.com Git - apple/libc.git/blob - os/debug_private.h
Libc-1272.200.26.tar.gz
[apple/libc.git] / os / debug_private.h
1 /* Copyright (c) 2012-2013 Apple Inc. All rights reserved.
2 *
3 * @APPLE_LICENSE_HEADER_START@
4 *
5 * This file contains Original Code and/or Modifications of Original Code
6 * as defined in and that are subject to the Apple Public Source License
7 * Version 2.0 (the 'License'). You may not use this file except in
8 * compliance with the License. Please obtain a copy of the License at
9 * http://www.opensource.apple.com/apsl/ and read it before using this
10 * file.
11 *
12 * The Original Code and all software distributed under the License are
13 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
17 * Please see the License for the specific language governing rights and
18 * limitations under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #ifndef __OS_DEBUG_LOG_H__
24 #define __OS_DEBUG_LOG_H__
25
26 #include <Availability.h>
27 #include <TargetConditionals.h>
28
29 #include <os/base_private.h>
30 #include <stdarg.h>
31
32 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0)
33 OS_FORMAT_PRINTF(1, 2)
34 extern void
35 _os_debug_log(const char *msg, ...);
36
37 /* The os_debug_log macros insert spaces before the message. If logging to a file,
38 * the spaces will be replaced by a timestamp. If logging to syslog, they will
39 * be skipped (syslog knows what time it is). There are 20 spaces because the
40 * timestamp is printed as %16llu + 4 spaces before the next column.
41 * 10^16 ns = 3.8 months. Don't run your process in _debug for that long. This
42 * isn't syslog.
43 */
44 #define _OS_DEBUG_LOG_PREFIX " "
45
46 #define os_debug_log(tag, fmt, ...) __extension__({\
47 _os_debug_log(_OS_DEBUG_LOG_PREFIX "%s: " fmt, tag, ## __VA_ARGS__); \
48 })
49
50 #define os_debug_log_ctx(tag, ctx, fmt, ...) __extension__({\
51 _os_debug_log(_OS_DEBUG_LOG_PREFIX "[%p] %s: " fmt, ctx, tag, ## __VA_ARGS__); \
52 })
53
54 /* This is useful for clients who wish for the messages generated by os_debug_log()
55 * or os_assumes() failures to go somewhere other than (or in addition to) the
56 * system log, for example launchd or syslogd itself. If you don't wish for the
57 * message to be logged to the system log, then return true (to indicate that
58 * the message has been handled). If you want the default behavior, return
59 * false. Please use this macro, rather than directly declaring a function,
60 * since the declaration magic may change in the future.
61 */
62 #define os_debug_log_redirect(func) \
63 __attribute__((__used__)) \
64 __attribute__((__visibility__("default"))) \
65 bool _os_debug_log_redirect_func(const char *msg) { \
66 return func(msg); \
67 }
68
69 # pragma mark -
70 # pragma mark Private To Libc
71
72 // str must be modifiable (non-const)!
73 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0)
74 extern void
75 _os_debug_log_error_str(char *str);
76
77 #endif /* __OS_DEBUG_LOG_H__ */