diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..463c619 --- /dev/null +++ b/.gitignore @@ -0,0 +1,61 @@ +# Created by https://www.toptal.com/developers/gitignore/api/macos,xcode,cocoapods +# Edit at https://www.toptal.com/developers/gitignore?templates=macos,xcode,cocoapods + +### CocoaPods ### +## CocoaPods GitIgnore Template + +# CocoaPods - Only use to conserve bandwidth / Save time on Pushing +# - Also handy if you have a large number of dependant pods +# - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE +Pods/ + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Xcode ### +## User settings +xcuserdata/ + +## Xcode 8 and earlier +*.xcscmblueprint +*.xccheckout + +### Xcode Patch ### +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcodeproj/project.xcworkspace/ +!*.xcworkspace/contents.xcworkspacedata +/*.gcno +**/xcshareddata/WorkspaceSettings.xcsettings + +# End of https://www.toptal.com/developers/gitignore/api/macos,xcode,cocoapods diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9ab1924 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [2023] [Wen Yongyang] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/MLogStoreExporter.podspec b/MLogStoreExporter.podspec new file mode 100644 index 0000000..d81f9fd --- /dev/null +++ b/MLogStoreExporter.podspec @@ -0,0 +1,25 @@ +Pod::Spec.new do |spec| + + spec.name = "MLogStoreExporter" + spec.version = "1.0.0" + spec.summary = "Export logs from Apple Unified Logging System store" + + spec.homepage = "https://gitlab.sca.im/iOS/alphahomswiftykit" + + spec.license = { :type => "MIT", :file => "LICENSE" } + + spec.author = { "Wen Yongyang" => "raeyeung.mon@gmail.com" } + spec.social_media_url = "https://github.com/monsoir" + + spec.swift_version = "5.0" + + # When using multiple platforms + spec.ios.deployment_target = "11.0" + + spec.source = { :git => "https://github.com/monsoir/MLogStoreExporter.git", :branch => "master", :tag => "#{spec.version}" } + + spec.source_files = ["MLogStoreExporter/MLogStoreExporter.h", "MLogStoreExporter/Source/**/*.swift"] + + spec.requires_arc = true + +end diff --git a/MLogStoreExporter.xcodeproj/project.pbxproj b/MLogStoreExporter.xcodeproj/project.pbxproj new file mode 100644 index 0000000..5da5e09 --- /dev/null +++ b/MLogStoreExporter.xcodeproj/project.pbxproj @@ -0,0 +1,477 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + 4426356B29E6C06C00F53627 /* MLogStoreExporter.docc in Sources */ = {isa = PBXBuildFile; fileRef = 4426356A29E6C06C00F53627 /* MLogStoreExporter.docc */; }; + 4426357129E6C06D00F53627 /* MLogStoreExporter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4426356629E6C06C00F53627 /* MLogStoreExporter.framework */; }; + 4426357629E6C06D00F53627 /* MLogStoreExporterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4426357529E6C06D00F53627 /* MLogStoreExporterTests.swift */; }; + 4426357729E6C06D00F53627 /* MLogStoreExporter.h in Headers */ = {isa = PBXBuildFile; fileRef = 4426356929E6C06C00F53627 /* MLogStoreExporter.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4426358229E6C0BA00F53627 /* MLogStoreExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4426358129E6C0BA00F53627 /* MLogStoreExporter.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 4426357229E6C06D00F53627 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 4426355D29E6C06C00F53627 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 4426356529E6C06C00F53627; + remoteInfo = MLogStoreExporter; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 4426356629E6C06C00F53627 /* MLogStoreExporter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MLogStoreExporter.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 4426356929E6C06C00F53627 /* MLogStoreExporter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MLogStoreExporter.h; sourceTree = ""; }; + 4426356A29E6C06C00F53627 /* MLogStoreExporter.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = MLogStoreExporter.docc; sourceTree = ""; }; + 4426357029E6C06D00F53627 /* MLogStoreExporterTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MLogStoreExporterTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 4426357529E6C06D00F53627 /* MLogStoreExporterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MLogStoreExporterTests.swift; sourceTree = ""; }; + 4426358129E6C0BA00F53627 /* MLogStoreExporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MLogStoreExporter.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 4426356329E6C06C00F53627 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4426356D29E6C06D00F53627 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 4426357129E6C06D00F53627 /* MLogStoreExporter.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4426355C29E6C06C00F53627 = { + isa = PBXGroup; + children = ( + 4426356829E6C06C00F53627 /* MLogStoreExporter */, + 4426357429E6C06D00F53627 /* MLogStoreExporterTests */, + 4426356729E6C06C00F53627 /* Products */, + ); + sourceTree = ""; + }; + 4426356729E6C06C00F53627 /* Products */ = { + isa = PBXGroup; + children = ( + 4426356629E6C06C00F53627 /* MLogStoreExporter.framework */, + 4426357029E6C06D00F53627 /* MLogStoreExporterTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 4426356829E6C06C00F53627 /* MLogStoreExporter */ = { + isa = PBXGroup; + children = ( + 4426356929E6C06C00F53627 /* MLogStoreExporter.h */, + 4426356A29E6C06C00F53627 /* MLogStoreExporter.docc */, + 4426358029E6C09500F53627 /* Source */, + ); + path = MLogStoreExporter; + sourceTree = ""; + }; + 4426357429E6C06D00F53627 /* MLogStoreExporterTests */ = { + isa = PBXGroup; + children = ( + 4426357529E6C06D00F53627 /* MLogStoreExporterTests.swift */, + ); + path = MLogStoreExporterTests; + sourceTree = ""; + }; + 4426358029E6C09500F53627 /* Source */ = { + isa = PBXGroup; + children = ( + 4426358129E6C0BA00F53627 /* MLogStoreExporter.swift */, + ); + path = Source; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 4426356129E6C06C00F53627 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 4426357729E6C06D00F53627 /* MLogStoreExporter.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 4426356529E6C06C00F53627 /* MLogStoreExporter */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4426357A29E6C06D00F53627 /* Build configuration list for PBXNativeTarget "MLogStoreExporter" */; + buildPhases = ( + 4426356129E6C06C00F53627 /* Headers */, + 4426356229E6C06C00F53627 /* Sources */, + 4426356329E6C06C00F53627 /* Frameworks */, + 4426356429E6C06C00F53627 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MLogStoreExporter; + productName = MLogStoreExporter; + productReference = 4426356629E6C06C00F53627 /* MLogStoreExporter.framework */; + productType = "com.apple.product-type.framework"; + }; + 4426356F29E6C06D00F53627 /* MLogStoreExporterTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4426357D29E6C06D00F53627 /* Build configuration list for PBXNativeTarget "MLogStoreExporterTests" */; + buildPhases = ( + 4426356C29E6C06D00F53627 /* Sources */, + 4426356D29E6C06D00F53627 /* Frameworks */, + 4426356E29E6C06D00F53627 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 4426357329E6C06D00F53627 /* PBXTargetDependency */, + ); + name = MLogStoreExporterTests; + productName = MLogStoreExporterTests; + productReference = 4426357029E6C06D00F53627 /* MLogStoreExporterTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 4426355D29E6C06C00F53627 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1430; + LastUpgradeCheck = 1430; + TargetAttributes = { + 4426356529E6C06C00F53627 = { + CreatedOnToolsVersion = 14.3; + }; + 4426356F29E6C06D00F53627 = { + CreatedOnToolsVersion = 14.3; + }; + }; + }; + buildConfigurationList = 4426356029E6C06C00F53627 /* Build configuration list for PBXProject "MLogStoreExporter" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 4426355C29E6C06C00F53627; + productRefGroup = 4426356729E6C06C00F53627 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 4426356529E6C06C00F53627 /* MLogStoreExporter */, + 4426356F29E6C06D00F53627 /* MLogStoreExporterTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 4426356429E6C06C00F53627 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4426356E29E6C06D00F53627 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 4426356229E6C06C00F53627 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4426356B29E6C06C00F53627 /* MLogStoreExporter.docc in Sources */, + 4426358229E6C0BA00F53627 /* MLogStoreExporter.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4426356C29E6C06D00F53627 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4426357629E6C06D00F53627 /* MLogStoreExporterTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 4426357329E6C06D00F53627 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 4426356529E6C06C00F53627 /* MLogStoreExporter */; + targetProxy = 4426357229E6C06D00F53627 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 4426357829E6C06D00F53627 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 4426357929E6C06D00F53627 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 4426357B29E6C06D00F53627 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; + PRODUCT_BUNDLE_IDENTIFIER = com.monsoir.MLogStoreExporter; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 4426357C29E6C06D00F53627 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; + PRODUCT_BUNDLE_IDENTIFIER = com.monsoir.MLogStoreExporter; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 4426357E29E6C06D00F53627 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.monsoir.MLogStoreExporterTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 4426357F29E6C06D00F53627 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.monsoir.MLogStoreExporterTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 4426356029E6C06C00F53627 /* Build configuration list for PBXProject "MLogStoreExporter" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4426357829E6C06D00F53627 /* Debug */, + 4426357929E6C06D00F53627 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4426357A29E6C06D00F53627 /* Build configuration list for PBXNativeTarget "MLogStoreExporter" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4426357B29E6C06D00F53627 /* Debug */, + 4426357C29E6C06D00F53627 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4426357D29E6C06D00F53627 /* Build configuration list for PBXNativeTarget "MLogStoreExporterTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4426357E29E6C06D00F53627 /* Debug */, + 4426357F29E6C06D00F53627 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 4426355D29E6C06C00F53627 /* Project object */; +} diff --git a/MLogStoreExporter.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/MLogStoreExporter.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/MLogStoreExporter.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/MLogStoreExporter.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/MLogStoreExporter.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/MLogStoreExporter.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/MLogStoreExporter/MLogStoreExporter.docc/MLogStoreExporter.md b/MLogStoreExporter/MLogStoreExporter.docc/MLogStoreExporter.md new file mode 100755 index 0000000..73da0bd --- /dev/null +++ b/MLogStoreExporter/MLogStoreExporter.docc/MLogStoreExporter.md @@ -0,0 +1,13 @@ +# ``MLogStoreExporter`` + +Summary + +## Overview + +Text + +## Topics + +### Group + +- ``Symbol`` \ No newline at end of file diff --git a/MLogStoreExporter/MLogStoreExporter.h b/MLogStoreExporter/MLogStoreExporter.h new file mode 100644 index 0000000..ddf43d1 --- /dev/null +++ b/MLogStoreExporter/MLogStoreExporter.h @@ -0,0 +1,18 @@ +// +// MLogStoreExporter.h +// MLogStoreExporter +// +// Created by monsoir on 4/12/23. +// + +#import + +//! Project version number for MLogStoreExporter. +FOUNDATION_EXPORT double MLogStoreExporterVersionNumber; + +//! Project version string for MLogStoreExporter. +FOUNDATION_EXPORT const unsigned char MLogStoreExporterVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/MLogStoreExporter/Source/MLogStoreExporter.swift b/MLogStoreExporter/Source/MLogStoreExporter.swift new file mode 100644 index 0000000..ecd1a59 --- /dev/null +++ b/MLogStoreExporter/Source/MLogStoreExporter.swift @@ -0,0 +1,127 @@ +// +// MLogStoreExporter.swift +// MLogStoreExporter +// +// Created by monsoir on 4/12/23. +// + +import OSLog + +@available(iOS 15.0, *) +public class MLogStoreExporter { + + public init(ext: String = "log") { + self.ext = ext + } + + private let ext: String + + public func export(to directory: URL, filename: String = UUID().uuidString, startDate: Date, overrideIfNeeded: Bool = false) throws -> LogFile { + try validate(directory: directory) + + let fullFileame = "\(filename).\(ext)" + let fileURL: URL = { + if #available(iOS 16.0, *) { + return directory.appending(component: fullFileame, directoryHint: .notDirectory) + } else { + return directory.appendingPathComponent(fullFileame, isDirectory: false) + } + }() + + let fileHandle = try createFileHandle(at: fileURL, overrideIfNeeded: overrideIfNeeded) + defer { fileHandle.closeFile() } + + try _export(at: startDate, to: fileHandle) + return .init(name: filename, url: fileURL, ext: ext) + } + + private func validate(directory: URL) throws { + var isDirectory: ObjCBool = false + let isDirectoryExist = FileManager.default.fileExists(atPath: directory.path, isDirectory: &isDirectory) + if !isDirectoryExist || !isDirectory.boolValue { + throw CreateLogFileFailure() + } + } + + private func createFileHandle(at url: URL, overrideIfNeeded: Bool) throws -> FileHandle { + if FileManager.default.fileExists(atPath: url.path) && !overrideIfNeeded { + throw CreateLogFileFailure() + } + + guard FileManager.default.createFile(atPath: url.path, contents: nil) else { throw CreateLogFileFailure() } + + let handle = try FileHandle(forWritingTo: url) + return handle + } + + private func _export(at date: Date, to fileHandle: FileHandle) throws { + try fileHandle.seekToEnd() + + guard let bundleIdentifier = Bundle.main.bundleIdentifier else { throw BundleIdentifierNotFoundFailure() } + + let store = try OSLogStore(scope: .currentProcessIdentifier) + let start = store.position(date: date) + let entries = try store.getEntries( + with: [], + at: start, + matching: NSPredicate(format: "subsystem == %@", bundleIdentifier) + ) + + let jsonEncoder = JSONEncoder() + + try entries.forEach { + if let entry = $0 as? OSLogEntryLog { + let item = LogItem(entry: entry) + let rawData = try jsonEncoder.encode(item) + try fileHandle.write(contentsOf: rawData) + if let newline = "\n".data(using: .utf8) { + try fileHandle.write(contentsOf: newline) + } + } + } + } +} + +@available(iOS 15.0, *) +extension MLogStoreExporter { + public struct CreateLogFileFailure: LocalizedError { + public var errorDescription: String? { "Failed to create a log file" } + } + + public struct BundleIdentifierNotFoundFailure: LocalizedError { + public var errorDescription: String? { "Bundle identifier not found" } + } + + public struct LogFile { + public let name: String + public let url: URL + public let ext: String + + public var fullName: String { "\(name).\(ext)" } + } + + fileprivate struct LogItem: Encodable { + + let entry: OSLogEntryLog + + private enum CodingKeys: String, CodingKey { + case date + case timestamp + case entry + case category + case thread + case level + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode("\(entry.date)", forKey: .date) + try container.encode(entry.date.timeIntervalSince1970, forKey: .timestamp) + try container.encode(entry.composedMessage, forKey: .entry) + try container.encode(entry.category, forKey: .category) + try container.encode(entry.threadIdentifier, forKey: .thread) + try container.encode(entry.level.rawValue, forKey: .level) + } + } +} diff --git a/MLogStoreExporterTests/MLogStoreExporterTests.swift b/MLogStoreExporterTests/MLogStoreExporterTests.swift new file mode 100644 index 0000000..1f353ea --- /dev/null +++ b/MLogStoreExporterTests/MLogStoreExporterTests.swift @@ -0,0 +1,36 @@ +// +// MLogStoreExporterTests.swift +// MLogStoreExporterTests +// +// Created by monsoir on 4/12/23. +// + +import XCTest +@testable import MLogStoreExporter + +final class MLogStoreExporterTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + // Any test you write for XCTest can be annotated as throws and async. + // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. + // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..85b28c5 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# MLogStoreExporter + +Export logs from Apple Unified Logging System store + +## Installation + +```rb +pod 'MLogStoreExporter', :git => "https://github.com/monsoir/MLogStoreExporter.git", :tag => 'v1.0.0' +``` + +## Usage + +```swift +import MLogStoreExporter + +let exporter = MLogStoreExporter() +let file = try exporter.export(to: <#local path to log file#>, startDate: <#start date#>, overrideIfNeeded: true) +``` + +- `file` contains the url to dumped file + +## Caveats + +- It's caller's responsibility to take care of the thread or queue in which the export executes + +