Coder Social home page Coder Social logo

Comments (4)

ktoso avatar ktoso commented on June 11, 2024

You didn't finish implementing your log handler, in the screenshot you paste the solution is included: @available(*, deprecated, message: "You should implement this method instead of using the default implementation")

    @available(*, deprecated, message: "You should implement this method instead of using the default implementation")
    public func log(level: Logger.Level,
                    message: Logger.Message,
                    metadata: Logger.Metadata?,
                    source: String,
                    file: String,
                    function: String,
                    line: UInt) {
// ... 
    }

you have to implement this method. It delegates to old methods for compatibility with existing LogHandler implementations which used the "old" API. This way we did not break source compat when adding the new handler APIs.

Please implement the above method and things will work as expected.

from swift-log.

ktoso avatar ktoso commented on June 11, 2024

Double checked, yeah this works correctly:

import Logging

@main
public struct untitled4 {

    public static func main() {
        LoggingSystem.bootstrap(Hello.init)

        var log = Logger(label: "unique.value")
        log[metadataKey: "mykey"] = "jelly"
        log.error("hi")
    }
}

struct Hello: LogHandler {

    var metadata: Logging.Logger.Metadata = [:]

    var logLevel: Logging.Logger.Level = .error

    init(_ label: String) {
    }

    subscript(metadataKey metadataKey: String) -> Logger.Metadata.Value? {
        get {
            return self.metadata[metadataKey]
        }
        set(newValue) {
            self.metadata[metadataKey] = newValue
        }
    }

    // REQUIRED
     func log(level: Logger.Level,
                    message: Logger.Message,
                    metadata: Logger.Metadata?,
                    source: String,
                    file: String,
                    function: String,
                    line: UInt) {
        print("message: \(message)")
    }
}

Please complete your LogHandler implementation and it'll work fine.
If there's anything else here please feel free to comment or reopen the issue

from swift-log.

nashysolutions avatar nashysolutions commented on June 11, 2024

Please re-open this ticket :) I will submit a PR to fix.

from swift-log.

ktoso avatar ktoso commented on June 11, 2024

Commented more in the PR: #249
We can't do source breaking changes like this for quite a while.

from swift-log.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.