Skip to content

Commit

Permalink
feat: improve logging system to filter markers (#1270)
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering authored Mar 19, 2024
1 parent 721370e commit e89bf41
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 32 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ buildscript {
preferenceVersion = '1.2.0'

// Utils
slf4jVersion = '1.7.32'
slf4jVersion = '2.0.7'
desugaringLibraryVersion = '1.1.5'

// UI
Expand Down
21 changes: 1 addition & 20 deletions wallet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ dependencies {
implementation "com.google.zxing:core:$zxingVersion"

implementation "org.slf4j:slf4j-api:$slf4jVersion"
implementation('com.github.tony19:logback-android-classic:1.1.1-6') {
implementation('com.github.tony19:logback-android:3.0.0') {
exclude(group: 'com.google.android', module: 'android')
}
implementation 'com.github.tony19:logback-android-core:1.1.1-6'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'com.tbuonomo:dotsindicator:4.2'
implementation 'com.github.amulyakhare:textdrawable:558677ea31'
Expand Down Expand Up @@ -243,24 +242,6 @@ android {
}
}

signingConfigs {
debug {
storeFile file('keystore/debug.keystore')
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}

signingConfigs {
debug {
storeFile file('keystore/debug.keystore')
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}

buildTypes {
all {
def imgurClientId = props.getProperty("IMGUR_CLIENT_ID")
Expand Down
Binary file removed wallet/keystore/debug.keystore
Binary file not shown.
16 changes: 12 additions & 4 deletions wallet/src/de/schildbach/wallet/WalletApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
import org.dash.wallet.features.exploredash.utils.DashDirectConstants;
import org.dash.wallet.integrations.coinbase.service.CoinBaseClientConstants;

import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy;
import ch.qos.logback.core.util.FileSize;
import de.schildbach.wallet.service.BlockchainStateDataProvider;
import de.schildbach.wallet.service.PackageInfoProvider;
import de.schildbach.wallet.service.WalletFactory;
Expand Down Expand Up @@ -123,7 +125,6 @@
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.rolling.RollingFileAppender;
import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;
import dagger.hilt.android.HiltAndroidApp;
import org.dash.wallet.common.data.entity.BlockchainState;
import de.schildbach.wallet.database.dao.BlockchainStateDao;
Expand All @@ -142,6 +143,7 @@
import de.schildbach.wallet.security.PinRetryController;
import de.schildbach.wallet.util.AllowLockTimeRiskAnalysis;
import de.schildbach.wallet.util.CrashReporter;
import de.schildbach.wallet.util.LogMarkerFilter;
import de.schildbach.wallet.util.MnemonicCodeExt;
import de.schildbach.wallet_test.BuildConfig;
import de.schildbach.wallet_test.R;
Expand Down Expand Up @@ -576,6 +578,8 @@ private void initLogging() {

final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

final LogMarkerFilter markerFilter = new LogMarkerFilter();

final PatternLayoutEncoder filePattern = new PatternLayoutEncoder();
filePattern.setContext(context);
filePattern.setPattern("%d{HH:mm:ss,UTC} [%thread] %logger{0} - %msg%n");
Expand All @@ -585,16 +589,19 @@ private void initLogging() {
fileAppender.setContext(context);
fileAppender.setFile(logFile.getAbsolutePath());

final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
final SizeAndTimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new SizeAndTimeBasedRollingPolicy<ILoggingEvent>();
rollingPolicy.setContext(context);
rollingPolicy.setParent(fileAppender);
rollingPolicy.setFileNamePattern(logDir.getAbsolutePath() + "/wallet.%d{yyyy-MM-dd,UTC}.log.gz");
rollingPolicy.setMaxHistory(7);
rollingPolicy.setFileNamePattern(logDir.getAbsolutePath() + "/wallet.%i.%d{yyyy-MM-dd,UTC}.log.gz");
rollingPolicy.setMaxHistory(20);
rollingPolicy.setMaxFileSize(FileSize.valueOf("10MB"));
rollingPolicy.setTotalSizeCap(FileSize.valueOf("200MB"));
rollingPolicy.start();


fileAppender.setEncoder(filePattern);
fileAppender.setRollingPolicy(rollingPolicy);
fileAppender.addFilter(markerFilter);
fileAppender.start();

final PatternLayoutEncoder logcatTagPattern = new PatternLayoutEncoder();
Expand All @@ -611,6 +618,7 @@ private void initLogging() {
logcatAppender.setContext(context);
logcatAppender.setTagEncoder(logcatTagPattern);
logcatAppender.setEncoder(logcatPattern);
logcatAppender.addFilter(markerFilter);
logcatAppender.start();

final ch.qos.logback.classic.Logger log = context.getLogger(Logger.ROOT_LOGGER_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ private void handleBlockchainStateNotification(BlockchainState blockchainState,
final Intent broadcast = new Intent(ACTION_BLOCKCHAIN_STATE);
broadcast.setPackage(getPackageName());
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
log.info("handle blockchain state notification: {}, {}", foregroundService, mixingStatus);
// log.info("handle blockchain state notification: {}, {}", foregroundService, mixingStatus);
this.mixingProgress = mixingProgress;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && blockchainState != null
&& blockchainState.getBestChainDate() != null) {
Expand Down
11 changes: 5 additions & 6 deletions wallet/src/de/schildbach/wallet/service/CoinJoinService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton


enum class CoinJoinMode {
NONE,
INTERMEDIATE,
Expand Down Expand Up @@ -120,7 +121,7 @@ class CoinJoinMixingService @Inject constructor(
val log: Logger = LoggerFactory.getLogger(CoinJoinMixingService::class.java)
const val DEFAULT_MULTISESSION = false // for stability, need to investigate
const val DEFAULT_ROUNDS = 4
const val DEFAULT_SESSIONS = 4
const val DEFAULT_SESSIONS = 6
const val DEFAULT_DENOMINATIONS_GOAL = 50
const val DEFAULT_DENOMINATIONS_HARDCAP = 300

Expand Down Expand Up @@ -188,6 +189,7 @@ class CoinJoinMixingService @Inject constructor(
override fun observeMixingProgress(): Flow<Double> = _progressFlow

init {
//initLogging()
blockchainStateProvider.observeNetworkStatus()
.filterNot { it == NetworkStatus.UNKNOWN }
.onEach { status ->
Expand Down Expand Up @@ -250,7 +252,7 @@ class CoinJoinMixingService @Inject constructor(
}
}

suspend fun getCurrentTimeSkew(): Long {
private suspend fun getCurrentTimeSkew(): Long {
return try {
getTimeSkew()
} catch (e: Exception) {
Expand Down Expand Up @@ -404,7 +406,6 @@ class CoinJoinMixingService @Inject constructor(
message: PoolMessage?
) {
super.onSessionStarted(wallet, sessionId, denomination, message)
log.info("Session started: {}. {}% mixed. {} active sessions", sessionId, progress, activeSessions + 1)
updateActiveSessions()
}

Expand All @@ -418,13 +419,11 @@ class CoinJoinMixingService @Inject constructor(
joined: Boolean
) {
super.onSessionComplete(wallet, sessionId, denomination, state, message, address, joined)
log.info("Session completed: {}. {}% mixed. {} active sessions", sessionId, progress, activeSessions - 1)
updateActiveSessions()
}

override fun onTransactionProcessed(tx: Transaction?, type: CoinJoinTransactionType?, sessionId: Int) {
super.onTransactionProcessed(tx, type, sessionId)
log.info("coinjoin-tx {} in session {} {}", type, sessionId, tx?.txId)
coroutineScope.launch {
updateProgress()
}
Expand Down Expand Up @@ -652,7 +651,7 @@ class CoinJoinMixingService @Inject constructor(
} else {
0
}
log.info("coinjoin-activeSessions: {}", activeSessions)
// log.info("coinjoin-activeSessions: {}", activeSessions)
activeSessionsFlow.emit(activeSessions)
}
}
Expand Down
29 changes: 29 additions & 0 deletions wallet/src/de/schildbach/wallet/util/LogMarkerFilter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.schildbach.wallet.util

import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.filter.Filter
import ch.qos.logback.core.spi.FilterReply

class LogMarkerFilter(acceptedMarkers: List<String>) : Filter<ILoggingEvent?>() {

constructor() : this(listOf())

private val acceptedMarkers = arrayListOf<String>()

init {
this.acceptedMarkers.addAll(acceptedMarkers)
}

fun addAcceptedMarker(marker: String) {
acceptedMarkers.add(marker)
}
override fun decide(event: ILoggingEvent?): FilterReply {
val marker = event?.markers?.get(0) ?: return FilterReply.ACCEPT

return if (acceptedMarkers.contains(marker.name)) {
FilterReply.ACCEPT
} else {
FilterReply.DENY
}
}
}

0 comments on commit e89bf41

Please sign in to comment.