WebKitLogging.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2005, 2007 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  14. * its contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #import "WebKitLogging.h"
  29. #if !LOG_DISABLED
  30. WTFLogChannel WebKitLogTextInput = { 0x00000010, "WebKitLogLevel", WTFLogChannelOff };
  31. WTFLogChannel WebKitLogTiming = { 0x00000020, "WebKitLogLevel", WTFLogChannelOff };
  32. WTFLogChannel WebKitLogLoading = { 0x00000040, "WebKitLogLevel", WTFLogChannelOff };
  33. WTFLogChannel WebKitLogFontCache = { 0x00000100, "WebKitLogLevel", WTFLogChannelOff };
  34. WTFLogChannel WebKitLogFontSubstitution = { 0x00000200, "WebKitLogLevel", WTFLogChannelOff };
  35. WTFLogChannel WebKitLogDownload = { 0x00000800, "WebKitLogLevel", WTFLogChannelOff };
  36. WTFLogChannel WebKitLogDocumentLoad = { 0x00001000, "WebKitLogLevel", WTFLogChannelOff };
  37. WTFLogChannel WebKitLogPlugins = { 0x00002000, "WebKitLogLevel", WTFLogChannelOff };
  38. WTFLogChannel WebKitLogEvents = { 0x00010000, "WebKitLogLevel", WTFLogChannelOff };
  39. WTFLogChannel WebKitLogView = { 0x00020000, "WebKitLogLevel", WTFLogChannelOff };
  40. WTFLogChannel WebKitLogRedirect = { 0x00040000, "WebKitLogLevel", WTFLogChannelOff };
  41. WTFLogChannel WebKitLogPageCache = { 0x00080000, "WebKitLogLevel", WTFLogChannelOff };
  42. WTFLogChannel WebKitLogCacheSizes = { 0x00100000, "WebKitLogLevel", WTFLogChannelOff };
  43. WTFLogChannel WebKitLogFormDelegate = { 0x00200000, "WebKitLogLevel", WTFLogChannelOff };
  44. WTFLogChannel WebKitLogFileDatabaseActivity = { 0x00400000, "WebKitLogLevel", WTFLogChannelOff };
  45. WTFLogChannel WebKitLogHistory = { 0x00800000, "WebKitLogLevel", WTFLogChannelOff };
  46. WTFLogChannel WebKitLogBindings = { 0x01000000, "WebKitLogLevel", WTFLogChannelOff };
  47. WTFLogChannel WebKitLogFontSelection = { 0x02000000, "WebKitLogLevel", WTFLogChannelOff };
  48. WTFLogChannel WebKitLogEncoding = { 0x04000000, "WebKitLogLevel", WTFLogChannelOff };
  49. WTFLogChannel WebKitLogLiveConnect = { 0x08000000, "WebKitLogLevel", WTFLogChannelOff };
  50. WTFLogChannel WebKitLogBackForward = { 0x10000000, "WebKitLogLevel", WTFLogChannelOff };
  51. WTFLogChannel WebKitLogProgress = { 0x20000000, "WebKitLogLevel", WTFLogChannelOff };
  52. WTFLogChannel WebKitLogPluginEvents = { 0x40000000, "WebKitLogLevel", WTFLogChannelOff };
  53. WTFLogChannel WebKitLogIconDatabase = { 0x80000000, "WebKitLogLevel", WTFLogChannelOff };
  54. static void initializeLogChannel(WTFLogChannel *channel)
  55. {
  56. NSString *logLevelString = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithUTF8String:channel->defaultName]];
  57. // If there's no log level string from the user defaults, don't obliterate the compiled in values.
  58. if (logLevelString) {
  59. channel->state = WTFLogChannelOff;
  60. unsigned logLevel;
  61. if (![[NSScanner scannerWithString:logLevelString] scanHexInt:&logLevel])
  62. NSLog(@"unable to parse hex value for %s (%@), logging is off", channel->defaultName, logLevelString);
  63. if ((logLevel & channel->mask) == channel->mask)
  64. channel->state = WTFLogChannelOn;
  65. }
  66. }
  67. void WebKitInitializeLoggingChannelsIfNecessary()
  68. {
  69. static bool haveInitializedLoggingChannels = false;
  70. if (haveInitializedLoggingChannels)
  71. return;
  72. haveInitializedLoggingChannels = true;
  73. initializeLogChannel(&WebKitLogTiming);
  74. initializeLogChannel(&WebKitLogLoading);
  75. initializeLogChannel(&WebKitLogFontCache);
  76. initializeLogChannel(&WebKitLogFontSubstitution);
  77. initializeLogChannel(&WebKitLogDownload);
  78. initializeLogChannel(&WebKitLogDocumentLoad);
  79. initializeLogChannel(&WebKitLogPlugins);
  80. initializeLogChannel(&WebKitLogEvents);
  81. initializeLogChannel(&WebKitLogView);
  82. initializeLogChannel(&WebKitLogRedirect);
  83. initializeLogChannel(&WebKitLogPageCache);
  84. initializeLogChannel(&WebKitLogCacheSizes);
  85. initializeLogChannel(&WebKitLogFormDelegate);
  86. initializeLogChannel(&WebKitLogFileDatabaseActivity);
  87. initializeLogChannel(&WebKitLogHistory);
  88. initializeLogChannel(&WebKitLogBindings);
  89. initializeLogChannel(&WebKitLogFontSelection);
  90. initializeLogChannel(&WebKitLogEncoding);
  91. initializeLogChannel(&WebKitLogLiveConnect);
  92. initializeLogChannel(&WebKitLogBackForward);
  93. initializeLogChannel(&WebKitLogProgress);
  94. initializeLogChannel(&WebKitLogPluginEvents);
  95. initializeLogChannel(&WebKitLogIconDatabase);
  96. initializeLogChannel(&WebKitLogTextInput);
  97. }
  98. #endif // !LOG_DISABLED
  99. void ReportDiscardedDelegateException(SEL delegateSelector, id exception)
  100. {
  101. if ([exception isKindOfClass:[NSException class]])
  102. NSLog(@"*** WebKit discarded an uncaught exception in the %s delegate: <%@> %@",
  103. sel_getName(delegateSelector), [exception name], [exception reason]);
  104. else
  105. NSLog(@"*** WebKit discarded an uncaught exception in the %s delegate: %@",
  106. sel_getName(delegateSelector), exception);
  107. }