Skip to content

Commit

Permalink
Use macro for debugging (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
sushichop authored Aug 13, 2022
1 parent ff9270c commit b8dc015
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Build a Swift package
run: swift build -v -c release
- name: Test a Swift package
run: swift test -v
run: swift test -v -Xswiftc -DPUPPY_DEBUG

swiftpm-backwards:
name: SwiftPM - Swift ${{ matrix.swift-version }} on ${{ matrix.os }}
Expand All @@ -53,7 +53,7 @@ jobs:
- name: Build a Swift package
run: swift build -v -c release
- name: Test a Swift package
run: swift test -v
run: swift test -v -Xswiftc -DPUPPY_DEBUG

cmake:
name: CMake - Swift ${{ matrix.swift-version }} on ${{ matrix.os }}
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## [0.5.0](https://github.com/sushichop/Puppy/releases/tag/x.y.z) (2022-02-28)
## [x.y.z](https://github.com/sushichop/Puppy/releases/tag/x.y.z) (yyyy-mm-dd)

- Use macro for debugging. [#50](https://github.com/sushichop/Puppy/pull/50)

## [0.5.0](https://github.com/sushichop/Puppy/releases/tag/0.5.0) (2022-02-28)

- Remove concurrency features. [#39](https://github.com/sushichop/Puppy/pull/39)
- Fix the default rotation type to `numbering`. [#40](https://github.com/sushichop/Puppy/pull/40)
Expand Down
2 changes: 1 addition & 1 deletion Configurations/Common.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ MARKETING_VERSION = 0.5.0
DYLIB_CURRENT_VERSION = 1
CURRENT_PROJECT_VERSION = $(DYLIB_CURRENT_VERSION)

SCP_COPYRIGHT = Copyright (c) 2020-2021 Koichi Yokota
SCP_COPYRIGHT = Copyright (c) 2020-2022 Koichi Yokota
SCP_PRODUCT_BUNDLE_IDENTIFIER_PREFIX = net.sushichop
2 changes: 2 additions & 0 deletions Configurations/Framework.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ APPLICATION_EXTENSION_API_ONLY = YES
ENABLE_BITCODE = YES
BITCODE_GENERATION_MODE = bitcode
OTHER_CFLAGS = -fembed-bitcode

//SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) PUPPY_DEBUG
8 changes: 4 additions & 4 deletions Sources/Puppy/FileLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class FileLogger: BaseLogger {
self.fileURL = fileURL
self.filePermission = filePermission
self.flushMode = flushMode
debug("fileURL is \(fileURL).")
puppyDebug("initialized, fileURL: \(fileURL)")
super.init(label)
try validateFileURL(fileURL)
try validateFilePermission(fileURL, filePermission: filePermission)
Expand Down Expand Up @@ -85,20 +85,20 @@ public class FileLogger: BaseLogger {
let directoryURL = fileURL.deletingLastPathComponent()
do {
try FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
debug("created directoryURL, directoryURL: \(directoryURL)")
puppyDebug("created directoryURL, directoryURL: \(directoryURL)")
} catch {
throw FileError.creatingDirectoryFailed(at: directoryURL)
}

if !FileManager.default.fileExists(atPath: fileURL.path) {
let successful = FileManager.default.createFile(atPath: fileURL.path, contents: nil, attributes: [FileAttributeKey.posixPermissions: uintPermission])
if successful {
debug("succeeded in creating filePath")
puppyDebug("succeeded in creating filePath")
} else {
throw FileError.creatingFileFailed(at: fileURL)
}
} else {
debug("filePath exists, filePath: \(fileURL.path)")
puppyDebug("filePath exists, filePath: \(fileURL.path)")
}

if fileHandle == nil {
Expand Down
10 changes: 5 additions & 5 deletions Sources/Puppy/FileRotationLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class FileRotationLogger: FileLogger {
for (index, oldArchivedFileURL) in oldArchivedFileURLs.enumerated() {
let generationNumber = oldArchivedFileURLs.count + 1 - index
let rotatedFileURL = oldArchivedFileURL.deletingPathExtension().appendingPathExtension("\(generationNumber)")
debug("generationNumber: \(generationNumber), rotatedFileURL: \(rotatedFileURL)")
puppyDebug("generationNumber: \(generationNumber), rotatedFileURL: \(rotatedFileURL)")
if !FileManager.default.fileExists(atPath: rotatedFileURL.path) {
try FileManager.default.moveItem(at: oldArchivedFileURL, to: rotatedFileURL)
}
Expand Down Expand Up @@ -68,7 +68,7 @@ public class FileRotationLogger: FileLogger {

// Opens a new target file.
do {
debug("will openFile in rotateFiles")
puppyDebug("will openFile in rotateFiles")
try openFile()
} catch {
print("error in openFile while rotating, error: \(error.localizedDescription)")
Expand Down Expand Up @@ -99,7 +99,7 @@ public class FileRotationLogger: FileLogger {
} catch {
print("error in ascArchivedFileURLs, error: \(error.localizedDescription)")
}
debug("ascArchivedFileURLs: \(ascArchivedFileURLs)")
puppyDebug("ascArchivedFileURLs: \(ascArchivedFileURLs)")
return ascArchivedFileURLs
}

Expand All @@ -108,9 +108,9 @@ public class FileRotationLogger: FileLogger {
let archivedFileURLs = ascArchivedFileURLs(fileURL)
if archivedFileURLs.count > maxArchivedFilesCount {
for index in 0 ..< archivedFileURLs.count - Int(maxArchivedFilesCount) {
debug("\(archivedFileURLs[index]) will be removed...")
puppyDebug("\(archivedFileURLs[index]) will be removed...")
try FileManager.default.removeItem(at: archivedFileURLs[index])
debug("\(archivedFileURLs[index]) has been removed")
puppyDebug("\(archivedFileURLs[index]) has been removed")
delegate?.fileRotationLogger(self, didRemoveArchivedFileURL: archivedFileURLs[index])
}
}
Expand Down
12 changes: 4 additions & 8 deletions Sources/Puppy/Puppy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ typealias Log = Puppy

public class Puppy {

public static var useDebug = false
public static let `default` = Puppy()

public private(set) var loggers = Set<BaseLogger>()

public init() {}
Expand Down Expand Up @@ -108,10 +106,8 @@ public class Puppy {
}

@inlinable
func debug(_ items: Any) {
#if DEBUG
if Puppy.useDebug {
print("Puppy:", items)
}
#endif // DEBUG
func puppyDebug(_ items: Any) {
#if DEBUG && PUPPY_DEBUG
print("PUPPY_DEBUG:", items)
#endif // DEBUG && PUPPY_DEBUG
}
2 changes: 0 additions & 2 deletions Tests/PuppyTests/FileLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ final class FileLoggerTests: XCTestCase {

override func setUpWithError() throws {
try super.setUpWithError()
Puppy.useDebug = true
}

override func tearDownWithError() throws {
Puppy.useDebug = false
try super.tearDownWithError()
}

Expand Down
2 changes: 0 additions & 2 deletions Tests/PuppyTests/FileManager+WindowsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ class FileManagerWindowsTests: XCTestCase {

override func setUpWithError() throws {
try super.setUpWithError()
Puppy.useDebug = true
}

override func tearDownWithError() throws {
Puppy.useDebug = false
try super.tearDownWithError()
}

Expand Down
2 changes: 0 additions & 2 deletions Tests/PuppyTests/FileRotationLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ final class FileRotationLoggerTests: XCTestCase {

override func setUpWithError() throws {
try super.setUpWithError()
Puppy.useDebug = true
}

override func tearDownWithError() throws {
Puppy.useDebug = false
try super.tearDownWithError()
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/llvm-cov-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [ "${SCRIPT_TYPE}" = "export" ]; then
fi

swift package clean
swift test --enable-code-coverage
swift test -v -Xswiftc -DPUPPY_DEBUG --enable-code-coverage

BIN_PATH="$(swift build --show-bin-path)"
XCTEST_PATH="$(find ${BIN_PATH} -name '*.xctest')"
Expand Down

0 comments on commit b8dc015

Please sign in to comment.