Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#XD-1170 fix #224

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal fun ODatabaseSession.applyIndices(indices: Map<String, Set<DeferredInde
internal class IndicesCreator(
private val indicesByOwnerVertexName: Map<String, Set<DeferredIndex>>
) {
private val logger = PaddedLogger(log)
private val logger = PaddedLogger.logger(log)

fun createIndices(oSession: ODatabaseSession) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ internal class OrientDbSchemaInitializer(
private val indexForEverySimpleProperty: Boolean,
private val applyLinkCardinality: Boolean
) {
private val paddedLogger = PaddedLogger(log)
private val paddedLogger = PaddedLogger.logger(log)

private fun withPadding(code: () -> Unit) = paddedLogger.withPadding(4, code)

Expand All @@ -152,6 +152,7 @@ internal class OrientDbSchemaInitializer(
}

fun apply(): SchemaApplicationResult {
val start = System.currentTimeMillis()
try {
oSession.createClassIdSequenceIfAbsent()

Expand Down Expand Up @@ -221,6 +222,7 @@ internal class OrientDbSchemaInitializer(
)
} finally {
paddedLogger.flush()
log.info("Schema initialization took ${System.currentTimeMillis() - start}ms")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Copyright ${inceptionYear} - ${year} ${owner}
*
Expand All @@ -17,30 +18,42 @@ package jetbrains.exodus.query.metadata

import mu.KLogger

class PaddedLogger(
interface PaddedLogger {
companion object {
//todo switch to configuration loading
private val VERBOSE_LOGGING get() = System.getProperty("jetbrains.xodus.oxigendb.verbose_schema_logging", "false").toBoolean()
fun logger(logger: KLogger): PaddedLogger = if (VERBOSE_LOGGING) PaddedLoggerImpl(logger) else DisabledPaddedLogger()
}
fun append(s: String)
fun appendLine(s: String)
fun updatePadding(paddingShift: Int)
fun flush()
}

class PaddedLoggerImpl(
private val logger: KLogger
) {
) : PaddedLogger {
private var paddingCount: Int = 0
private val sb = StringBuilder()

private var newLine: Boolean = false

fun append(s: String) {
override fun append(s: String) {
addPaddingIfNewLine()
sb.append(s)
}

fun appendLine(s: String = "") {
override fun appendLine(s: String) {
addPaddingIfNewLine()
sb.appendLine(s)
newLine = true
}

fun updatePadding(paddingShift: Int) {
override fun updatePadding(paddingShift: Int) {
paddingCount += paddingShift
}

fun flush() {
override fun flush() {
// trim last \n
if (sb.isNotEmpty() && sb.last() == '\n') {
sb.setLength(sb.length - 1)
Expand All @@ -63,4 +76,14 @@ fun PaddedLogger.withPadding(padding: Int = 4, code: () -> Unit) {
updatePadding(padding)
code()
updatePadding(-padding)
}
}

class DisabledPaddedLogger : PaddedLogger {
override fun append(s: String) = Unit

override fun appendLine(s: String) = Unit

override fun updatePadding(paddingShift: Int) = Unit

override fun flush() = Unit
}
Loading