After a lot of digging, I managed to find a way to disable warning and error logs (not info logs unfortunately) in Google Tag Manager v7.0.0.
Code below is written in Swift 5:
static func turnOffGTMLogs() {
let tagClass: AnyClass? = NSClassFromString("TAGJSExportedInstructions")
guard
var properties = class_copyMethodList(tagClass, nil)
else { return }
let detourSelector = #selector(FirebaseInitializer.detour_logMessage(with:message:))
var pointed = properties.pointee
while(!pointed.isNil()) {
if method_getName(pointed).coreStoreDumpString.contains("logMessage") {
guard let detourMethod = class_getClassMethod(FirebaseInitializer.self, detourSelector) else { return }
let _ = class_replaceMethod(tagClass, method_getName(pointed), method_getImplementation(detourMethod), method_getTypeEncoding(pointed))
break
}
properties = properties.advanced(by: 1)
pointed = properties.pointee
}
}
@objc
static func detour_logMessage(with level: Int, message: String) {
return
}
Extension for opaque pointer:
private extension OpaquePointer {
/*Used to check if value pointed by the opaque pointer is nil (to silence compiler warnings as self == nil would also work)
It works by figuring out whether the pointer is a nil pointer, from it's debug description .*/
func isNil() -> Bool {
return !self.debugDescription.contains { "123456789abcdef".contains($0.lowercased()) }
}
After that you only need to call turnOffGTMLogs()
once (preferably in the same place where you initialise GTM, usually in AppDelegate
) to silence the log outputs.