├── .gitignore ├── CATLog.gif ├── CATLog.podspec ├── CATLog.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── CATLog ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── CATLog │ ├── CATLog.h │ ├── CATLog.m │ ├── CATLogFilesViewController.h │ ├── CATLogFilesViewController.m │ ├── CATLogFilesViewController.xib │ ├── CATLogReviewController.h │ ├── CATLogReviewController.m │ ├── CATLogReviewController.xib │ ├── CATLogTransfer.h │ └── CATLogTransfer.m ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m ├── CATLogServer.zip ├── LICENSE ├── README.md ├── alllog.jpg ├── color.jpg ├── email.jpg ├── kzlinkedconsole.jpg ├── pod.png ├── preview.jpg └── xcodecolors.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | -------------------------------------------------------------------------------- /CATLog.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatchZeng/CATLog/60e2aca990f5b8f1aa25906b499ed77f2b57c457/CATLog.gif -------------------------------------------------------------------------------- /CATLog.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "CATLog" 3 | s.version = "1.1.0" 4 | s.license = 'MIT' 5 | s.homepage = "http://catchzeng.com" 6 | s.summary = "CATLog is a log system that supports remote output." 7 | s.author = { "CatchZeng" => "891793848@qq.com" } 8 | s.platform = :ios, '6.0' 9 | s.source = { :git => "https://github.com/CatchZeng/CATLog.git", :tag => "1.1.0" } 10 | s.source_files = "CATLog/CATLog/*.{h,m}" 11 | s.resources = "CATLog/CATLog/*.xib" 12 | s.requires_arc = true 13 | end -------------------------------------------------------------------------------- /CATLog.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3F1111DC1D10094D00CF842D /* CATLogReviewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F1111DA1D10094D00CF842D /* CATLogReviewController.m */; }; 11 | 3F1111DD1D10094D00CF842D /* CATLogReviewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3F1111DB1D10094D00CF842D /* CATLogReviewController.xib */; }; 12 | 3F1111E11D1010A600CF842D /* CATLogFilesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F1111DF1D1010A600CF842D /* CATLogFilesViewController.m */; }; 13 | 3F1111E21D1010A600CF842D /* CATLogFilesViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3F1111E01D1010A600CF842D /* CATLogFilesViewController.xib */; }; 14 | 3F8EEFBC1CD2115B0029E3EC /* CATLogTransfer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F8EEFBB1CD2115B0029E3EC /* CATLogTransfer.m */; }; 15 | 5D2A6C481CC7DEB300608D28 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2A6C471CC7DEB300608D28 /* main.m */; }; 16 | 5D2A6C4B1CC7DEB300608D28 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2A6C4A1CC7DEB300608D28 /* AppDelegate.m */; }; 17 | 5D2A6C4E1CC7DEB300608D28 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2A6C4D1CC7DEB300608D28 /* ViewController.m */; }; 18 | 5D2A6C511CC7DEB300608D28 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5D2A6C4F1CC7DEB300608D28 /* Main.storyboard */; }; 19 | 5D2A6C531CC7DEB300608D28 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5D2A6C521CC7DEB300608D28 /* Assets.xcassets */; }; 20 | 5D2A6C561CC7DEB300608D28 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5D2A6C541CC7DEB300608D28 /* LaunchScreen.storyboard */; }; 21 | 5D2A6C601CC7DED900608D28 /* CATLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2A6C5F1CC7DED900608D28 /* CATLog.m */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | 3F1111D91D10094D00CF842D /* CATLogReviewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CATLogReviewController.h; sourceTree = ""; }; 26 | 3F1111DA1D10094D00CF842D /* CATLogReviewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CATLogReviewController.m; sourceTree = ""; }; 27 | 3F1111DB1D10094D00CF842D /* CATLogReviewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CATLogReviewController.xib; sourceTree = ""; }; 28 | 3F1111DE1D1010A600CF842D /* CATLogFilesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CATLogFilesViewController.h; sourceTree = ""; }; 29 | 3F1111DF1D1010A600CF842D /* CATLogFilesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CATLogFilesViewController.m; sourceTree = ""; }; 30 | 3F1111E01D1010A600CF842D /* CATLogFilesViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CATLogFilesViewController.xib; sourceTree = ""; }; 31 | 3F8EEFBA1CD2115A0029E3EC /* CATLogTransfer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CATLogTransfer.h; sourceTree = ""; }; 32 | 3F8EEFBB1CD2115B0029E3EC /* CATLogTransfer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CATLogTransfer.m; sourceTree = ""; }; 33 | 5D2A6C431CC7DEB300608D28 /* CATLog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CATLog.app; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 5D2A6C471CC7DEB300608D28 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 35 | 5D2A6C491CC7DEB300608D28 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 36 | 5D2A6C4A1CC7DEB300608D28 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 37 | 5D2A6C4C1CC7DEB300608D28 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 38 | 5D2A6C4D1CC7DEB300608D28 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 39 | 5D2A6C501CC7DEB300608D28 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 40 | 5D2A6C521CC7DEB300608D28 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 41 | 5D2A6C551CC7DEB300608D28 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 42 | 5D2A6C571CC7DEB300608D28 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | 5D2A6C5E1CC7DED900608D28 /* CATLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CATLog.h; sourceTree = ""; }; 44 | 5D2A6C5F1CC7DED900608D28 /* CATLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CATLog.m; sourceTree = ""; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 5D2A6C401CC7DEB300608D28 /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | ); 53 | runOnlyForDeploymentPostprocessing = 0; 54 | }; 55 | /* End PBXFrameworksBuildPhase section */ 56 | 57 | /* Begin PBXGroup section */ 58 | 5D2A6C3A1CC7DEB300608D28 = { 59 | isa = PBXGroup; 60 | children = ( 61 | 5D2A6C451CC7DEB300608D28 /* CATLog */, 62 | 5D2A6C441CC7DEB300608D28 /* Products */, 63 | ); 64 | sourceTree = ""; 65 | }; 66 | 5D2A6C441CC7DEB300608D28 /* Products */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 5D2A6C431CC7DEB300608D28 /* CATLog.app */, 70 | ); 71 | name = Products; 72 | sourceTree = ""; 73 | }; 74 | 5D2A6C451CC7DEB300608D28 /* CATLog */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 5D2A6C5D1CC7DED900608D28 /* CATLog */, 78 | 5D2A6C491CC7DEB300608D28 /* AppDelegate.h */, 79 | 5D2A6C4A1CC7DEB300608D28 /* AppDelegate.m */, 80 | 5D2A6C4C1CC7DEB300608D28 /* ViewController.h */, 81 | 5D2A6C4D1CC7DEB300608D28 /* ViewController.m */, 82 | 5D2A6C4F1CC7DEB300608D28 /* Main.storyboard */, 83 | 5D2A6C521CC7DEB300608D28 /* Assets.xcassets */, 84 | 5D2A6C541CC7DEB300608D28 /* LaunchScreen.storyboard */, 85 | 5D2A6C571CC7DEB300608D28 /* Info.plist */, 86 | 5D2A6C461CC7DEB300608D28 /* Supporting Files */, 87 | ); 88 | path = CATLog; 89 | sourceTree = ""; 90 | }; 91 | 5D2A6C461CC7DEB300608D28 /* Supporting Files */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 5D2A6C471CC7DEB300608D28 /* main.m */, 95 | ); 96 | name = "Supporting Files"; 97 | sourceTree = ""; 98 | }; 99 | 5D2A6C5D1CC7DED900608D28 /* CATLog */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | 5D2A6C5E1CC7DED900608D28 /* CATLog.h */, 103 | 5D2A6C5F1CC7DED900608D28 /* CATLog.m */, 104 | 3F8EEFBA1CD2115A0029E3EC /* CATLogTransfer.h */, 105 | 3F8EEFBB1CD2115B0029E3EC /* CATLogTransfer.m */, 106 | 3F1111D91D10094D00CF842D /* CATLogReviewController.h */, 107 | 3F1111DA1D10094D00CF842D /* CATLogReviewController.m */, 108 | 3F1111DB1D10094D00CF842D /* CATLogReviewController.xib */, 109 | 3F1111DE1D1010A600CF842D /* CATLogFilesViewController.h */, 110 | 3F1111DF1D1010A600CF842D /* CATLogFilesViewController.m */, 111 | 3F1111E01D1010A600CF842D /* CATLogFilesViewController.xib */, 112 | ); 113 | path = CATLog; 114 | sourceTree = ""; 115 | }; 116 | /* End PBXGroup section */ 117 | 118 | /* Begin PBXNativeTarget section */ 119 | 5D2A6C421CC7DEB300608D28 /* CATLog */ = { 120 | isa = PBXNativeTarget; 121 | buildConfigurationList = 5D2A6C5A1CC7DEB300608D28 /* Build configuration list for PBXNativeTarget "CATLog" */; 122 | buildPhases = ( 123 | 5D2A6C3F1CC7DEB300608D28 /* Sources */, 124 | 5D2A6C401CC7DEB300608D28 /* Frameworks */, 125 | 5D2A6C411CC7DEB300608D28 /* Resources */, 126 | ); 127 | buildRules = ( 128 | ); 129 | dependencies = ( 130 | ); 131 | name = CATLog; 132 | productName = CATLog; 133 | productReference = 5D2A6C431CC7DEB300608D28 /* CATLog.app */; 134 | productType = "com.apple.product-type.application"; 135 | }; 136 | /* End PBXNativeTarget section */ 137 | 138 | /* Begin PBXProject section */ 139 | 5D2A6C3B1CC7DEB300608D28 /* Project object */ = { 140 | isa = PBXProject; 141 | attributes = { 142 | LastUpgradeCheck = 0730; 143 | ORGANIZATIONNAME = zengcatch; 144 | TargetAttributes = { 145 | 5D2A6C421CC7DEB300608D28 = { 146 | CreatedOnToolsVersion = 7.3; 147 | }; 148 | }; 149 | }; 150 | buildConfigurationList = 5D2A6C3E1CC7DEB300608D28 /* Build configuration list for PBXProject "CATLog" */; 151 | compatibilityVersion = "Xcode 3.2"; 152 | developmentRegion = English; 153 | hasScannedForEncodings = 0; 154 | knownRegions = ( 155 | en, 156 | Base, 157 | ); 158 | mainGroup = 5D2A6C3A1CC7DEB300608D28; 159 | productRefGroup = 5D2A6C441CC7DEB300608D28 /* Products */; 160 | projectDirPath = ""; 161 | projectRoot = ""; 162 | targets = ( 163 | 5D2A6C421CC7DEB300608D28 /* CATLog */, 164 | ); 165 | }; 166 | /* End PBXProject section */ 167 | 168 | /* Begin PBXResourcesBuildPhase section */ 169 | 5D2A6C411CC7DEB300608D28 /* Resources */ = { 170 | isa = PBXResourcesBuildPhase; 171 | buildActionMask = 2147483647; 172 | files = ( 173 | 5D2A6C561CC7DEB300608D28 /* LaunchScreen.storyboard in Resources */, 174 | 5D2A6C531CC7DEB300608D28 /* Assets.xcassets in Resources */, 175 | 3F1111E21D1010A600CF842D /* CATLogFilesViewController.xib in Resources */, 176 | 5D2A6C511CC7DEB300608D28 /* Main.storyboard in Resources */, 177 | 3F1111DD1D10094D00CF842D /* CATLogReviewController.xib in Resources */, 178 | ); 179 | runOnlyForDeploymentPostprocessing = 0; 180 | }; 181 | /* End PBXResourcesBuildPhase section */ 182 | 183 | /* Begin PBXSourcesBuildPhase section */ 184 | 5D2A6C3F1CC7DEB300608D28 /* Sources */ = { 185 | isa = PBXSourcesBuildPhase; 186 | buildActionMask = 2147483647; 187 | files = ( 188 | 5D2A6C4E1CC7DEB300608D28 /* ViewController.m in Sources */, 189 | 3F8EEFBC1CD2115B0029E3EC /* CATLogTransfer.m in Sources */, 190 | 5D2A6C601CC7DED900608D28 /* CATLog.m in Sources */, 191 | 3F1111E11D1010A600CF842D /* CATLogFilesViewController.m in Sources */, 192 | 5D2A6C4B1CC7DEB300608D28 /* AppDelegate.m in Sources */, 193 | 5D2A6C481CC7DEB300608D28 /* main.m in Sources */, 194 | 3F1111DC1D10094D00CF842D /* CATLogReviewController.m in Sources */, 195 | ); 196 | runOnlyForDeploymentPostprocessing = 0; 197 | }; 198 | /* End PBXSourcesBuildPhase section */ 199 | 200 | /* Begin PBXVariantGroup section */ 201 | 5D2A6C4F1CC7DEB300608D28 /* Main.storyboard */ = { 202 | isa = PBXVariantGroup; 203 | children = ( 204 | 5D2A6C501CC7DEB300608D28 /* Base */, 205 | ); 206 | name = Main.storyboard; 207 | sourceTree = ""; 208 | }; 209 | 5D2A6C541CC7DEB300608D28 /* LaunchScreen.storyboard */ = { 210 | isa = PBXVariantGroup; 211 | children = ( 212 | 5D2A6C551CC7DEB300608D28 /* Base */, 213 | ); 214 | name = LaunchScreen.storyboard; 215 | sourceTree = ""; 216 | }; 217 | /* End PBXVariantGroup section */ 218 | 219 | /* Begin XCBuildConfiguration section */ 220 | 5D2A6C581CC7DEB300608D28 /* Debug */ = { 221 | isa = XCBuildConfiguration; 222 | buildSettings = { 223 | ALWAYS_SEARCH_USER_PATHS = NO; 224 | CLANG_ANALYZER_NONNULL = YES; 225 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 226 | CLANG_CXX_LIBRARY = "libc++"; 227 | CLANG_ENABLE_MODULES = YES; 228 | CLANG_ENABLE_OBJC_ARC = YES; 229 | CLANG_WARN_BOOL_CONVERSION = YES; 230 | CLANG_WARN_CONSTANT_CONVERSION = YES; 231 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INT_CONVERSION = YES; 235 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 236 | CLANG_WARN_UNREACHABLE_CODE = YES; 237 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 238 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 239 | COPY_PHASE_STRIP = NO; 240 | DEBUG_INFORMATION_FORMAT = dwarf; 241 | ENABLE_STRICT_OBJC_MSGSEND = YES; 242 | ENABLE_TESTABILITY = YES; 243 | GCC_C_LANGUAGE_STANDARD = gnu99; 244 | GCC_DYNAMIC_NO_PIC = NO; 245 | GCC_NO_COMMON_BLOCKS = YES; 246 | GCC_OPTIMIZATION_LEVEL = 0; 247 | GCC_PREPROCESSOR_DEFINITIONS = ( 248 | "DEBUG=1", 249 | "$(inherited)", 250 | ); 251 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 252 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 253 | GCC_WARN_UNDECLARED_SELECTOR = YES; 254 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 255 | GCC_WARN_UNUSED_FUNCTION = YES; 256 | GCC_WARN_UNUSED_VARIABLE = YES; 257 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 258 | MTL_ENABLE_DEBUG_INFO = YES; 259 | ONLY_ACTIVE_ARCH = YES; 260 | SDKROOT = iphoneos; 261 | TARGETED_DEVICE_FAMILY = "1,2"; 262 | }; 263 | name = Debug; 264 | }; 265 | 5D2A6C591CC7DEB300608D28 /* Release */ = { 266 | isa = XCBuildConfiguration; 267 | buildSettings = { 268 | ALWAYS_SEARCH_USER_PATHS = NO; 269 | CLANG_ANALYZER_NONNULL = YES; 270 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 271 | CLANG_CXX_LIBRARY = "libc++"; 272 | CLANG_ENABLE_MODULES = YES; 273 | CLANG_ENABLE_OBJC_ARC = YES; 274 | CLANG_WARN_BOOL_CONVERSION = YES; 275 | CLANG_WARN_CONSTANT_CONVERSION = YES; 276 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 277 | CLANG_WARN_EMPTY_BODY = YES; 278 | CLANG_WARN_ENUM_CONVERSION = YES; 279 | CLANG_WARN_INT_CONVERSION = YES; 280 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 281 | CLANG_WARN_UNREACHABLE_CODE = YES; 282 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 283 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 284 | COPY_PHASE_STRIP = NO; 285 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 286 | ENABLE_NS_ASSERTIONS = NO; 287 | ENABLE_STRICT_OBJC_MSGSEND = YES; 288 | GCC_C_LANGUAGE_STANDARD = gnu99; 289 | GCC_NO_COMMON_BLOCKS = YES; 290 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 291 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 292 | GCC_WARN_UNDECLARED_SELECTOR = YES; 293 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 294 | GCC_WARN_UNUSED_FUNCTION = YES; 295 | GCC_WARN_UNUSED_VARIABLE = YES; 296 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 297 | MTL_ENABLE_DEBUG_INFO = NO; 298 | SDKROOT = iphoneos; 299 | TARGETED_DEVICE_FAMILY = "1,2"; 300 | VALIDATE_PRODUCT = YES; 301 | }; 302 | name = Release; 303 | }; 304 | 5D2A6C5B1CC7DEB300608D28 /* Debug */ = { 305 | isa = XCBuildConfiguration; 306 | buildSettings = { 307 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 308 | INFOPLIST_FILE = CATLog/Info.plist; 309 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 310 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 311 | PRODUCT_BUNDLE_IDENTIFIER = com.catch.CATLog; 312 | PRODUCT_NAME = "$(TARGET_NAME)"; 313 | }; 314 | name = Debug; 315 | }; 316 | 5D2A6C5C1CC7DEB300608D28 /* Release */ = { 317 | isa = XCBuildConfiguration; 318 | buildSettings = { 319 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 320 | INFOPLIST_FILE = CATLog/Info.plist; 321 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 322 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 323 | PRODUCT_BUNDLE_IDENTIFIER = com.catch.CATLog; 324 | PRODUCT_NAME = "$(TARGET_NAME)"; 325 | }; 326 | name = Release; 327 | }; 328 | /* End XCBuildConfiguration section */ 329 | 330 | /* Begin XCConfigurationList section */ 331 | 5D2A6C3E1CC7DEB300608D28 /* Build configuration list for PBXProject "CATLog" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | 5D2A6C581CC7DEB300608D28 /* Debug */, 335 | 5D2A6C591CC7DEB300608D28 /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | 5D2A6C5A1CC7DEB300608D28 /* Build configuration list for PBXNativeTarget "CATLog" */ = { 341 | isa = XCConfigurationList; 342 | buildConfigurations = ( 343 | 5D2A6C5B1CC7DEB300608D28 /* Debug */, 344 | 5D2A6C5C1CC7DEB300608D28 /* Release */, 345 | ); 346 | defaultConfigurationIsVisible = 0; 347 | defaultConfigurationName = Release; 348 | }; 349 | /* End XCConfigurationList section */ 350 | }; 351 | rootObject = 5D2A6C3B1CC7DEB300608D28 /* Project object */; 352 | } 353 | -------------------------------------------------------------------------------- /CATLog.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CATLog/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // CATLog 4 | // 5 | // Created by zengcatch on 16/4/20. 6 | // Copyright © 2016年 zengcatch. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /CATLog/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // CATLog 4 | // 5 | // Created by zengcatch on 16/4/20. 6 | // Copyright © 2016年 zengcatch. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "CATLog.h" 11 | 12 | #define YouLogI(fmt, ...) [CATLog logI:[NSString stringWithFormat:@"[%@:%d] %s %@",[NSString stringWithFormat:@"%s",__FILE__].lastPathComponent,__LINE__,__func__,fmt],##__VA_ARGS__,@""]; 13 | 14 | 15 | @interface AppDelegate () 16 | 17 | @end 18 | 19 | @implementation AppDelegate 20 | 21 | 22 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 23 | 24 | //Set ExceptionHandler 25 | NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); 26 | 27 | //Init log 28 | [CATLog initWithNumberOfDaysToDelete:3]; 29 | 30 | //Remote Log 31 | [CATLog setRemoteLogEnable:YES]; 32 | [CATLog setRemoteIp:@"192.168.1.100" port:1111]; 33 | 34 | //Set log level 35 | [CATLog setLogLevel:CATLevelV]; 36 | 37 | //Set Color 38 | [CATLog setR:200 G:0 B:0 forLevel:CATLevelE]; 39 | [CATLog setBgR:255 G:255 B:255 forLevel:CATLevelE]; 40 | 41 | //Redefine log 42 | YouLogI(@"ReDefine Log by yourself"); 43 | 44 | //Log normal string 45 | CLogE(@"Normal string"); 46 | 47 | NSString* normalStt = [NSString stringWithFormat:@"Normal String"]; 48 | CLogE(normalStt); 49 | 50 | //Log format string 51 | CLogD(@"Format String:string1,%@,%@",@"string2",@"string3"); 52 | 53 | UIImageView* imgView = [[UIImageView alloc]init]; 54 | CLogD(@"Format String %@",imgView); 55 | 56 | //Log Color 57 | CLogE(@"I am error log. Do you like my color?"); 58 | CLogW(@"I am warning log. Do you like my color?"); 59 | CLogI(@"I am info log. Do you like my color?"); 60 | CLogD(@"I am debug log. Do you like my color?"); 61 | CLogV(@"I am verbose log. Do you like my color?"); 62 | 63 | return YES; 64 | } 65 | 66 | void uncaughtExceptionHandler(NSException *exception){ 67 | [CATLog logCrash:exception]; 68 | } 69 | 70 | - (void)applicationWillResignActive:(UIApplication *)application { 71 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 72 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 73 | } 74 | 75 | - (void)applicationDidEnterBackground:(UIApplication *)application { 76 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 77 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 78 | } 79 | 80 | - (void)applicationWillEnterForeground:(UIApplication *)application { 81 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 82 | } 83 | 84 | - (void)applicationDidBecomeActive:(UIApplication *)application { 85 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 86 | } 87 | 88 | - (void)applicationWillTerminate:(UIApplication *)application { 89 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /CATLog/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /CATLog/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CATLog/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /CATLog/CATLog/CATLog.h: -------------------------------------------------------------------------------- 1 | // 2 | // CATLog.h 3 | // CATLog 4 | // 5 | // Created by zengcatch on 16/4/18. 6 | // Copyright © 2016年 cacth. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //Verbose 12 | #define CLogV(fmt, ...) [CATLog logV:[NSString stringWithFormat:@"[%@:%d] %s %@",[NSString stringWithFormat:@"%s",__FILE__].lastPathComponent,__LINE__,__func__,fmt],##__VA_ARGS__,@""]; 13 | 14 | //Debug 15 | #define CLogD(fmt, ...) [CATLog logD:[NSString stringWithFormat:@"[%@:%d] %s %@",[NSString stringWithFormat:@"%s",__FILE__].lastPathComponent,__LINE__,__func__,fmt],##__VA_ARGS__,@""]; 16 | 17 | //Info 18 | #define CLogI(fmt, ...) [CATLog logI:[NSString stringWithFormat:@"[%@:%d] %s %@",[NSString stringWithFormat:@"%s",__FILE__].lastPathComponent,__LINE__,__func__,fmt],##__VA_ARGS__,@""]; 19 | 20 | //Warning 21 | #define CLogW(fmt, ...) [CATLog logW:[NSString stringWithFormat:@"[%@:%d] %s %@",[NSString stringWithFormat:@"%s",__FILE__].lastPathComponent,__LINE__,__func__,fmt],##__VA_ARGS__,@""]; 22 | 23 | //Error 24 | #define CLogE(fmt, ...) [CATLog logE:[NSString stringWithFormat:@"[%@:%d] %s %@",[NSString stringWithFormat:@"%s",__FILE__].lastPathComponent,__LINE__,__func__,fmt],##__VA_ARGS__,@""]; 25 | 26 | //log Level 27 | typedef NS_ENUM(NSInteger, CATLogLevel) { 28 | CATLevelV = 0, //Verbose 29 | CATLevelD = 1, //Debug 30 | CATLevelI = 2, //Info 31 | CATLevelW = 3, //Warning 32 | CATLevelE = 4, //Error 33 | CATLevelN = 5, //Close All 34 | }; 35 | 36 | @interface CATLog : NSObject 37 | 38 | /** 39 | * init log 40 | */ 41 | +(void)initWithNumberOfDaysToDelete:(NSInteger)number; 42 | 43 | /** 44 | * set remote log enable 45 | * 46 | * @param enable : BOOL 47 | */ 48 | +(void)setRemoteLogEnable:(BOOL)enable; 49 | 50 | /** 51 | * set catlog server ip &port 52 | * 53 | * @param ip : server ip 54 | * @param port : server port 55 | */ 56 | +(void)setRemoteIp:(NSString *)ip port:(NSInteger)port; 57 | 58 | /** 59 | * set colorful log enable 60 | * 61 | * @param enable : BOOL 62 | */ 63 | +(void)setColorEnable:(BOOL)enable; 64 | 65 | /** 66 | * set color for level 67 | * 68 | * @param R : Red 69 | * @param G : Green 70 | * @param B : Blue 71 | * @param level : Log level 72 | */ 73 | +(void)setR:(NSInteger)R G:(NSInteger)G B:(NSInteger)B forLevel:(CATLogLevel)level; 74 | 75 | /** 76 | * set bg color for level 77 | * 78 | * @param R : Red 79 | * @param G : Green 80 | * @param B : Blue 81 | * @param level : Log level 82 | */ 83 | +(void)setBgR:(NSInteger)R G:(NSInteger)G B:(NSInteger)B forLevel:(CATLogLevel)level; 84 | 85 | /** 86 | * log exception 87 | * 88 | * @param exception 89 | */ 90 | + (void)logCrash:(NSException *)exception; 91 | 92 | /** 93 | * set log level 94 | * 95 | * @param level : log level 96 | */ 97 | + (void)setLogLevel:(CATLogLevel)level; 98 | 99 | /** 100 | * show today log file 101 | */ 102 | +(void)showTodayLogFile; 103 | 104 | /** 105 | * show all log file 106 | */ 107 | +(void)showAllLogFile; 108 | 109 | /** 110 | * log 111 | * 112 | * @param level : log level 113 | * @param format : format log message 114 | */ 115 | + (void)logLevel:(CATLogLevel)level logInfo:(NSString *)format, ...NS_FORMAT_FUNCTION(2,3); 116 | 117 | /** 118 | * log error 119 | * 120 | * @param format : format log message 121 | */ 122 | + (void)logE:(NSString *)format, ...NS_FORMAT_FUNCTION(1,2); 123 | 124 | /** 125 | * log warning 126 | * 127 | * @param format : format log message 128 | */ 129 | + (void)logW:(NSString *)format, ...NS_FORMAT_FUNCTION(1,2); 130 | 131 | /** 132 | * log info 133 | * 134 | * @param format : format log message 135 | */ 136 | + (void)logI:(NSString *)format, ...NS_FORMAT_FUNCTION(1,2); 137 | 138 | /** 139 | * log debug 140 | * 141 | * @param format : format log message 142 | */ 143 | + (void)logD:(NSString *)format, ...NS_FORMAT_FUNCTION(1,2); 144 | 145 | /** 146 | * log verbose 147 | * 148 | * @param format : format log message 149 | */ 150 | + (void)logV:(NSString *)format, ...NS_FORMAT_FUNCTION(1,2); 151 | 152 | @end -------------------------------------------------------------------------------- /CATLog/CATLog/CATLog.m: -------------------------------------------------------------------------------- 1 | // 2 | // CATLog.m 3 | // CATLog 4 | // 5 | // Created by zengcatch on 16/4/18. 6 | // Copyright © 2016年 cacth. All rights reserved. 7 | // 8 | 9 | #import "CATLog.h" 10 | #import 11 | #import "CATLogTransfer.h" 12 | #import "CATLogReviewController.h" 13 | #import "CATLogFilesViewController.h" 14 | 15 | #ifdef DEBUG 16 | static CATLogLevel LogLevel = CATLevelV; //Debug => DLevelV 17 | #else 18 | static CATLogLevel LogLevel = CATLevelE; //Release => DLevelE 19 | #endif 20 | 21 | //log color 22 | #define XCODE_COLORS_ESCAPE_MAC @"\033[" 23 | #define XCODE_COLORS_ESCAPE_IOS @"\xC2\xA0[" 24 | 25 | #if 0//TARGET_OS_IPHONE 26 | #define XCODE_COLORS_ESCAPE XCODE_COLORS_ESCAPE_IOS 27 | #else 28 | #define XCODE_COLORS_ESCAPE XCODE_COLORS_ESCAPE_MAC 29 | #endif 30 | 31 | #define XCODE_COLORS_RESET_FG XCODE_COLORS_ESCAPE @"fg;" // Clear any foreground color 32 | #define XCODE_COLORS_RESET_BG XCODE_COLORS_ESCAPE @"bg;" // Clear any background color 33 | #define XCODE_COLORS_RESET XCODE_COLORS_ESCAPE @";" // Clear any foreground or background color 34 | 35 | static NSMutableDictionary* colorDic = nil; 36 | static NSMutableDictionary* bgColorDic = nil; 37 | 38 | //log file 39 | static NSString *logFilePath = nil; 40 | static NSString *logDic = nil; 41 | static NSString *crashDic = nil; 42 | 43 | //log queue 44 | static dispatch_once_t logQueueCreatOnce; 45 | static dispatch_queue_t logOperationQueue; 46 | 47 | //remote log 48 | static CATLogTransfer *udpSocket; 49 | static BOOL remoteLogEnable; 50 | static NSString* remoteIp; 51 | static NSInteger remotePort; 52 | static long tag; 53 | 54 | @implementation CATLog 55 | 56 | 57 | #pragma mark -- 58 | #pragma mark -- public methods 59 | 60 | +(void)initWithNumberOfDaysToDelete:(NSInteger)numberOfDaysToDelete{ 61 | numberOfDaysToDelete = numberOfDaysToDelete < 0 ? 0 :numberOfDaysToDelete; 62 | [self setRemoteLogEnable:NO]; 63 | [self setColorEnable:YES]; 64 | [self _initColors]; 65 | [self _initFileWithNumberOfDaysToDelete:numberOfDaysToDelete]; 66 | dispatch_once(&logQueueCreatOnce, ^{ 67 | logOperationQueue = dispatch_queue_create("com.catlog.app.operationqueue", DISPATCH_QUEUE_SERIAL); 68 | }); 69 | } 70 | 71 | +(void)setRemoteLogEnable:(BOOL)enable{ 72 | remoteLogEnable = enable; 73 | if (enable) { 74 | [self _setupSocket]; 75 | } 76 | } 77 | 78 | +(void)_setupSocket{ 79 | if (!udpSocket) { 80 | udpSocket = [[CATLogTransfer alloc] initWithDelegate:nil delegateQueue:dispatch_get_main_queue()]; 81 | } 82 | NSError *error = nil; 83 | if (![udpSocket bindToPort:0 error:&error]){ 84 | NSLog(@"Error binding: %@", error); 85 | return; 86 | } 87 | if (![udpSocket beginReceiving:&error]){ 88 | NSLog(@"Error receiving: %@", error); 89 | return; 90 | } 91 | } 92 | 93 | +(void)setRemoteIp:(NSString *)ip port:(NSInteger)port{ 94 | remoteIp = ip; 95 | remotePort = port; 96 | } 97 | 98 | +(void)setColorEnable:(BOOL)enable{ 99 | if (enable) { 100 | setenv("XcodeColors", "YES", 0); 101 | }else{ 102 | setenv("XcodeColors", "NO", 0); 103 | } 104 | } 105 | 106 | +(void)setR:(NSInteger)R G:(NSInteger)G B:(NSInteger)B forLevel:(CATLogLevel)level{ 107 | NSString* rgbStr = [NSString stringWithFormat:@"%ld,%ld,%ld",(long)R,(long)G,(long)B]; 108 | if (colorDic) { 109 | [colorDic setObject:rgbStr forKey:@(level)]; 110 | }else{ 111 | NSLog(XCODE_COLORS_ESCAPE @"fg%@;" @"%@" XCODE_COLORS_RESET,rgbStr,@"You should call [CATLog initLog] before use it!"); 112 | } 113 | } 114 | 115 | +(void)setBgR:(NSInteger)R G:(NSInteger)G B:(NSInteger)B forLevel:(CATLogLevel)level{ 116 | NSString* rgbStr = [NSString stringWithFormat:@"%ld,%ld,%ld",(long)R,(long)G,(long)B]; 117 | if (!bgColorDic) { 118 | bgColorDic = [NSMutableDictionary dictionaryWithCapacity:5]; 119 | } 120 | [bgColorDic setObject:rgbStr forKey:@(level)]; 121 | } 122 | 123 | + (void)logCrash:(NSException *)exception{ 124 | if (!exception) return; 125 | 126 | #ifdef DEBUG 127 | NSLog(@"CRASH: %@",exception); 128 | NSLog(@"Stack Trace: %@",[exception callStackSymbols]); 129 | #endif 130 | if (!crashDic) { 131 | NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 132 | NSString *crashDirectory = [documentsDirectory stringByAppendingString:@"/log/"]; 133 | crashDic = crashDirectory; 134 | } 135 | 136 | NSString *fileName = [NSString stringWithFormat:@"CRASH_%@.log",[self _getCurrentTime]]; 137 | NSString *filePath = [crashDic stringByAppendingString:fileName]; 138 | NSString *content = [[NSString stringWithFormat:@"CRASH: %@\n", exception] stringByAppendingString:[NSString stringWithFormat:@"Stack Trace: %@\n", [exception callStackSymbols]]]; 139 | 140 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 141 | NSArray *languages = [defaults objectForKey:@"AppleLanguages"]; 142 | NSString *phoneLanguage = [languages objectAtIndex:0]; 143 | 144 | content = [content stringByAppendingString:[NSString stringWithFormat:@"iOS Version:%@ Language:%@", [[UIDevice currentDevice] systemVersion],phoneLanguage]]; 145 | NSError *error = nil; 146 | [content writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error]; 147 | 148 | if (error) { 149 | #if DEBUG 150 | NSLog(@"error is %@",error); 151 | #endif 152 | [self logE:@"CRASH LOG CREAT ERR INFO IS %@",error]; 153 | } 154 | } 155 | 156 | + (void)setLogLevel:(CATLogLevel)level{ 157 | LogLevel = level; 158 | } 159 | 160 | + (void)logLevel:(CATLogLevel)level logInfo:(NSString *)format, ...{ 161 | va_list args; 162 | va_start(args, format); 163 | [self _logvLevel:level format:format vaList:args]; 164 | va_end(args); 165 | } 166 | 167 | + (void)logV:(NSString *)format, ...{ 168 | va_list args; 169 | va_start(args, format); 170 | [self _logvLevel:CATLevelV format:format vaList:args]; 171 | va_end(args); 172 | } 173 | 174 | + (void)logD:(NSString *)format, ...{ 175 | va_list args; 176 | va_start(args, format); 177 | [self _logvLevel:CATLevelD format:format vaList:args]; 178 | va_end(args); 179 | } 180 | 181 | + (void)logI:(NSString *)format, ...{ 182 | va_list args; 183 | va_start(args, format); 184 | [self _logvLevel:CATLevelI format:format vaList:args]; 185 | va_end(args); 186 | } 187 | 188 | + (void)logW:(NSString *)format, ...{ 189 | va_list args; 190 | va_start(args, format); 191 | [self _logvLevel:CATLevelW format:format vaList:args]; 192 | va_end(args); 193 | } 194 | 195 | + (void)logE:(NSString *)format, ...{ 196 | va_list args; 197 | va_start(args, format); 198 | [self _logvLevel:CATLevelE format:format vaList:args]; 199 | va_end(args); 200 | } 201 | 202 | 203 | #pragma mark -- 204 | #pragma mark -- private methods 205 | 206 | +(void)_initColors{ 207 | NSString *color4LogE = @"255,0,0"; 208 | NSString *color4LogW = @"204,113,62"; 209 | NSString *color4LogI = @"73,176,249"; 210 | NSString *color4LogD = @"205,74,162"; 211 | NSString *color4LogV = @"115,205,102"; 212 | colorDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:color4LogV,@(0),color4LogD,@(1),color4LogI,@(2),color4LogW,@(3),color4LogE,@(4),nil]; 213 | } 214 | 215 | +(void)_initFileWithNumberOfDaysToDelete:(NSInteger)numberOfDaysToDelete{ 216 | if (!logFilePath){ 217 | NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 218 | NSString *logDirectory = [documentsDirectory stringByAppendingString:@"/log/"]; 219 | NSString *crashDirectory = [documentsDirectory stringByAppendingString:@"/log/"]; 220 | 221 | if (![[NSFileManager defaultManager] fileExistsAtPath:logDirectory]) { 222 | [[NSFileManager defaultManager] createDirectoryAtPath:logDirectory 223 | withIntermediateDirectories:YES 224 | attributes:nil 225 | error:nil]; 226 | } 227 | if (![[NSFileManager defaultManager] fileExistsAtPath:crashDirectory]) { 228 | [[NSFileManager defaultManager] createDirectoryAtPath:crashDirectory 229 | withIntermediateDirectories:YES 230 | attributes:nil 231 | error:nil]; 232 | } 233 | logDic = logDirectory; 234 | crashDic = crashDirectory; 235 | 236 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 237 | [dateFormatter setDateFormat:@"yyyy-MM-dd"]; 238 | dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT+0800"];; 239 | NSString *fileNamePrefix = [dateFormatter stringFromDate:[NSDate date]]; 240 | NSString *fileName = [NSString stringWithFormat:@"CAT_log_%@.logtraces.txt", fileNamePrefix]; 241 | NSString *filePath = [logDirectory stringByAppendingPathComponent:fileName]; 242 | logFilePath = filePath; 243 | #if DEBUG 244 | NSLog(@"【CATLog】LogPath: %@", logFilePath); 245 | #endif 246 | //create file if it doesn't exist 247 | if(![[NSFileManager defaultManager] fileExistsAtPath:filePath]){ 248 | [[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil]; 249 | } 250 | 251 | //delete previous log file 252 | NSDate *prevDate = [[NSDate date] dateByAddingTimeInterval:-60*60*24*numberOfDaysToDelete]; 253 | NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:prevDate]; 254 | [components setHour:0]; 255 | [components setMinute:0]; 256 | [components setSecond:0]; 257 | NSDate *delDate = [[NSCalendar currentCalendar] dateFromComponents:components]; 258 | NSArray *logFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:logDic error:nil]; 259 | for (NSString *file in logFiles){ 260 | NSString *fileName = [file stringByReplacingOccurrencesOfString:@".logtraces.txt" withString:@""]; 261 | fileName = [fileName stringByReplacingOccurrencesOfString:@"CAT_log_" withString:@""]; 262 | NSDate *fileDate = [dateFormatter dateFromString:fileName]; 263 | if (nil == fileDate){ 264 | continue; 265 | } 266 | if (NSOrderedAscending == [fileDate compare:delDate]){ 267 | [[NSFileManager defaultManager] removeItemAtPath:[logDic stringByAppendingString:file] error:nil]; 268 | } 269 | } 270 | } 271 | } 272 | 273 | +(void)_logvLevel:(CATLogLevel)level format:(NSString *)format vaList:(va_list)args{ 274 | __block NSString *formatTmp = format; 275 | formatTmp = [[self _logFormatPrefix:level] stringByAppendingString:formatTmp]; 276 | NSString *contentStr = [[NSString alloc] initWithFormat:formatTmp arguments:args]; 277 | NSString *contentN = [contentStr stringByAppendingString:@"\n"]; 278 | NSString *content = [NSString stringWithFormat:@"%@ %@",[self _getCurrentTime], contentN]; 279 | 280 | if (logOperationQueue) { 281 | dispatch_async(logOperationQueue, ^{ 282 | if (level >= LogLevel){ 283 | NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath:logFilePath]; 284 | [file seekToEndOfFile]; 285 | [file writeData:[content dataUsingEncoding:NSUTF8StringEncoding]]; 286 | [file closeFile]; 287 | #ifdef DEBUG 288 | NSString* color = [colorDic objectForKey:@(level)]; 289 | NSString* bgColor = [bgColorDic objectForKey:@(level)]; 290 | if (bgColor) { 291 | NSLog(XCODE_COLORS_ESCAPE @"fg%@;" XCODE_COLORS_ESCAPE @"bg%@;" @"%@" XCODE_COLORS_RESET,color,bgColor,content); 292 | }else{ 293 | NSLog(XCODE_COLORS_ESCAPE @"fg%@;" @"%@" XCODE_COLORS_RESET,color,contentN); 294 | } 295 | 296 | if (remoteLogEnable) { 297 | NSString* dataStr = [NSString stringWithFormat:@"%@;%@;%@",color,bgColor,content]; 298 | NSData *data = [dataStr dataUsingEncoding:NSUTF8StringEncoding]; 299 | [udpSocket sendData:data toHost:remoteIp port:remotePort withTimeout:-1 tag:tag]; 300 | tag++; 301 | } 302 | #endif 303 | formatTmp = nil; 304 | } 305 | }); 306 | }else{ 307 | NSString* color = [colorDic objectForKey:@(level)]; 308 | NSLog(XCODE_COLORS_ESCAPE @"fg%@;" @"%@" XCODE_COLORS_RESET,color,@"You should call [CATLog initLog] before use it!"); 309 | } 310 | } 311 | 312 | +(NSString *)_getCurrentTime{ 313 | NSDate *nowUTC = [NSDate date]; 314 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 315 | [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; 316 | [dateFormatter setTimeZone:[NSTimeZone localTimeZone]]; 317 | [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; 318 | [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; 319 | 320 | NSDateFormatter *format=[[NSDateFormatter alloc] init]; 321 | [format setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; 322 | NSString *dateString = [format stringFromDate:nowUTC]; 323 | 324 | return dateString; 325 | } 326 | 327 | + (NSString*)_stringFromLogLevel:(CATLogLevel)logLevel{ 328 | switch (logLevel){ 329 | case CATLevelV: return @"V"; 330 | case CATLevelD: return @"D"; 331 | case CATLevelI: return @"I"; 332 | case CATLevelW: return @"W"; 333 | case CATLevelE: return @"E"; 334 | case CATLevelN: return @"N"; 335 | } 336 | return @""; 337 | } 338 | 339 | + (NSString*)_logFormatPrefix:(CATLogLevel)logLevel{ 340 | return [NSString stringWithFormat:@"[%@] ", [self _stringFromLogLevel:logLevel]]; 341 | } 342 | 343 | +(void)showTodayLogFile{ 344 | CATLogReviewController* viewCtrl = [[CATLogReviewController alloc]initWithLogFilePath:logFilePath]; 345 | UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewCtrl]; 346 | UIApplication *application = [UIApplication sharedApplication]; 347 | UIWindow* keyWindow = application.keyWindow; 348 | if (keyWindow.rootViewController) { 349 | [keyWindow.rootViewController presentViewController:navigationController animated:YES completion:NULL]; 350 | } 351 | } 352 | 353 | +(void)showAllLogFile{ 354 | CATLogFilesViewController* viewCtrl = [[CATLogFilesViewController alloc]initWithLogDir:logDic]; 355 | UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewCtrl]; 356 | UIApplication *application = [UIApplication sharedApplication]; 357 | UIWindow* keyWindow = application.keyWindow; 358 | if (keyWindow.rootViewController) { 359 | [keyWindow.rootViewController presentViewController:navigationController animated:YES completion:NULL]; 360 | } 361 | } 362 | 363 | @end -------------------------------------------------------------------------------- /CATLog/CATLog/CATLogFilesViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CATLogFilesViewController.h 3 | // CATLog 4 | // 5 | // Created by catch on 16/6/14. 6 | // Copyright © 2016年 zengcatch. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CATLogFilesViewController : UIViewController 12 | 13 | -(instancetype)initWithLogDir:(NSString *)logDir; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /CATLog/CATLog/CATLogFilesViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CATLogFilesViewController.m 3 | // CATLog 4 | // 5 | // Created by catch on 16/6/14. 6 | // Copyright © 2016年 zengcatch. All rights reserved. 7 | // 8 | 9 | #import "CATLogFilesViewController.h" 10 | #import "CATLogReviewController.h" 11 | 12 | @interface CATLogFilesViewController () 13 | 14 | @property (weak, nonatomic) IBOutlet UITableView *tableView; 15 | 16 | @property (nonatomic, strong) NSString *logDir; 17 | @property (nonatomic, strong) NSArray *files; 18 | 19 | @end 20 | 21 | @implementation CATLogFilesViewController 22 | 23 | -(instancetype)initWithLogDir:(NSString *)logDir{ 24 | self = [super init]; 25 | if (self) { 26 | _logDir = logDir; 27 | } 28 | return self; 29 | } 30 | 31 | - (void)viewDidLoad { 32 | [super viewDidLoad]; 33 | self.title = @"All Log Files"; 34 | self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(_bakcButtonClicked)]; 35 | 36 | _files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:_logDir error:nil]; 37 | 38 | _tableView.tableFooterView = [[UIView alloc]init]; 39 | [_tableView reloadData]; 40 | } 41 | 42 | #pragma mark - private methods 43 | 44 | -(void)_bakcButtonClicked{ 45 | [self dismissViewControllerAnimated:YES completion:nil]; 46 | } 47 | 48 | #pragma mark -- delegate & datasource 49 | 50 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 51 | return _files.count; 52 | } 53 | 54 | -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 55 | static NSString *reuseIdetify = @"CATTableViewCell"; 56 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdetify]; 57 | if (!cell) { 58 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdetify]; 59 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 60 | cell.showsReorderControl = YES; 61 | cell.selectionStyle = UITableViewCellSelectionStyleNone; 62 | } 63 | cell.textLabel.text = [_files objectAtIndex:indexPath.row]; 64 | return cell; 65 | } 66 | 67 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 68 | NSString* logFilePath = [_logDir stringByAppendingString:[_files objectAtIndex:indexPath.row]]; 69 | CATLogReviewController* viewCtrl = [[CATLogReviewController alloc]initWithLogFilePath:logFilePath]; 70 | [self.navigationController pushViewController:viewCtrl animated:YES]; 71 | } 72 | 73 | @end -------------------------------------------------------------------------------- /CATLog/CATLog/CATLogFilesViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /CATLog/CATLog/CATLogReviewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CATLogReviewController.h 3 | // CATLog 4 | // 5 | // Created by catch on 16/6/14. 6 | // Copyright © 2016年 zengcatch. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CATLogReviewController : UIViewController 12 | 13 | /** 14 | * init 15 | * 16 | * @param filePath :log file path 17 | * 18 | * @return CATLogReviewController 19 | */ 20 | -(instancetype)initWithLogFilePath:(NSString *)filePath; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /CATLog/CATLog/CATLogReviewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CATLogReviewController.m 3 | // CATLog 4 | // 5 | // Created by catch on 16/6/14. 6 | // Copyright © 2016年 zengcatch. All rights reserved. 7 | // 8 | 9 | #import "CATLogReviewController.h" 10 | #import 11 | 12 | @interface CATLogReviewController () 13 | 14 | @property (nonatomic, strong) NSString *filePath; 15 | @property (weak, nonatomic) IBOutlet UIWebView *webView; 16 | 17 | @end 18 | 19 | @implementation CATLogReviewController 20 | 21 | -(instancetype)initWithLogFilePath:(NSString *)filePath{ 22 | self = [super init]; 23 | if (self) { 24 | _filePath = filePath; 25 | self.title = [_filePath lastPathComponent]; 26 | } 27 | return self; 28 | } 29 | 30 | - (void)viewDidLoad{ 31 | [super viewDidLoad]; 32 | self.navigationController.delegate = self; 33 | 34 | _webView.backgroundColor = [UIColor whiteColor]; 35 | _webView.delegate = self; 36 | [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:_filePath]]]; 37 | 38 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Email" style:UIBarButtonItemStylePlain target:self action:@selector(_emailButtonCliked)]; 39 | } 40 | 41 | -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 42 | if (navigationController.isBeingPresented) {//pop 43 | self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(_bakcButtonClicked)]; 44 | } 45 | } 46 | 47 | #pragma mark - private methods 48 | 49 | -(void)_bakcButtonClicked{ 50 | [self dismissViewControllerAnimated:YES completion:nil]; 51 | } 52 | 53 | - (void)_emailButtonCliked{ 54 | if ([MFMailComposeViewController canSendMail]) { 55 | MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; 56 | NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; 57 | NSString *appVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; 58 | NSString *appBuild = [infoDictionary objectForKey:@"CFBundleVersion"]; 59 | NSString *processName = [NSProcessInfo processInfo].processName; 60 | [mailController setSubject:[NSString stringWithFormat:@"%@ Log Report ", processName, appVersion, appBuild]]; 61 | [mailController setMailComposeDelegate:self]; 62 | 63 | NSData *logData = [[NSData alloc] initWithContentsOfURL:[NSURL fileURLWithPath:_filePath]]; 64 | [mailController addAttachmentData:logData mimeType:@"com.apple.log" fileName:_filePath.lastPathComponent]; 65 | 66 | [self presentViewController:mailController animated:YES completion:NULL]; 67 | } else { 68 | NSLog(@"You should set your email account in settngs first!"); 69 | } 70 | } 71 | 72 | #pragma mark - delegate 73 | - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{ 74 | [controller dismissViewControllerAnimated:YES completion:NULL]; 75 | } 76 | 77 | - (void)webViewDidFinishLoad:(UIWebView *)webView{ 78 | CGSize webviewContentSize = webView.scrollView.contentSize; 79 | [webView.scrollView scrollRectToVisible:CGRectMake(0, webviewContentSize.height - webView.bounds.size.height, webView.bounds.size.width, webView.bounds.size.height) animated:NO]; 80 | } 81 | 82 | @end -------------------------------------------------------------------------------- /CATLog/CATLog/CATLogReviewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /CATLog/CATLog/CATLogTransfer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CATLogSender.h 3 | // CATLog 4 | // 5 | // Created by zengcatch on 16/4/18. 6 | // Copyright © 2016年 cacth. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | #import 13 | 14 | extern NSString *const CATLogTransferException; 15 | extern NSString *const CATLogTransferErrorDomain; 16 | 17 | extern NSString *const CATLogTransferQueueName; 18 | extern NSString *const CATLogTransferThreadName; 19 | 20 | typedef NS_ENUM(NSInteger, CATLogTransferError) { 21 | CATLogTransferNoError = 0, 22 | CATLogTransferBadConfigError, 23 | CATLogTransferBadParamError, 24 | CATLogTransferSendTimeoutError, 25 | CATLogTransferClosedError, 26 | CATLogTransferOtherError, 27 | }; 28 | 29 | @class CATLogTransfer; 30 | 31 | @protocol CATLogTransferDelegate 32 | @optional 33 | 34 | - (void)transfer:(CATLogTransfer *)sock didConnectToAddress:(NSData *)address; 35 | 36 | - (void)transfer:(CATLogTransfer *)sock didNotConnect:(NSError *)error; 37 | 38 | - (void)transfer:(CATLogTransfer *)sock didSendDataWithTag:(long)tag; 39 | 40 | - (void)transfer:(CATLogTransfer *)sock didNotSendDataWithTag:(long)tag dueToError:(NSError *)error; 41 | 42 | - (void)transfer:(CATLogTransfer *)sock didReceiveData:(NSData *)data 43 | fromAddress:(NSData *)address 44 | withFilterContext:(id)filterContext; 45 | 46 | - (void)transferDidClose:(CATLogTransfer *)sock withError:(NSError *)error; 47 | 48 | @end 49 | 50 | typedef BOOL (^CATLogTransferReceiveFilterBlock)(NSData *data, NSData *address, id *context); 51 | 52 | typedef BOOL (^CATLogTransferSendFilterBlock)(NSData *data, NSData *address, long tag); 53 | 54 | 55 | @interface CATLogTransfer : NSObject 56 | 57 | - (id)init; 58 | - (id)initWithSocketQueue:(dispatch_queue_t)sq; 59 | - (id)initWithDelegate:(id )aDelegate delegateQueue:(dispatch_queue_t)dq; 60 | - (id)initWithDelegate:(id )aDelegate delegateQueue:(dispatch_queue_t)dq socketQueue:(dispatch_queue_t)sq; 61 | 62 | #pragma mark Configuration 63 | 64 | - (id )delegate; 65 | - (void)setDelegate:(id )delegate; 66 | - (void)synchronouslySetDelegate:(id )delegate; 67 | 68 | - (dispatch_queue_t)delegateQueue; 69 | - (void)setDelegateQueue:(dispatch_queue_t)delegateQueue; 70 | - (void)synchronouslySetDelegateQueue:(dispatch_queue_t)delegateQueue; 71 | 72 | - (void)getDelegate:(id *)delegatePtr delegateQueue:(dispatch_queue_t *)delegateQueuePtr; 73 | - (void)setDelegate:(id )delegate delegateQueue:(dispatch_queue_t)delegateQueue; 74 | - (void)synchronouslySetDelegate:(id )delegate delegateQueue:(dispatch_queue_t)delegateQueue; 75 | 76 | - (BOOL)isIPv4Enabled; 77 | - (void)setIPv4Enabled:(BOOL)flag; 78 | 79 | - (BOOL)isIPv6Enabled; 80 | - (void)setIPv6Enabled:(BOOL)flag; 81 | 82 | - (BOOL)isIPv4Preferred; 83 | - (BOOL)isIPv6Preferred; 84 | - (BOOL)isIPVersionNeutral; 85 | 86 | - (void)setPreferIPv4; 87 | - (void)setPreferIPv6; 88 | - (void)setIPVersionNeutral; 89 | 90 | - (uint16_t)maxReceiveIPv4BufferSize; 91 | - (void)setMaxReceiveIPv4BufferSize:(uint16_t)max; 92 | 93 | - (uint32_t)maxReceiveIPv6BufferSize; 94 | - (void)setMaxReceiveIPv6BufferSize:(uint32_t)max; 95 | 96 | - (id)userData; 97 | - (void)setUserData:(id)arbitraryUserData; 98 | 99 | #pragma mark Diagnostics 100 | - (NSData *)localAddress; 101 | - (NSString *)localHost; 102 | - (uint16_t)localPort; 103 | 104 | - (NSData *)localAddress_IPv4; 105 | - (NSString *)localHost_IPv4; 106 | - (uint16_t)localPort_IPv4; 107 | 108 | - (NSData *)localAddress_IPv6; 109 | - (NSString *)localHost_IPv6; 110 | - (uint16_t)localPort_IPv6; 111 | 112 | - (NSData *)connectedAddress; 113 | - (NSString *)connectedHost; 114 | - (uint16_t)connectedPort; 115 | - (BOOL)isConnected; 116 | - (BOOL)isClosed; 117 | - (BOOL)isIPv4; 118 | - (BOOL)isIPv6; 119 | 120 | #pragma mark Binding 121 | - (BOOL)bindToPort:(uint16_t)port error:(NSError **)errPtr; 122 | - (BOOL)bindToPort:(uint16_t)port interface:(NSString *)interface error:(NSError **)errPtr; 123 | - (BOOL)bindToAddress:(NSData *)localAddr error:(NSError **)errPtr; 124 | 125 | #pragma mark Connecting 126 | - (BOOL)connectToHost:(NSString *)host onPort:(uint16_t)port error:(NSError **)errPtr; 127 | 128 | - (BOOL)connectToAddress:(NSData *)remoteAddr error:(NSError **)errPtr; 129 | 130 | #pragma mark Multicast 131 | - (BOOL)joinMulticastGroup:(NSString *)group error:(NSError **)errPtr; 132 | - (BOOL)joinMulticastGroup:(NSString *)group onInterface:(NSString *)interface error:(NSError **)errPtr; 133 | 134 | - (BOOL)leaveMulticastGroup:(NSString *)group error:(NSError **)errPtr; 135 | - (BOOL)leaveMulticastGroup:(NSString *)group onInterface:(NSString *)interface error:(NSError **)errPtr; 136 | 137 | #pragma mark Reuse Port 138 | - (BOOL)enableReusePort:(BOOL)flag error:(NSError **)errPtr; 139 | 140 | #pragma mark Broadcast 141 | - (BOOL)enableBroadcast:(BOOL)flag error:(NSError **)errPtr; 142 | 143 | #pragma mark Sending 144 | - (void)sendData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag; 145 | 146 | - (void)sendData:(NSData *)data 147 | toHost:(NSString *)host 148 | port:(uint16_t)port 149 | withTimeout:(NSTimeInterval)timeout 150 | tag:(long)tag; 151 | 152 | - (void)sendData:(NSData *)data toAddress:(NSData *)remoteAddr withTimeout:(NSTimeInterval)timeout tag:(long)tag; 153 | 154 | - (void)setSendFilter:(CATLogTransferSendFilterBlock)filterBlock withQueue:(dispatch_queue_t)filterQueue; 155 | 156 | - (void)setSendFilter:(CATLogTransferSendFilterBlock)filterBlock 157 | withQueue:(dispatch_queue_t)filterQueue 158 | isAsynchronous:(BOOL)isAsynchronous; 159 | 160 | #pragma mark Receiving 161 | - (BOOL)receiveOnce:(NSError **)errPtr; 162 | 163 | - (BOOL)beginReceiving:(NSError **)errPtr; 164 | 165 | - (void)pauseReceiving; 166 | 167 | - (void)setReceiveFilter:(CATLogTransferReceiveFilterBlock)filterBlock withQueue:(dispatch_queue_t)filterQueue; 168 | 169 | - (void)setReceiveFilter:(CATLogTransferReceiveFilterBlock)filterBlock 170 | withQueue:(dispatch_queue_t)filterQueue 171 | isAsynchronous:(BOOL)isAsynchronous; 172 | 173 | #pragma mark Closing 174 | - (void)close; 175 | - (void)closeAfterSending; 176 | 177 | #pragma mark Advanced 178 | - (void)markSocketQueueTargetQueue:(dispatch_queue_t)socketQueuesPreConfiguredTargetQueue; 179 | - (void)unmarkSocketQueueTargetQueue:(dispatch_queue_t)socketQueuesPreviouslyConfiguredTargetQueue; 180 | 181 | - (void)performBlock:(dispatch_block_t)block; 182 | 183 | - (int)socketFD; 184 | - (int)socket4FD; 185 | - (int)socket6FD; 186 | 187 | #if TARGET_OS_IPHONE 188 | - (CFReadStreamRef)readStream; 189 | - (CFWriteStreamRef)writeStream; 190 | #endif 191 | 192 | #pragma mark Utilities 193 | 194 | + (NSString *)hostFromAddress:(NSData *)address; 195 | + (uint16_t)portFromAddress:(NSData *)address; 196 | + (int)familyFromAddress:(NSData *)address; 197 | 198 | + (BOOL)isIPv4Address:(NSData *)address; 199 | + (BOOL)isIPv6Address:(NSData *)address; 200 | 201 | + (BOOL)getHost:(NSString **)hostPtr port:(uint16_t *)portPtr fromAddress:(NSData *)address; 202 | + (BOOL)getHost:(NSString **)hostPtr port:(uint16_t *)portPtr family:(int *)afPtr fromAddress:(NSData *)address; 203 | 204 | @end -------------------------------------------------------------------------------- /CATLog/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /CATLog/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // CATLog 4 | // 5 | // Created by zengcatch on 16/4/20. 6 | // Copyright © 2016年 zengcatch. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /CATLog/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // CATLog 4 | // 5 | // Created by zengcatch on 16/4/20. 6 | // Copyright © 2016年 zengcatch. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "CATLog.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | [self performSelector:@selector(showFile) withObject:nil afterDelay:2.0f]; 22 | } 23 | 24 | -(void)showFile{ 25 | [CATLog showAllLogFile]; 26 | // [CATLog showTodayLogFile]; 27 | } 28 | 29 | - (void)didReceiveMemoryWarning { 30 | [super didReceiveMemoryWarning]; 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /CATLog/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CATLog 4 | // 5 | // Created by zengcatch on 16/4/20. 6 | // Copyright © 2016年 zengcatch. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CATLogServer.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatchZeng/CATLog/60e2aca990f5b8f1aa25906b499ed77f2b57c457/CATLogServer.zip -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Catch Zeng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CATLog 2 | 3 | [![Pod Version](https://github.com/CatchZeng/CATLog/blob/master/pod.png)](http://cocoadocs.org/docsets/CATLog/) 4 | 5 | 6 | An iOS log system,contains many excellent features,based on [Xcodecolors](https://github.com/robbiehanson/XcodeColors) and [KZLinkedConsole](https://github.com/krzysztofzablocki/KZLinkedConsole). 7 | 8 | ## New Feature 9 | 10 | - Add log review and email the log files in the App 11 | 12 | - Add mac client to help you debug without the data line.(mac client called CATLogServer.zip is included in the project file) 13 | 14 | - Add custom background color for log 15 | 16 | 中文请下翻 17 | 18 | ## Effect 19 | ![effect](https://github.com/CatchZeng/CATLog/blob/master/CATLog.gif) 20 | 21 | ![alllog](https://github.com/CatchZeng/CATLog/blob/master/alllog.jpg) 22 | 23 | ![preview](https://github.com/CatchZeng/CATLog/blob/master/preview.jpg) 24 | 25 | ![email](https://github.com/CatchZeng/CATLog/blob/master/email.jpg) 26 | 27 | ## Requirements 28 | This library requires a deployment target of iOS 6.0 or greater. 29 | 30 | ## Features 31 | 32 | ### CATLog is Simple: 33 | 34 | It takes as little as a single line of code to configure CATLog when your application launches.Then replace your NSLog statements with CLog[X] statements and that's about it. 35 | 36 | ### CATLog is Powerful: 37 | - Log level 38 | - Log file 39 | - Log crash 40 | - Auto delete old log file 41 | - Custom log macro easily 42 | - Colorizing debugger console output 43 | - Clickable links in your Xcode console, so you never wonder which class logged the message. 44 | - Remote log to mac client (debug without the data line) 45 | - Log review and email the log files 46 | 47 | ## Adding CATLog to your project 48 | 49 | ### Pod 50 | 51 | `pod 'CATLog'` 52 | 53 | ### Source files 54 | 55 | Alternatively you can directly add the `CATLog.h`& `CATLog.m` source files to your project. 56 | 57 | ## Usage 58 | 59 | #### 1.Install [Xcodecolors](https://github.com/robbiehanson/XcodeColors) by [Alcatraz](https://github.com/alcatraz/Alcatraz) 60 | 61 | ![Xcodecolors](https://github.com/CatchZeng/CATLog/blob/master/xcodecolors.jpg) 62 | 63 | #### 2.Install [KZLinkedConsole](https://github.com/krzysztofzablocki/KZLinkedConsole) by [Alcatraz](https://github.com/alcatraz/Alcatraz) 64 | 65 | ![KZLinkedConsole](https://github.com/CatchZeng/CATLog/blob/master/kzlinkedconsole.jpg) 66 | 67 | #### 3.Code 68 | 69 | ##### Init log && Set exceptionHandler 70 | 71 | ```objective-c 72 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 73 | //Set ExceptionHandler 74 | NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); 75 | //Init log 76 | [CATLog initWithNumberOfDaysToDelete:3]; 77 | } 78 | 79 | void uncaughtExceptionHandler(NSException *exception){ 80 | [CATLog logCrash:exception]; 81 | } 82 | ``` 83 | 84 | ##### Set log level 85 | 86 | ```objective-c 87 | [CATLog setLogLevel:CATLevelE]; 88 | ``` 89 | 90 | ##### If you do not like default log color,you can set color for each level. 91 | 92 | ```objective-c 93 | [CATLog setR:200 G:200 B:200 forLevel:CATLevelE]; 94 | ``` 95 | 96 | ##### If you do not like use CLog,you can custom log macro you need. 97 | 98 | ```objective-c 99 | #define YouLogI(fmt, ...) [CATLog logI:[NSString stringWithFormat:@"[%@:%d] %s %@",[NSString stringWithFormat:@"%s",__FILE__].lastPathComponent,__LINE__,__func__,fmt],##__VA_ARGS__,@""]; 100 | YouLogI(@"ReDefine Log by yourself"); 101 | ``` 102 | 103 | ##### Show Log review 104 | 105 | ```objective-c 106 | [CATLog shwoAllLogFile]; 107 | ``` 108 | 109 | ```objective-c 110 | [CATLog showTodayLogFile]; 111 | ``` 112 | 113 | 114 | ## Change Log 115 | 116 | #### V1.1.0 117 | 118 | 1.Fix numberOfDaysToDelete bug 119 | 120 | 2.Add log review and email the log files in the App 121 | 122 | #### V1.0.2 123 | 124 | 1.Fix pod bug 125 | 126 | 2.Add mac client 127 | 128 | #### V1.0.0 129 | 130 | Add project 131 | 132 | 133 | ---- 134 | 135 | # CATLog 136 | [![Pod Version](https://github.com/CatchZeng/CATLog/blob/master/pod.png)](http://cocoadocs.org/docsets/CATLog/) 137 | 138 | 一个基于[Xcodecolors](https://github.com/robbiehanson/XcodeColors)和[KZLinkedConsole](https://github.com/krzysztofzablocki/KZLinkedConsole),拥有许多优良特性的iOS开源日志工具。 139 | 140 | ## 新特性 141 | - 增加日志的预览和邮件发送日志功能 142 | - 增加mac客户端,让你可以无需连接数据线调试。(mac客户端在本工程的CATLogServer.zip文件中) 143 | - 增加自定义log输出背景颜色功能 144 | 145 | ## 效果 146 | ![effect](https://github.com/CatchZeng/CATLog/blob/master/CATLog.gif) 147 | 148 | ![alllog](https://github.com/CatchZeng/CATLog/blob/master/alllog.jpg) 149 | 150 | ![preview](https://github.com/CatchZeng/CATLog/blob/master/preview.jpg) 151 | 152 | ![email](https://github.com/CatchZeng/CATLog/blob/master/email.jpg) 153 | 154 | ## Requirements 155 | iOS6或以上 156 | 157 | ## 特性 158 | 159 | ### CATLog 使用简单: 160 | 只需加入几行代码就可配置完毕。然后将NSLog换成CLog[X] 就可以了。 161 | 162 | ### CATLog 功能强大: 163 | - 支持设置日志级别 164 | - 支持日志输出到文件 165 | - 支持日志记录Crash信息 166 | - 自动删除旧的日志文件 167 | - 方便地自定义日志宏 168 | - 支持颜色打印日志 169 | - 支持点击日志信息跳转到代码中,方便定位错误信息。 170 | - 远程输出到mac客户端(无需连接数据线调试) 171 | - 日志的预览和邮件发送日志功能 172 | 173 | ## 将CATLog加入工程 174 | 175 | ### 使用Pod 176 | 177 | `pod 'CATLog'` 178 | 179 | ### 使用源码 180 | 181 | 直接拖拽 `CATLog.h`& `CATLog.m` 到工程中即可。 182 | 183 | ## 使用说明 184 | 185 | #### 1.先通过[Alcatraz](https://github.com/alcatraz/Alcatraz)安装[Xcodecolors](https://github.com/robbiehanson/XcodeColors) 186 | ![Xcodecolors](https://github.com/CatchZeng/CATLog/blob/master/xcodecolors.jpg) 187 | 188 | #### 2.再安装 [KZLinkedConsole](https://github.com/krzysztofzablocki/KZLinkedConsole) 189 | ![KZLinkedConsole](https://github.com/CatchZeng/CATLog/blob/master/kzlinkedconsole.jpg) 190 | 191 | #### 3.编码 192 | 193 | ##### 初始化 && 设置异常捕获 194 | 195 | ```objective-c 196 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 197 | //Set ExceptionHandler 198 | NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); 199 | //Init log 200 | [CATLog initWithNumberOfDaysToDelete:3]; 201 | } 202 | 203 | void uncaughtExceptionHandler(NSException *exception){ 204 | [CATLog logCrash:exception]; 205 | } 206 | ``` 207 | 208 | ##### 设置日志级别 209 | 210 | ```objective-c 211 | [CATLog setLogLevel:CATLevelE]; 212 | ``` 213 | ##### 设置删除几天前的日志文件 214 | 215 | ```objective-c 216 | [CATLog setNumberOfDaysToDelete:3]; 217 | ``` 218 | 219 | ##### 如果不喜欢默认的日志输出颜色,可以为每个级别设置自定义的颜色 220 | 221 | ```objective-c 222 | [CATLog setR:200 G:200 B:200 forLevel:CATLevelE]; 223 | ``` 224 | 225 | 226 | ##### 如果不喜欢用CLog作为日志宏,可以自定义 227 | 228 | ```objective-c 229 | #define YouLogI(fmt, ...) [CATLog logI:[NSString stringWithFormat:@"[%@:%d] %s %@",[NSString stringWithFormat:@"%s",__FILE__].lastPathComponent,__LINE__,__func__,fmt],##__VA_ARGS__,@""]; 230 | YouLogI(@"ReDefine Log by yourself"); 231 | ``` 232 | 233 | ##### 显示log预览界面 234 | 235 | ```objective-c 236 | [CATLog shwoAllLogFile]; 237 | ``` 238 | 239 | ```objective-c 240 | [CATLog showTodayLogFile]; 241 | ``` 242 | 243 | ## 版本信息 244 | 245 | #### V1.1.0 246 | 247 | 1.修复了设置删除日志文件天数的bug 248 | 249 | 2.增加日志的预览和邮件发送日志功能 250 | 251 | #### V1.0.2 252 | 253 | 1.修复pod问题 254 | 255 | 2.增加mac客户端 256 | 257 | #### V1.0.0 258 | 259 | 添加基本工程 260 | -------------------------------------------------------------------------------- /alllog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatchZeng/CATLog/60e2aca990f5b8f1aa25906b499ed77f2b57c457/alllog.jpg -------------------------------------------------------------------------------- /color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatchZeng/CATLog/60e2aca990f5b8f1aa25906b499ed77f2b57c457/color.jpg -------------------------------------------------------------------------------- /email.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatchZeng/CATLog/60e2aca990f5b8f1aa25906b499ed77f2b57c457/email.jpg -------------------------------------------------------------------------------- /kzlinkedconsole.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatchZeng/CATLog/60e2aca990f5b8f1aa25906b499ed77f2b57c457/kzlinkedconsole.jpg -------------------------------------------------------------------------------- /pod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatchZeng/CATLog/60e2aca990f5b8f1aa25906b499ed77f2b57c457/pod.png -------------------------------------------------------------------------------- /preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatchZeng/CATLog/60e2aca990f5b8f1aa25906b499ed77f2b57c457/preview.jpg -------------------------------------------------------------------------------- /xcodecolors.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatchZeng/CATLog/60e2aca990f5b8f1aa25906b499ed77f2b57c457/xcodecolors.jpg --------------------------------------------------------------------------------