Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 4764282

Browse files
committed
Lazily instantiates Clog profile to avoid issues with Jansi on Android
1 parent 999d822 commit 4764282

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

Clog/src/main/java/com/caseyjbrooks/clog/Clog.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ public static Priority getByKey(String key) {
5353
private static String currentProfileKey;
5454
private static ClogProfile currentProfile;
5555

56-
static {
57-
profileSuppliers = new HashMap<>();
58-
profiles = new HashMap<>();
59-
profiles.put(null, new ClogProfile());
60-
}
61-
6256
/**
6357
* Get the instance of Clog to log to. If the instance is defined, use that profile, otherwise
6458
* create a new default profile.
@@ -437,6 +431,7 @@ public static int wtf(String message, Throwable throwable, Object... args) {
437431
* @param clog the profile
438432
*/
439433
public static void addProfile(String key, ProfileSupplier clog) {
434+
if(profileSuppliers == null) profileSuppliers = new HashMap<>();
440435
profileSuppliers.put(key, clog);
441436
}
442437

@@ -446,6 +441,7 @@ public static void addProfile(String key, ProfileSupplier clog) {
446441
* @param key the key of the profile to remove
447442
*/
448443
public static void removeProfile(String key) {
444+
if(profiles == null) profiles = new HashMap<>();
449445
profiles.remove(key);
450446
}
451447

@@ -455,6 +451,7 @@ public static void removeProfile(String key) {
455451
* @param key the key of the profile to use
456452
*/
457453
public static ClogProfile setCurrentProfile(String key) {
454+
if(profiles == null) profiles = new HashMap<>();
458455
Clog.currentProfileKey = key;
459456
Clog.currentProfile = profiles.get(key);
460457
return getInstance();
@@ -477,6 +474,7 @@ public static ClogProfile setCurrentProfile(String key, ProfileSupplier clog) {
477474
* @return the map of profiles
478475
*/
479476
public static Map<String, ClogProfile> getProfiles() {
477+
if(profiles == null) profiles = new HashMap<>();
480478
return profiles;
481479
}
482480

@@ -486,6 +484,7 @@ public static Map<String, ClogProfile> getProfiles() {
486484
* @param profiles the profile set to use
487485
*/
488486
public static void setAllProfiles(Map<String, ClogProfile> profiles) {
487+
if(profiles == null) throw new NullPointerException("profiles cannot be null");
489488
Clog.profiles = profiles;
490489
}
491490
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
3+
version: '1.6.4'
4+
5+
---
6+
7+
- Lazily instantiates Clog profile to avoid issues with Jansi on Android

0 commit comments

Comments
 (0)