0

I wanted to add a prefix to all my logs. I tried to subclass XCGLogger to override logln(...) or debug(...) functions.

But I am facing two difficulties while using this

  1. Compiler always give me error (see picture).
  2. I don't know how to customize the given log message as the parameter is a closure.

enter image description here

Thanks

ryancrunchi
  • 465
  • 2
  • 16
  • Please add a feature request here: https://github.com/DaveWoodCom/XCGLogger/issues and I'll add it. It's something I've wanted to add anyway, just has been low on the priority list. – Dave Wood Sep 19 '16 at 17:13

2 Answers2

0

Ok I found. We need to define a class or struct that conforms to LogFormatterProtocol and implement the format(logDetails: inout LogDetails, message: inout String) -> String function to modify the inout message. Then create an instance of that class or struct and add it to the destination formatters array :

let consoleDest = ConsoleDestination(owner: myLogger, identifier: "") // myLogger is an instance of XCGLogger
consoleDest.formatters = [MyFormatter()] // MyFormatter is a struct conforming to LogFormatterProtocol
myLogger.add(destination: consoleDest)
ryancrunchi
  • 465
  • 2
  • 16
0

The issue you've got in your code above, is that you're not being clear to the compiler which of the super.logln methods you're calling. Because there are multiple versions of the method, with various functions, some of which have defaults, you need to explicitly include enough of the parameters for the compiler to know which version you're calling. That's why your error messages say "Ambiguous..."

Dave Wood
  • 13,143
  • 2
  • 59
  • 67