Skip to content

Commit

Permalink
Merge pull request #98 from SpryRocks/merge-cap2
Browse files Browse the repository at this point in the history
Merge cap2
  • Loading branch information
Maxim Zhemerenko authored Nov 29, 2023
2 parents ef320d0 + e0650fc commit 992ae3d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 18 deletions.
4 changes: 2 additions & 2 deletions ios/src/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ open class CorePlugin<TDelegate : CoreDelegate, TMappers: CoreMappers>: IPluginL
wrapperDelegate.sendEvent(event.name, event.getData())
}

public func sendLog(_ action: String?, _ tag: String?, _ type: LogType, _ message: String, _ params: LogParams) {
sendEvent(LogEvent<TDelegate, TMappers>(action: action, tag: tag, type: type, message: message, params: params))
public func sendLog(_ action: String?, _ tag: String?, _ level: LogLevel, _ message: String, _ params: LogParams) {
sendEvent(LogEvent<TDelegate, TMappers>(action: action, tag: tag, level: level, message: message, params: params))
}

public func call(_ actionType: CoreBaseAction<TDelegate, TMappers>.Type, _ call: CAPPluginCall) {
Expand Down
4 changes: 3 additions & 1 deletion ios/src/actions/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ open class CoreLogMapper {
}
}

internal func getLogTypeValue(_ type: LogType) -> String {
internal func getLogTypeValue(_ type: LogLevel) -> String {
switch(type) {
case .Warning:
return "Warning"
Expand All @@ -96,6 +96,8 @@ open class CoreLogMapper {
return "Info"
case .Error:
return "Error"
case .Trace:
return "Trace"
}
}

Expand Down
7 changes: 5 additions & 2 deletions ios/src/logs/ILogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ public protocol WithLogger {

public typealias LogParams = Dictionary<String, Any?>

public enum LogType: Int {
public enum LogLevel: Int {
case Warning
case Debug
case Info
case Error
case Trace
}

public protocol IPluginLogger {
func sendLog(_ action: String?, _ tag: String?, _ type: LogType, _ message: String, _ params: LogParams)
func sendLog(_ action: String?, _ tag: String?, _ type: LogLevel, _ message: String, _ params: LogParams)
}

public protocol ILogger {
Expand All @@ -25,6 +26,8 @@ public protocol ILogger {
func info(message: String)
func error(message: String, params: LogParams?)
func error(message: String)
func trace(message: String, params: LogParams?)
func trace(message: String)
func tag(_ tag: String) -> ILogger
func child() -> ILogger
func updateParams(_ params: LogParams)
Expand Down
2 changes: 2 additions & 0 deletions ios/src/logs/ILoggerLegacy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public protocol ILoggerLegacy {
func info(message: String)
func error(message: String, params: LogParamsLegacy?)
func error(message: String)
func trace(message: String, params: LogParamsLegacy?)
func trace(message: String)
func tag(_ tag: String) -> ILoggerLegacy
func child() -> ILoggerLegacy
func updateParams(_ params: LogParamsLegacy)
Expand Down
13 changes: 9 additions & 4 deletions ios/src/logs/LogEvent.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
public class LogEvent<TDelegate, TMappers>: CoreBaseEvent<TDelegate, TMappers> where TDelegate : CoreDelegate, TMappers : CoreMappers {
private let action: String?
private let tag: String?
private let type: LogType
private let level: LogLevel
private let message: String
private let params: LogParams

init(action: String?, tag: String?, type: LogType, message: String, params: LogParams) {
init(action: String?,
tag: String?,
level: LogLevel,
message: String,
params: LogParams
) {
self.action = action
self.tag = tag
self.type = type
self.level = level
self.message = message
self.params = params
super.init(name: "log")
Expand All @@ -17,7 +22,7 @@ public class LogEvent<TDelegate, TMappers>: CoreBaseEvent<TDelegate, TMappers> w
public override func getData() -> JsonObject {
let logMapper = mappers.logMapper
let data = mutableJsonObject()
data.put("type", logMapper.getLogTypeValue(type))
data.put("level", logMapper.getLogTypeValue(level))
if let action = action {
data.put("action", action)
}
Expand Down
16 changes: 12 additions & 4 deletions ios/src/logs/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,45 @@ public class Logger : NSObject, ILogger {
}

public func warning(message: String, params: LogParams?) {
pluginLogger.sendLog(action, tag, LogType.Warning, message, prepareParams(params))
pluginLogger.sendLog(action, tag, LogLevel.Warning, message, prepareParams(params))
}

public func warning(message: String) {
warning(message: message, params: nil)
}

public func debug(message: String, params: LogParams?) {
pluginLogger.sendLog(action, tag, LogType.Debug, message, prepareParams(params))
pluginLogger.sendLog(action, tag, LogLevel.Debug, message, prepareParams(params))
}

public func debug(message: String) {
debug(message: message, params: nil)
}

public func info(message: String, params: LogParams?) {
pluginLogger.sendLog(action, tag, LogType.Info, message, prepareParams(params))
pluginLogger.sendLog(action, tag, LogLevel.Info, message, prepareParams(params))
}

public func info(message: String) {
info(message: message, params: nil)
}

public func error(message: String, params: LogParams?) {
pluginLogger.sendLog(action, tag, LogType.Error, message, prepareParams(params))
pluginLogger.sendLog(action, tag, LogLevel.Error, message, prepareParams(params))
}

public func error(message: String) {
error(message: message, params: nil)
}

public func trace(message: String, params: LogParams?) {
pluginLogger.sendLog(action, tag, LogLevel.Trace, message, prepareParams(params))
}

public func trace(message: String) {
trace(message: message, params: nil)
}

public func tag(_ tag: String) -> ILogger {
return Logger(action: action, tag: tag, params: nil, pluginLogger: pluginLogger)
}
Expand Down
16 changes: 12 additions & 4 deletions ios/src/logs/LoggerLegacy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,45 @@ public class LoggerLegacy : NSObject, ILoggerLegacy {
}

public func warning(message: String, params: LogParamsLegacy?) {
pluginLogger.sendLog(action, tag, LogType.Warning, message, prepareParams(params))
pluginLogger.sendLog(action, tag, LogLevel.Warning, message, prepareParams(params))
}

public func warning(message: String) {
warning(message: message, params: nil)
}

public func debug(message: String, params: LogParamsLegacy?) {
pluginLogger.sendLog(action, tag, LogType.Debug, message, prepareParams(params))
pluginLogger.sendLog(action, tag, LogLevel.Debug, message, prepareParams(params))
}

public func debug(message: String) {
debug(message: message, params: nil)
}

public func info(message: String, params: LogParamsLegacy?) {
pluginLogger.sendLog(action, tag, LogType.Info, message, prepareParams(params))
pluginLogger.sendLog(action, tag, LogLevel.Info, message, prepareParams(params))
}

public func info(message: String) {
info(message: message, params: nil)
}

public func error(message: String, params: LogParamsLegacy?) {
pluginLogger.sendLog(action, tag, LogType.Error, message, prepareParams(params))
pluginLogger.sendLog(action, tag, LogLevel.Error, message, prepareParams(params))
}

public func error(message: String) {
error(message: message, params: nil)
}

public func trace(message: String, params: LogParamsLegacy?) {
pluginLogger.sendLog(action, tag, LogLevel.Trace, message, prepareParams(params))
}

public func trace(message: String) {
trace(message: message, params: nil)
}

public func tag(_ tag: String) -> ILoggerLegacy {
return LoggerLegacy(action: action, tag: tag, params: nil, pluginLogger: pluginLogger)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spryrocks/capacitor-ionic-core-plugin",
"version": "2.5.5-alpha.0",
"version": "2.5.6-alpha.0",
"description": "Ionic plugin core capacitor",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down

0 comments on commit 992ae3d

Please sign in to comment.