Skip to content

Commit

Permalink
Add Log
Browse files Browse the repository at this point in the history
Add Log
  • Loading branch information
andrewfirsenko committed Oct 5, 2021
1 parent 7da0dab commit e9f2397
Show file tree
Hide file tree
Showing 35 changed files with 1,550 additions and 26 deletions.
11 changes: 6 additions & 5 deletions CSwiftLog.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

Pod::Spec.new do |s|
s.name = 'CSwiftLog'
s.version = '0.1.0'
s.summary = 'A short description of CSwiftLog.'
s.version = '1.0.0'
s.summary = 'Logger for Xcode'
s.swift_version = '5.0'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
Expand All @@ -21,11 +22,11 @@ Pod::Spec.new do |s|
TODO: Add long description of the pod here.
DESC

s.homepage = 'https://github.com/Andrew/CSwiftLog'
s.homepage = 'https://github.com/andrewfirsenko/CSwiftLog'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Andrew' => '[email protected]' }
s.source = { :git => 'https://github.com/Andrew/CSwiftLog.git', :tag => s.version.to_s }
s.author = { 'Andrew Firsenko' => '[email protected]' }
s.source = { :git => 'https://github.com/andrewfirsenko/CSwiftLog.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

s.ios.deployment_target = '9.0'
Expand Down
22 changes: 22 additions & 0 deletions CSwiftLog/Classes/Log+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Log+Extensions.swift
// SwiftLog
//
// Created by Andrew on 04.10.2021.
//

import Foundation

extension Log {

internal static func time(date: Date = Date(), style: Log.LogStyle = .short) -> String {
let df = DateFormatter()
switch style {
case .full:
df.dateFormat = "HH:mm:ss.SSS"
case .short:
df.dateFormat = "HH:mm:ss.SSS"
}
return df.string(from: date)
}
}
104 changes: 104 additions & 0 deletions CSwiftLog/Classes/Log.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// Log.swift
// SwiftLog
//
// Created by Andrew on 05.10.2021.
//

import Foundation

extension Log {

// Default categories
public static let ui = Log(category: "UI")
public static let network = Log(category: "NETWORK")

public enum LogType: String {
case error = "📕"
case warning = "📙"
case success = "📗"
case info = "📘"
case canceled = "📓"
}

public enum LogStyle {
case full
case short
}

}

public class Log {

private var category: String? = nil

public init(category: String) {
self.category = category
}

// MARK: With category
public func log(
tag: String? = nil,
_ message: String,
_ type: LogType = .info,
style: LogStyle = .short,
file: String = #file,
function: String = #function,
line: Int = #line
) {
Log.log(tag: tag, message, type, style: style, category: self.category, file: file, function: function, line: line)
}

// MARK: Not category
public static func log(
tag: String? = nil,
_ message: String,
_ type: LogType = .info,
style: LogStyle = .short,
file: String = #file,
function: String = #function,
line: Int = #line
) {
log(tag: tag, message, type, style: style, category: nil, file: file, function: function, line: line)
}

// MARK: Log
private static func log(
tag: String? = nil,
_ message: String,
_ type: LogType = .info,
style: LogStyle = .short,
category: String? = nil,
file: String = #file,
function: String = #function,
line: Int = #line
) {
#if DEBUG
let fileName = (file as NSString).lastPathComponent
// Add time
var printString = time(style: style)
// Add Type icon
printString.append(" " + type.rawValue)
// Add fileName|line|function
switch style {
case .full:
printString.append(" " + "[\(fileName): \(line)] \(function) ==>")
case .short:
printString.append(" " + "==>")
}
// Add category & tag
if let category = category, let tag = tag {
printString.append(" " + "[\(category)/\(tag)]")
} else if let category = category {
printString.append(" " + "[\(category)]")
} else if let tag = tag {
printString.append(" " + "[\(tag)]")
}
// Add message
printString.append(" " + message)

print(printString)
#endif
}

}
Empty file removed CSwiftLog/Classes/ReplaceMe.swift
Empty file.
42 changes: 21 additions & 21 deletions Example/CSwiftLog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/* Begin PBXFileReference section */
08876D370A21E22D0A49EFA3 /* Pods-CSwiftLog_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CSwiftLog_Example.release.xcconfig"; path = "Target Support Files/Pods-CSwiftLog_Example/Pods-CSwiftLog_Example.release.xcconfig"; sourceTree = "<group>"; };
2BA7B6C665B16D30A56DB9BE /* Pods_CSwiftLog_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CSwiftLog_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2C8ED527A922062649D6C582 /* CSwiftLog.podspec */ = {isa = PBXFileReference; includeInIndex = 1; name = CSwiftLog.podspec; path = ../CSwiftLog.podspec; sourceTree = "<group>"; };
2C8ED527A922062649D6C582 /* CSwiftLog.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = CSwiftLog.podspec; path = ../CSwiftLog.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
2F386B42DAF5B352E0D9E462 /* Pods-CSwiftLog_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CSwiftLog_Tests.release.xcconfig"; path = "Target Support Files/Pods-CSwiftLog_Tests/Pods-CSwiftLog_Tests.release.xcconfig"; sourceTree = "<group>"; };
57E175D74331B542BAEF894B /* Pods-CSwiftLog_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CSwiftLog_Example.debug.xcconfig"; path = "Target Support Files/Pods-CSwiftLog_Example/Pods-CSwiftLog_Example.debug.xcconfig"; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* CSwiftLog_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CSwiftLog_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -44,9 +44,9 @@
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
76C37CC557D73FBF51864F9A /* Pods-CSwiftLog_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CSwiftLog_Tests.debug.xcconfig"; path = "Target Support Files/Pods-CSwiftLog_Tests/Pods-CSwiftLog_Tests.debug.xcconfig"; sourceTree = "<group>"; };
849598E15FE136D49840B0CA /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; name = README.md; path = ../README.md; sourceTree = "<group>"; };
849598E15FE136D49840B0CA /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
B9045BA65B81191FB163EE24 /* Pods_CSwiftLog_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CSwiftLog_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FA1FE9E3C3C7353066CBCFF4 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
FA1FE9E3C3C7353066CBCFF4 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -77,7 +77,6 @@
76C37CC557D73FBF51864F9A /* Pods-CSwiftLog_Tests.debug.xcconfig */,
2F386B42DAF5B352E0D9E462 /* Pods-CSwiftLog_Tests.release.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -171,7 +170,7 @@
607FACCC1AFB9204008FA782 /* Sources */,
607FACCD1AFB9204008FA782 /* Frameworks */,
607FACCE1AFB9204008FA782 /* Resources */,
9288F5D29C51DE33E0B6F4D8 /* [CP] Embed Pods Frameworks */,
1597022740477E37D6A524E1 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -227,6 +226,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -262,44 +262,44 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
4A7839831CFCD769BE6EE8A0 /* [CP] Check Pods Manifest.lock */ = {
1597022740477E37D6A524E1 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-CSwiftLog_Example/Pods-CSwiftLog_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/CSwiftLog/CSwiftLog.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-CSwiftLog_Tests-checkManifestLockResult.txt",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CSwiftLog.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-CSwiftLog_Example/Pods-CSwiftLog_Example-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
9288F5D29C51DE33E0B6F4D8 /* [CP] Embed Pods Frameworks */ = {
4A7839831CFCD769BE6EE8A0 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-CSwiftLog_Example/Pods-CSwiftLog_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/CSwiftLog/CSwiftLog.framework",
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CSwiftLog.framework",
"$(DERIVED_FILE_DIR)/Pods-CSwiftLog_Tests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-CSwiftLog_Example/Pods-CSwiftLog_Example-frameworks.sh\"\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
C8698DD31A3E8C30CDEE6F85 /* [CP] Check Pods Manifest.lock */ = {
Expand Down
10 changes: 10 additions & 0 deletions Example/CSwiftLog.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
16 changes: 16 additions & 0 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PODS:
- CSwiftLog (0.1.0)

DEPENDENCIES:
- CSwiftLog (from `../`)

EXTERNAL SOURCES:
CSwiftLog:
:path: "../"

SPEC CHECKSUMS:
CSwiftLog: 935a2275435a48fd0e69df7a20f1c7a0560e5288

PODFILE CHECKSUM: 202d93f7aed4a586b9ba6a4ba466e56d0a7f16b4

COCOAPODS: 1.11.2
22 changes: 22 additions & 0 deletions Example/Pods/Local Podspecs/CSwiftLog.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e9f2397

Please sign in to comment.