forked from mirrors/linphone-iphone
Add Log
This commit is contained in:
parent
52b4bd9f56
commit
26dd731f84
2 changed files with 119 additions and 0 deletions
|
|
@ -11,6 +11,7 @@
|
|||
66C491FB2B24D32600CEA16D /* CoreExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C491FA2B24D32600CEA16D /* CoreExtension.swift */; };
|
||||
66C491FD2B24D36500CEA16D /* AudioRouteUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C491FC2B24D36500CEA16D /* AudioRouteUtils.swift */; };
|
||||
66C491FF2B24D4AC00CEA16D /* FileUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C491FE2B24D4AC00CEA16D /* FileUtils.swift */; };
|
||||
66C492012B24DB6900CEA16D /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66C492002B24DB6900CEA16D /* Log.swift */; };
|
||||
D706BA822ADD72D100278F45 /* DeviceRotationViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D706BA812ADD72D100278F45 /* DeviceRotationViewModifier.swift */; };
|
||||
D70C93DE2AC2D0F60063CA3B /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = D70C93DD2AC2D0F60063CA3B /* Localizable.xcstrings */; };
|
||||
D717071E2AC5922E0037746F /* ColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D717071D2AC5922E0037746F /* ColorExtension.swift */; };
|
||||
|
|
@ -94,6 +95,7 @@
|
|||
66C491FA2B24D32600CEA16D /* CoreExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreExtension.swift; sourceTree = "<group>"; };
|
||||
66C491FC2B24D36500CEA16D /* AudioRouteUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRouteUtils.swift; sourceTree = "<group>"; };
|
||||
66C491FE2B24D4AC00CEA16D /* FileUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUtils.swift; sourceTree = "<group>"; };
|
||||
66C492002B24DB6900CEA16D /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
|
||||
D706BA812ADD72D100278F45 /* DeviceRotationViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceRotationViewModifier.swift; sourceTree = "<group>"; };
|
||||
D70C93DD2AC2D0F60063CA3B /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
|
||||
D717071D2AC5922E0037746F /* ColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorExtension.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -212,6 +214,7 @@
|
|||
D7ADF5FF2AFE356400212231 /* Avatar.swift */,
|
||||
D7C48DF32AFA66F900D938CB /* EditContactController.swift */,
|
||||
66C491FE2B24D4AC00CEA16D /* FileUtils.swift */,
|
||||
66C492002B24DB6900CEA16D /* Log.swift */,
|
||||
D7D1698B2AE66FA500109A5C /* MagicSearchSingleton.swift */,
|
||||
D74C9D002ACB098C0021626A /* PermissionManager.swift */,
|
||||
D7C3650D2AF15BF200FE6142 /* PhotoPicker.swift */,
|
||||
|
|
@ -629,6 +632,7 @@
|
|||
D7A03FC62ACC458A0081A588 /* SplashScreen.swift in Sources */,
|
||||
D7A03FC02ACC2E390081A588 /* HistoryView.swift in Sources */,
|
||||
D748BF2E2ACD82E7004844EB /* ThirdPartySipAccountWarningFragment.swift in Sources */,
|
||||
66C492012B24DB6900CEA16D /* Log.swift in Sources */,
|
||||
D748BF2C2ACD82D2004844EB /* ThirdPartySipAccountLoginFragment.swift in Sources */,
|
||||
D74C9CF82ACACECE0021626A /* WelcomePage1Fragment.swift in Sources */,
|
||||
D7E6D0552AEBFCCE00A57AAF /* ContactsInnerFragment.swift in Sources */,
|
||||
|
|
|
|||
115
Linphone/Utils/Log.swift
Normal file
115
Linphone/Utils/Log.swift
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2023 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// swiftlint:disable line_length
|
||||
|
||||
// Singleton instance that logs both info from the App and from the core, using the core log level. ([app] log_level parameter in linphonerc-factory-app
|
||||
|
||||
import UIKit
|
||||
import os
|
||||
import linphonesw
|
||||
import linphone
|
||||
|
||||
class Log: LoggingServiceDelegate {
|
||||
|
||||
static let instance = Log()
|
||||
|
||||
var debugEnabled = true // Todo : bind to app parameters
|
||||
var service = LoggingService.Instance
|
||||
|
||||
private init() {
|
||||
service.domain = Bundle.main.bundleIdentifier!
|
||||
Core.setLogCollectionPath(path: Factory.Instance.getDownloadDir(context: UnsafeMutablePointer<Int8>(mutating: (Config.appGroupName as NSString).utf8String)))
|
||||
Core.enableLogCollection(state: LogCollectionState.Enabled)
|
||||
setMask()
|
||||
LoggingService.Instance.addDelegate(delegate: self)
|
||||
|
||||
}
|
||||
|
||||
func setMask() {
|
||||
if debugEnabled {
|
||||
LoggingService.Instance.logLevelMask = UInt(LogLevel.Fatal.rawValue + LogLevel.Error.rawValue + LogLevel.Warning.rawValue + LogLevel.Message.rawValue + LogLevel.Trace.rawValue + LogLevel.Debug.rawValue)
|
||||
} else {
|
||||
LoggingService.Instance.logLevelMask = UInt(LogLevel.Fatal.rawValue + LogLevel.Error.rawValue + LogLevel.Warning.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
let levelToStrings: [Int: String] =
|
||||
[LogLevel.Debug.rawValue: "Debug"
|
||||
, LogLevel.Trace.rawValue: "Trace"
|
||||
, LogLevel.Message.rawValue: "Message"
|
||||
, LogLevel.Warning.rawValue: "Warning"
|
||||
, LogLevel.Error.rawValue: "Error"
|
||||
, LogLevel.Fatal.rawValue: "Fatal"]
|
||||
|
||||
let levelToOSleLogLevel: [Int: OSLogType] =
|
||||
[LogLevel.Debug.rawValue: .debug,
|
||||
LogLevel.Trace.rawValue: .info,
|
||||
LogLevel.Message.rawValue: .info,
|
||||
LogLevel.Warning.rawValue: .error,
|
||||
LogLevel.Error.rawValue: .error,
|
||||
LogLevel.Fatal.rawValue: .fault]
|
||||
|
||||
public class func debug(_ message: String) {
|
||||
instance.service.debug(message: message)
|
||||
}
|
||||
public class func info(_ message: String) {
|
||||
instance.service.message(message: message)
|
||||
}
|
||||
public class func warn(_ message: String) {
|
||||
instance.service.warning(message: message)
|
||||
}
|
||||
public class func error(_ message: String) {
|
||||
instance.service.error(message: message)
|
||||
}
|
||||
public class func fatal(_ message: String) {
|
||||
instance.service.fatal(message: message)
|
||||
}
|
||||
|
||||
private func output(_ message: String, _ level: Int, _ domain: String = Bundle.main.bundleIdentifier!) {
|
||||
let log = "[\(domain)][\(levelToStrings[level] ?? "Unkown")] \(message)\n"
|
||||
if #available(iOS 10.0, *) {
|
||||
os_log("%{public}@", type: levelToOSleLogLevel[level] ?? .info,log)
|
||||
} else {
|
||||
NSLog(log)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func onLogMessageWritten(logService: linphonesw.LoggingService, domain: String, level: linphonesw.LogLevel, message: String) {
|
||||
output(message, level.rawValue, domain)
|
||||
}
|
||||
|
||||
public class func stackTrace() {
|
||||
Thread.callStackSymbols.forEach{ print($0) }
|
||||
}
|
||||
|
||||
// Debug
|
||||
public class func cdlog(_ message: String) {
|
||||
info("cdes>\(message)")
|
||||
}
|
||||
public class func bmlog(_ message: String) {
|
||||
info("bmar>\(message)")
|
||||
}
|
||||
public class func qelog(_ message: String) {
|
||||
info("qarg>\(message)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// swiftlint:enable line_length
|
||||
Loading…
Add table
Reference in a new issue