Skip to content

Commit fa25839

Browse files
committed
Removed logVerbosity from KMP code
1 parent 987095a commit fa25839

File tree

9 files changed

+117
-172
lines changed

9 files changed

+117
-172
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package com.pubnub.api.enums
1717
*
1818
* @see [Swift SDK Logging Documentation](https://www.pubnub.com/docs/sdks/swift/logging#log-levels)
1919
*/
20-
data class LogLevel(val levels: Set<Level>) {
20+
actual data class LogLevel(val levels: Set<Level>) {
2121
/**
2222
* Individual log level flags that can be combined.
2323
* Each level corresponds to a specific bitmask in the Swift SDK.
@@ -78,9 +78,11 @@ data class LogLevel(val levels: Set<Level>) {
7878
ALL
7979
}
8080

81-
companion object {
81+
actual companion object {
82+
8283
/** Logging disabled */
8384
val None = LogLevel(setOf(Level.NONE))
85+
actual val NONE = None
8486

8587
/** Only errors */
8688
val Error = LogLevel(setOf(Level.ERROR))

pubnub-kotlin/pubnub-kotlin-core-api/src/appleMain/kotlin/com/pubnub/api/v2/PNConfiguration.ios.kt

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ actual interface PNConfiguration {
1212
actual val subscribeKey: String
1313
actual val publishKey: String
1414
actual val secretKey: String
15-
16-
@Deprecated(
17-
message = "This setting will be removed in the future. Use logLevel instead.",
18-
level = DeprecationLevel.WARNING
19-
)
20-
actual val logVerbosity: PNLogVerbosity
2115
val logLevel: LogLevel
2216

2317
@Deprecated(
@@ -59,28 +53,19 @@ actual fun createPNConfiguration(
5953
get() = secretKey.orEmpty()
6054
override val authKey: String
6155
get() = authKey.orEmpty()
62-
override val logVerbosity: PNLogVerbosity
63-
get() = logVerbosity
6456
override val logLevel: LogLevel
6557
get() = LogLevel.None
6658
override val authToken: String?
6759
get() = null
6860
}
6961
}
7062

71-
@Deprecated(
72-
message = "logVerbosity is deprecated. Use createPNConfiguration with LogLevel instead.",
73-
replaceWith = ReplaceWith(
74-
"createPNConfiguration(userId, subscribeKey, publishKey, secretKey, logLevel, authToken)"
75-
),
76-
level = DeprecationLevel.WARNING
77-
)
7863
actual fun createPNConfiguration(
7964
userId: UserId,
8065
subscribeKey: String,
8166
publishKey: String,
8267
secretKey: String?,
83-
logVerbosity: PNLogVerbosity,
68+
logLevel: LogLevel,
8469
authToken: String?
8570
): PNConfiguration {
8671
return object : PNConfiguration {
@@ -91,38 +76,8 @@ actual fun createPNConfiguration(
9176
get() = secretKey.orEmpty()
9277
override val authKey: String
9378
get() = NO_AUTH_KEY
94-
override val logVerbosity: PNLogVerbosity
95-
get() = logVerbosity
96-
override val logLevel: LogLevel
97-
get() = LogLevel.None
98-
override val authToken: String?
99-
get() = authToken
100-
}
101-
}
102-
103-
fun createPNConfiguration(
104-
userId: UserId,
105-
subscribeKey: String,
106-
publishKey: String = "",
107-
secretKey: String? = null,
108-
logLevel: LogLevel = LogLevel.None,
109-
authToken: String? = null
110-
): PNConfiguration {
111-
return object : PNConfiguration {
112-
override val userId: UserId
113-
get() = userId
114-
override val subscribeKey: String
115-
get() = subscribeKey
116-
override val publishKey: String
117-
get() = publishKey
118-
override val secretKey: String
119-
get() = secretKey.orEmpty()
120-
override val logVerbosity: PNLogVerbosity
121-
get() = PNLogVerbosity.NONE
12279
override val logLevel: LogLevel
12380
get() = logLevel
124-
override val authKey: String
125-
get() = NO_AUTH_KEY
12681
override val authToken: String?
12782
get() = authToken
12883
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.pubnub.api.enums
2+
3+
/**
4+
* Platform-specific log level configuration.
5+
*
6+
* - **JVM**: This parameter is ignored. Configure logging via slf4j implementation.
7+
* - **JS**: Simple hierarchical log levels (NONE, ERROR, WARN, INFO, DEBUG, TRACE).
8+
* - **iOS**: Bitmask-based log levels that can be combined.
9+
*/
10+
expect class LogLevel {
11+
companion object {
12+
/** Logging disabled (default) */
13+
val NONE: LogLevel
14+
15+
// Additional common constants can be added
16+
}
17+
}

pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/v2/PNConfiguration.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.pubnub.api.v2
22

33
import com.pubnub.api.UserId
4+
import com.pubnub.api.enums.LogLevel
45
import com.pubnub.api.enums.PNLogVerbosity
56

67
expect interface PNConfiguration {
@@ -12,7 +13,6 @@ expect interface PNConfiguration {
1213
* The secretKey should only be used within a server side and never exposed to client devices.
1314
*/
1415
val secretKey: String
15-
val logVerbosity: PNLogVerbosity
1616

1717
@Deprecated(
1818
message = "This setting is deprecated because it relates to deprecated Access Manager (PAM V2) and will be removed in the future. " +
@@ -34,7 +34,7 @@ expect interface PNConfiguration {
3434
"(PAM V3) https://www.pubnub.com/docs/general/resources/migration-guides/pam-v3-migration ",
3535
level = DeprecationLevel.WARNING,
3636
replaceWith = ReplaceWith(
37-
"createPNConfiguration(userId, subscribeKey, publishKey, secretKey, logVerbosity)"
37+
"createPNConfiguration(userId, subscribeKey, publishKey, secretKey, logLevel, authToken)"
3838
),
3939
)
4040
expect fun createPNConfiguration(
@@ -46,18 +46,11 @@ expect fun createPNConfiguration(
4646
logVerbosity: PNLogVerbosity = PNLogVerbosity.NONE,
4747
): PNConfiguration
4848

49-
@Deprecated(
50-
message = "logVerbosity is deprecated. Use createPNConfiguration with LogLevel instead.",
51-
replaceWith = ReplaceWith(
52-
"createPNConfiguration(userId, subscribeKey, publishKey, secretKey, logLevel, authToken)"
53-
),
54-
level = DeprecationLevel.WARNING
55-
)
5649
expect fun createPNConfiguration(
5750
userId: UserId,
5851
subscribeKey: String,
5952
publishKey: String,
6053
secretKey: String? = null,
61-
logVerbosity: PNLogVerbosity = PNLogVerbosity.NONE,
54+
logLevel: LogLevel = LogLevel.NONE,
6255
authToken: String? = null
6356
): PNConfiguration

pubnub-kotlin/pubnub-kotlin-core-api/src/jsMain/kotlin/com/pubnub/api/enums/LogLevel.js.kt

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,59 @@ package com.pubnub.api.enums
33
/**
44
* JavaScript SDK log level.
55
*/
6-
enum class LogLevel {
7-
/**
8-
* Logging is disabled.
9-
* Default setting.
10-
*/
11-
NONE,
12-
13-
/**
14-
* Logs only error messages.
15-
* Most restrictive level.
16-
*/
17-
ERROR,
18-
19-
/**
20-
* Logs warnings and errors.
21-
* Includes: WARN, ERROR
22-
*/
23-
WARN,
24-
25-
/**
26-
* Logs informational messages, warnings, and errors.
27-
* Includes: INFO, WARN, ERROR
28-
*/
29-
INFO,
30-
31-
/**
32-
* Logs debug information and all higher severity levels.
33-
* Includes: DEBUG, INFO, WARN, ERROR
34-
*
35-
* Warning: May log sensitive information including API keys and message content.
36-
* Use only in development environments.
37-
*/
38-
DEBUG,
39-
40-
/**
41-
* Most verbose logging level. Logs all messages including internal traces.
42-
* Includes: TRACE, DEBUG, INFO, WARN, ERROR
43-
*
44-
* Warning: Logs sensitive information. Never enable in production.
45-
*/
46-
TRACE;
47-
48-
companion object {
49-
/** Default log level (logging disabled) */
6+
actual class LogLevel private constructor(private val name: String, internal val level: Int) {
7+
actual companion object {
8+
/**
9+
* Logging is disabled.
10+
* Default setting.
11+
*/
12+
actual val NONE: LogLevel = LogLevel("NONE", 0)
13+
14+
/**
15+
* Logs only error messages.
16+
* Most restrictive level.
17+
*/
18+
val ERROR: LogLevel = LogLevel("ERROR", 1)
19+
20+
/**
21+
* Logs warnings and errors.
22+
* Includes: WARN, ERROR
23+
*/
24+
val WARN: LogLevel = LogLevel("WARN", 2)
25+
26+
/**
27+
* Logs informational messages, warnings, and errors.
28+
* Includes: INFO, WARN, ERROR
29+
*/
30+
val INFO: LogLevel = LogLevel("INFO", 3)
31+
32+
/**
33+
* Logs debug information and all higher severity levels.
34+
* Includes: DEBUG, INFO, WARN, ERROR
35+
*
36+
* Warning: May log sensitive information including API keys and message content.
37+
* Use only in development environments.
38+
*/
39+
val DEBUG: LogLevel = LogLevel("DEBUG", 4)
40+
41+
/**
42+
* Most verbose logging level. Logs all messages including internal traces.
43+
* Includes: TRACE, DEBUG, INFO, WARN, ERROR
44+
*
45+
* Warning: Logs sensitive information. Never enable in production.
46+
*/
47+
val TRACE: LogLevel = LogLevel("TRACE", 5)
48+
5049
val DEFAULT = NONE
5150
}
51+
52+
override fun toString(): String = name
53+
54+
override fun equals(other: Any?): Boolean {
55+
if (this === other) return true
56+
if (other !is LogLevel) return false
57+
return level == other.level
58+
}
59+
60+
override fun hashCode(): Int = level
5261
}

pubnub-kotlin/pubnub-kotlin-core-api/src/jsMain/kotlin/com/pubnub/api/v2/PNConfiguration.js.kt

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ actual interface PNConfiguration {
1212
actual val subscribeKey: String
1313
actual val publishKey: String
1414
actual val secretKey: String
15-
16-
@Deprecated(
17-
message = "This setting will be removed in the future. Use logLevel instead.",
18-
level = DeprecationLevel.WARNING
19-
)
20-
actual val logVerbosity: PNLogVerbosity
2115
val logLevel: LogLevel
2216
val enableEventEngine: Boolean
2317

@@ -41,7 +35,7 @@ actual interface PNConfiguration {
4135
"(PAM V3) https://www.pubnub.com/docs/general/resources/migration-guides/pam-v3-migration ",
4236
level = DeprecationLevel.WARNING,
4337
replaceWith = ReplaceWith(
44-
"createPNConfiguration(userId, subscribeKey, publishKey, secretKey, logVerbosity)"
38+
"createPNConfiguration(userId, subscribeKey, publishKey, secretKey, logLevel, authToken)"
4539
),
4640
)
4741
actual fun createPNConfiguration(
@@ -67,26 +61,17 @@ actual fun createPNConfiguration(
6761
get() = null
6862
override val enableEventEngine: Boolean
6963
get() = true
70-
override val logVerbosity: PNLogVerbosity
71-
get() = logVerbosity
7264
override val logLevel: LogLevel
7365
get() = LogLevel.NONE
7466
}
7567
}
7668

77-
@Deprecated(
78-
message = "logVerbosity is deprecated. Use createPNConfiguration with LogLevel instead.",
79-
replaceWith = ReplaceWith(
80-
"createPNConfiguration(userId, subscribeKey, publishKey, secretKey, logLevel, authToken)"
81-
),
82-
level = DeprecationLevel.WARNING
83-
)
8469
actual fun createPNConfiguration(
8570
userId: UserId,
8671
subscribeKey: String,
8772
publishKey: String,
8873
secretKey: String?,
89-
logVerbosity: PNLogVerbosity,
74+
logLevel: LogLevel,
9075
authToken: String?
9176
): PNConfiguration {
9277
return object : PNConfiguration {
@@ -104,39 +89,7 @@ actual fun createPNConfiguration(
10489
get() = authToken
10590
override val enableEventEngine: Boolean
10691
get() = true
107-
override val logVerbosity: PNLogVerbosity
108-
get() = logVerbosity
109-
override val logLevel: LogLevel
110-
get() = LogLevel.NONE
111-
}
112-
}
113-
114-
fun createPNConfiguration(
115-
userId: UserId,
116-
subscribeKey: String,
117-
publishKey: String,
118-
secretKey: String? = null,
119-
logLevel: LogLevel? = LogLevel.NONE,
120-
authToken: String? = null
121-
): PNConfiguration {
122-
return object : PNConfiguration {
123-
override val userId: UserId
124-
get() = userId
125-
override val subscribeKey: String
126-
get() = subscribeKey
127-
override val publishKey: String
128-
get() = publishKey
129-
override val secretKey: String
130-
get() = secretKey.orEmpty()
131-
override val logVerbosity: PNLogVerbosity
132-
get() = PNLogVerbosity.NONE
13392
override val logLevel: LogLevel
134-
get() = logLevel ?: LogLevel.NONE
135-
override val enableEventEngine: Boolean
136-
get() = true
137-
override val authKey: String
138-
get() = NO_AUTH_KEY
139-
override val authToken: String?
140-
get() = authToken
93+
get() = logLevel
14194
}
14295
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.pubnub.api.enums
2+
3+
/**
4+
* JVM LogLevel (ignored - use slf4j configuration instead).
5+
*
6+
* This parameter exists for API consistency across platforms but has no effect on JVM.
7+
* To configure logging on JVM, add an slf4j implementation (e.g., logback, log4j2)
8+
* and configure it according to that implementation's documentation.
9+
*/
10+
actual class LogLevel private constructor(private val name: String) {
11+
actual companion object {
12+
/** Logging disabled (JVM: configure via slf4j) */
13+
actual val NONE: LogLevel = LogLevel("NONE")
14+
15+
val ERROR: LogLevel = LogLevel("ERROR")
16+
val WARN: LogLevel = LogLevel("WARN")
17+
val INFO: LogLevel = LogLevel("INFO")
18+
val DEBUG: LogLevel = LogLevel("DEBUG")
19+
val TRACE: LogLevel = LogLevel("TRACE")
20+
}
21+
22+
override fun toString(): String = name
23+
24+
override fun equals(other: Any?): Boolean {
25+
if (this === other) return true
26+
if (other !is LogLevel) return false
27+
return name == other.name
28+
}
29+
30+
override fun hashCode(): Int = name.hashCode()
31+
}

0 commit comments

Comments
 (0)