Skip to content

Passing FileName and LineNumber #57

Description

@nsinklier

open func error(_ message: @autoclosure @escaping () -> LogMessage) {

I don't see a way to attach the file name and line number to the logs, which would be useful for errors especially. Is this something you've considered and discarded or just something you haven't needed? I'm going to add it to my project, if it's something you're interested in, I'd be happy to make a PR at add this. This is basically the code:

// function
    open func error(_ message: @autoclosure @escaping () -> LogMessage, _ file: String = #file, _ line: Int = #line) {
        print("file = \(file)\nline = \(line)")
        logMessage(message, with: LogLevel.error)
    }

// function call (unchanged)
log.error(Message.requestFailed(request: request, response: fakeResponse, error: nil))

// resulting output
file = /Users/.../Desktop/Willow-5.1.0 2/Example/Frameworks/Database/Connection.swift
line = 63
2019-07-31 12:27:57.744 💣💥💣💥 [Database] => SQL Error: ["error_description": "The database file is locked", "framework_name": "Database", "result": "failure", "framework_version": "1.0", "sql": "CREATE TABLE cars(make TEXT NOT NULL, model TEXT NOT NULL)", "error_code": 5]

This would be especially helpful when creating a LogWriter to post logs to a server. That way you can determine error locations based on logs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions