Swiftpack.co - 0xLeif/SwiftUILogger as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by 0xLeif.
0xLeif/SwiftUILogger 0.1.0
Logging to a SwiftUI View
⭐️ 6
🕓 1 year ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/0xLeif/SwiftUILogger.git", from: "0.1.0")

SwiftUILogger

Logging to a SwiftUI View

What is SwiftUILogger?

SwiftUILogger allows you to log events by reference. Then you can display all the events using the LoggerView and passing the logger into the initalizer.

Why use SwiftUILogger?

SwiftUILogger can be used while developing and testing your application to quickly see the debug logs without needing to be attached to LLDB session or Xcode.

Example Usage

import SwiftUI
import SwiftUILogger

let logger = SwiftUILogger(name: "Demo")

@main
struct SwiftUILogger_DemoApp: App {
    @State private var isPresentedLogger: Bool = false

    var body: some Scene {
        WindowGroup {
            NavigationStack {
                ContentView()
                    .sheet(isPresented: $isPresentedLogger) {
                        LoggerView(logger: logger)
                    }
                    .toolbar {
                        Button(
                            action: { isPresentedLogger.toggle() },
                            label: { Image(systemName: "ladybug") }
                        )
                    }
            }
        }
    }
}

// MARK: - ContentView

struct ContentView: View {
    init() {
        logger.log(level: .info, message: "init")
    }

    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
        .onAppear {
            logger.log(level: .info, message: "onAppear")
        }
    }
}

GitHub

link
Stars: 6
Last commit: 17 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.1.0
1 year ago

SwiftUILogger

Logging to a SwiftUI View

What is SwiftUILogger?

SwiftUILogger allows you to log events by reference. Then you can display all the events using the LoggerView and passing the logger into the initalizer.

Why use SwiftUILogger?

SwiftUILogger can be used while developing and testing your application to quickly see the debug logs without needing to be attached to LLDB session or Xcode.

Example Usage

import SwiftUI
import SwiftUILogger

let logger = SwiftUILogger(name: "Demo")

@main
struct SwiftUILogger_DemoApp: App {
    @State private var isPresentedLogger: Bool = false

    var body: some Scene {
        WindowGroup {
            NavigationStack {
                ContentView()
                    .sheet(isPresented: $isPresentedLogger) {
                        LoggerView(logger: logger)
                    }
                    .toolbar {
                        Button(
                            action: { isPresentedLogger.toggle() },
                            label: { Image(systemName: "ladybug") }
                        )
                    }
            }
        }
    }
}

// MARK: - ContentView

struct ContentView: View {
    init() {
        logger.log(level: .info, message: "init")
    }

    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
        .onAppear {
            logger.log(level: .info, message: "onAppear")
        }
    }
}

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics