]>
Commit | Line | Data |
---|---|---|
23e20b00 | 1 | /* Copyright (c) 2012-2013 Apple Inc. All rights reserved. |
6465356a A |
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 | ||
23e20b00 A |
23 | #ifndef __OS_DEBUG_LOG_H__ |
24 | #define __OS_DEBUG_LOG_H__ | |
6465356a A |
25 | |
26 | #include <Availability.h> | |
27 | #include <TargetConditionals.h> | |
28 | ||
23e20b00 | 29 | #include <os/base_private.h> |
6465356a A |
30 | #include <stdarg.h> |
31 | ||
32 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0) | |
507116e3 | 33 | OS_FORMAT_PRINTF(1, 2) OS_COLD |
6465356a | 34 | extern void |
23e20b00 | 35 | _os_debug_log(const char *msg, ...); |
6465356a | 36 | |
23e20b00 | 37 | /* The os_debug_log macros insert spaces before the message. If logging to a file, |
6465356a A |
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 | */ | |
23e20b00 | 44 | #define _OS_DEBUG_LOG_PREFIX " " |
6465356a | 45 | |
23e20b00 A |
46 | #define os_debug_log(tag, fmt, ...) __extension__({\ |
47 | _os_debug_log(_OS_DEBUG_LOG_PREFIX "%s: " fmt, tag, ## __VA_ARGS__); \ | |
6465356a A |
48 | }) |
49 | ||
23e20b00 A |
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__); \ | |
6465356a A |
52 | }) |
53 | ||
23e20b00 | 54 | /* This is useful for clients who wish for the messages generated by os_debug_log() |
6465356a A |
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 | */ | |
23e20b00 | 62 | #define os_debug_log_redirect(func) \ |
6465356a | 63 | __attribute__((__used__)) \ |
507116e3 | 64 | __attribute__((__cold__)) \ |
6465356a | 65 | __attribute__((__visibility__("default"))) \ |
23e20b00 | 66 | bool _os_debug_log_redirect_func(const char *msg) { \ |
6465356a A |
67 | return func(msg); \ |
68 | } | |
69 | ||
70 | # pragma mark - | |
71 | # pragma mark Private To Libc | |
72 | ||
73 | // str must be modifiable (non-const)! | |
74 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0) | |
507116e3 | 75 | OS_COLD |
6465356a | 76 | extern void |
23e20b00 | 77 | _os_debug_log_error_str(char *str); |
6465356a | 78 | |
23e20b00 | 79 | #endif /* __OS_DEBUG_LOG_H__ */ |