You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
4.0 KiB

6 years ago
  1. /* Copyright 2014 Google Inc. All rights reserved.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #import "GTMSessionFetcher.h"
  16. // GTM HTTP Logging
  17. //
  18. // All traffic using GTMSessionFetcher can be easily logged. Call
  19. //
  20. // [GTMSessionFetcher setLoggingEnabled:YES];
  21. //
  22. // to begin generating log files.
  23. //
  24. // Log files are put into a folder on the desktop called "GTMHTTPDebugLogs"
  25. // unless another directory is specified with +setLoggingDirectory.
  26. //
  27. // In the iPhone simulator, the default logs location is the user's home
  28. // directory in ~/Library/Application Support. On the iPhone device, the
  29. // default logs location is the application's documents directory on the device.
  30. //
  31. // Tip: use the Finder's "Sort By Date" to find the most recent logs.
  32. //
  33. // Each run of an application gets a separate set of log files. An html
  34. // file is generated to simplify browsing the run's http transactions.
  35. // The html file includes javascript links for inline viewing of uploaded
  36. // and downloaded data.
  37. //
  38. // A symlink is created in the logs folder to simplify finding the html file
  39. // for the latest run of the application; the symlink is called
  40. //
  41. // AppName_http_log_newest.html
  42. //
  43. // For better viewing of XML logs, use Camino or Firefox rather than Safari.
  44. //
  45. // Each fetcher may be given a comment to be inserted as a label in the logs,
  46. // such as
  47. // [fetcher setCommentWithFormat:@"retrieve item %@", itemName];
  48. //
  49. // Projects may define STRIP_GTM_FETCH_LOGGING to remove logging code.
  50. #if !STRIP_GTM_FETCH_LOGGING
  51. @interface GTMSessionFetcher (GTMSessionFetcherLogging)
  52. // Note: the default logs directory is ~/Desktop/GTMHTTPDebugLogs; it will be
  53. // created as needed. If a custom directory is set, the directory should
  54. // already exist.
  55. + (void)setLoggingDirectory:(NSString *)path;
  56. + (NSString *)loggingDirectory;
  57. // client apps can turn logging on and off
  58. + (void)setLoggingEnabled:(BOOL)isLoggingEnabled;
  59. + (BOOL)isLoggingEnabled;
  60. // client apps can turn off logging to a file if they want to only check
  61. // the fetcher's log property
  62. + (void)setLoggingToFileEnabled:(BOOL)isLoggingToFileEnabled;
  63. + (BOOL)isLoggingToFileEnabled;
  64. // client apps can optionally specify process name and date string used in
  65. // log file names
  66. + (void)setLoggingProcessName:(NSString *)processName;
  67. + (NSString *)loggingProcessName;
  68. + (void)setLoggingDateStamp:(NSString *)dateStamp;
  69. + (NSString *)loggingDateStamp;
  70. // client apps can specify the directory for the log for this specific run,
  71. // typically to match the directory used by another fetcher class, like:
  72. //
  73. // [GTMSessionFetcher setLogDirectoryForCurrentRun:[GTMHTTPFetcher logDirectoryForCurrentRun]];
  74. //
  75. // Setting this overrides the logging directory, process name, and date stamp when writing
  76. // the log file.
  77. + (void)setLogDirectoryForCurrentRun:(NSString *)logDirectoryForCurrentRun;
  78. + (NSString *)logDirectoryForCurrentRun;
  79. // Prunes old log directories that have not been modified since the provided date.
  80. // This will not delete the current run's log directory.
  81. + (void)deleteLogDirectoriesOlderThanDate:(NSDate *)date;
  82. // internal; called by fetcher
  83. - (void)logFetchWithError:(NSError *)error;
  84. - (NSInputStream *)loggedInputStreamForInputStream:(NSInputStream *)inputStream;
  85. - (GTMSessionFetcherBodyStreamProvider)loggedStreamProviderForStreamProvider:
  86. (GTMSessionFetcherBodyStreamProvider)streamProvider;
  87. // internal; accessors useful for viewing logs
  88. + (NSString *)processNameLogPrefix;
  89. + (NSString *)symlinkNameSuffix;
  90. + (NSString *)htmlFileName;
  91. @end
  92. #endif // !STRIP_GTM_FETCH_LOGGING