Small logging refactoring

Most logs are now console.debug
Removed "Omnisearch" prefix in (almost) all logs
Removed timestamp prefix
This commit is contained in:
Simon Cambier
2024-11-09 17:46:48 +01:00
parent 1c98d8b2d7
commit ca3ca3b24b
12 changed files with 76 additions and 83 deletions

View File

@@ -60,7 +60,7 @@ export class Database extends Dexie {
paths, paths,
data: minisearchJson, data: minisearchJson,
}) })
console.log('Omnisearch - Search cache written') console.debug('Omnisearch - Search cache written')
} }
/** /**
@@ -74,7 +74,7 @@ export class Database extends Dexie {
db.version !== Database.dbVersion * 10 db.version !== Database.dbVersion * 10
) )
if (toDelete.length) { if (toDelete.length) {
console.log('Omnisearch - Those IndexedDb databases will be deleted:') console.debug('Omnisearch - Those IndexedDb databases will be deleted:')
for (const db of toDelete) { for (const db of toDelete) {
if (db.name) { if (db.name) {
indexedDB.deleteDatabase(db.name) indexedDB.deleteDatabase(db.name)

View File

@@ -32,11 +32,11 @@ import { notifyOnIndexed, registerAPI } from './tools/api'
import { Database } from './database' import { Database } from './database'
import { SearchEngine } from './search/search-engine' import { SearchEngine } from './search/search-engine'
import { DocumentsRepository } from './repositories/documents-repository' import { DocumentsRepository } from './repositories/documents-repository'
import { logDebug } from './tools/utils' import { logVerbose } from './tools/utils'
import { NotesIndexer } from './notes-indexer' import { NotesIndexer } from './notes-indexer'
import { TextProcessor } from './tools/text-processing' import { TextProcessor } from './tools/text-processing'
import { EmbedsRepository } from './repositories/embeds-repository' import { EmbedsRepository } from './repositories/embeds-repository'
import { SearchHistory } from "./search/search-history"; import { SearchHistory } from './search/search-history'
export default class OmnisearchPlugin extends Plugin { export default class OmnisearchPlugin extends Plugin {
// FIXME: fix the type // FIXME: fix the type
@@ -71,7 +71,7 @@ export default class OmnisearchPlugin extends Plugin {
} }
if (isPluginDisabled(this.app)) { if (isPluginDisabled(this.app)) {
console.log('Omnisearch - Plugin disabled') console.debug('Plugin disabled')
return return
} }
@@ -120,7 +120,7 @@ export default class OmnisearchPlugin extends Plugin {
file instanceof TFile && file instanceof TFile &&
this.notesIndexer.isFileIndexable(file.path) this.notesIndexer.isFileIndexable(file.path)
) { ) {
logDebug('Indexing new file', file.path) logVerbose('Indexing new file', file.path)
searchEngine.addFromPaths([file.path]) searchEngine.addFromPaths([file.path])
this.embedsRepository.refreshEmbedsForNote(file.path) this.embedsRepository.refreshEmbedsForNote(file.path)
} }
@@ -128,7 +128,7 @@ export default class OmnisearchPlugin extends Plugin {
) )
this.registerEvent( this.registerEvent(
this.app.vault.on('delete', file => { this.app.vault.on('delete', file => {
logDebug('Removing file', file.path) logVerbose('Removing file', file.path)
this.documentsRepository.removeDocument(file.path) this.documentsRepository.removeDocument(file.path)
searchEngine.removeFromPaths([file.path]) searchEngine.removeFromPaths([file.path])
this.embedsRepository.removeFile(file.path) this.embedsRepository.removeFile(file.path)
@@ -145,7 +145,7 @@ export default class OmnisearchPlugin extends Plugin {
this.registerEvent( this.registerEvent(
this.app.vault.on('rename', async (file, oldPath) => { this.app.vault.on('rename', async (file, oldPath) => {
if (this.notesIndexer.isFileIndexable(file.path)) { if (this.notesIndexer.isFileIndexable(file.path)) {
logDebug('Renaming file', file.path) logVerbose('Renaming file', file.path)
this.documentsRepository.removeDocument(oldPath) this.documentsRepository.removeDocument(oldPath)
await this.documentsRepository.addDocument(file.path) await this.documentsRepository.addDocument(file.path)
@@ -237,25 +237,23 @@ export default class OmnisearchPlugin extends Plugin {
} }
private async populateIndex(): Promise<void> { private async populateIndex(): Promise<void> {
console.time('Omnisearch - Indexing total time') console.time('Indexing total time')
indexingStep.set(IndexingStepType.ReadingFiles) indexingStep.set(IndexingStepType.ReadingFiles)
const files = this.app.vault const files = this.app.vault
.getFiles() .getFiles()
.filter(f => this.notesIndexer.isFileIndexable(f.path)) .filter(f => this.notesIndexer.isFileIndexable(f.path))
console.log(`Omnisearch - ${files.length} files total`) console.debug(`${files.length} files total`)
console.log( console.debug(`Cache is ${isCacheEnabled() ? 'enabled' : 'disabled'}`)
`Omnisearch - Cache is ${isCacheEnabled() ? 'enabled' : 'disabled'}`
)
// Map documents in the background // Map documents in the background
// Promise.all(files.map(f => cacheManager.addToLiveCache(f.path))) // Promise.all(files.map(f => cacheManager.addToLiveCache(f.path)))
const searchEngine = this.searchEngine const searchEngine = this.searchEngine
if (isCacheEnabled()) { if (isCacheEnabled()) {
console.time('Omnisearch - Loading index from cache') console.time('Loading index from cache')
indexingStep.set(IndexingStepType.LoadingCache) indexingStep.set(IndexingStepType.LoadingCache)
const hasCache = await searchEngine.loadCache() const hasCache = await searchEngine.loadCache()
if (hasCache) { if (hasCache) {
console.timeEnd('Omnisearch - Loading index from cache') console.timeEnd('Loading index from cache')
} }
} }
@@ -265,22 +263,20 @@ export default class OmnisearchPlugin extends Plugin {
if (isCacheEnabled()) { if (isCacheEnabled()) {
if (diff.toAdd.length) { if (diff.toAdd.length) {
console.log( console.debug(
'Omnisearch - Total number of files to add/update: ' + 'Total number of files to add/update: ' + diff.toAdd.length
diff.toAdd.length
) )
} }
if (diff.toRemove.length) { if (diff.toRemove.length) {
console.log( console.debug(
'Omnisearch - Total number of files to remove: ' + 'Total number of files to remove: ' + diff.toRemove.length
diff.toRemove.length
) )
} }
} }
if (diff.toAdd.length >= 1000 && isCacheEnabled()) { if (diff.toAdd.length >= 1000 && isCacheEnabled()) {
new Notice( new Notice(
`Omnisearch - ${diff.toAdd.length} files need to be indexed. Obsidian may experience stutters and freezes during the process`, `${diff.toAdd.length} files need to be indexed. Obsidian may experience stutters and freezes during the process`,
10_000 10_000
) )
} }
@@ -310,9 +306,9 @@ export default class OmnisearchPlugin extends Plugin {
} }
} }
console.timeEnd('Omnisearch - Indexing total time') console.timeEnd('Indexing total time')
if (diff.toAdd.length >= 1000 && isCacheEnabled()) { if (diff.toAdd.length >= 1000 && isCacheEnabled()) {
new Notice(`Omnisearch - Your files have been indexed.`) new Notice(`Your files have been indexed.`)
} }
indexingStep.set(IndexingStepType.Done) indexingStep.set(IndexingStepType.Done)
notifyOnIndexed() notifyOnIndexed()

View File

@@ -7,7 +7,7 @@ import {
isFileFromDataloom, isFileFromDataloom,
isFileImage, isFileImage,
isFilePDF, isFilePDF,
logDebug, logVerbose,
} from './tools/utils' } from './tools/utils'
export class NotesIndexer { export class NotesIndexer {
@@ -25,7 +25,7 @@ export class NotesIndexer {
public async refreshIndex(): Promise<void> { public async refreshIndex(): Promise<void> {
for (const file of this.notesToReindex) { for (const file of this.notesToReindex) {
logDebug('Updating file', file.path) logVerbose('Updating file', file.path)
await this.plugin.documentsRepository.addDocument(file.path) await this.plugin.documentsRepository.addDocument(file.path)
} }

View File

@@ -9,7 +9,7 @@ import {
isFileImage, isFileImage,
isFileOffice, isFileOffice,
isFilePDF, isFilePDF,
logDebug, logVerbose,
removeDiacritics, removeDiacritics,
stripMarkdownCharacters, stripMarkdownCharacters,
} from '../tools/utils' } from '../tools/utils'
@@ -65,7 +65,7 @@ export class DocumentsRepository {
if (this.documents.has(path)) { if (this.documents.has(path)) {
return this.documents.get(path)! return this.documents.get(path)!
} }
logDebug('Generating IndexedDocument from', path) logVerbose('Generating IndexedDocument from', path)
await this.addDocument(path) await this.addDocument(path)
return this.documents.get(path)! return this.documents.get(path)!
} }

View File

@@ -1,6 +1,6 @@
import { getLinkpath, Notice } from 'obsidian' import { getLinkpath, Notice } from 'obsidian'
import type OmnisearchPlugin from '../main' import type OmnisearchPlugin from '../main'
import { logDebug } from '../tools/utils' import { logVerbose } from '../tools/utils'
export class EmbedsRepository { export class EmbedsRepository {
/** Map<embedded file, notes where the embed is referenced> */ /** Map<embedded file, notes where the embed is referenced> */
@@ -55,7 +55,7 @@ export class EmbedsRepository {
} }
public async writeToCache(): Promise<void> { public async writeToCache(): Promise<void> {
logDebug('Writing embeds to cache') logVerbose('Writing embeds to cache')
const database = this.plugin.database const database = this.plugin.database
const data: { embedded: string; referencedBy: string[] }[] = [] const data: { embedded: string; referencedBy: string[] }[] = []
for (const [path, embedsList] of this.embeds) { for (const [path, embedsList] of this.embeds) {
@@ -69,10 +69,10 @@ export class EmbedsRepository {
try { try {
const database = this.plugin.database const database = this.plugin.database
if (!database.embeds) { if (!database.embeds) {
logDebug('No embeds in cache') logVerbose('No embeds in cache')
return return
} }
logDebug('Loading embeds from cache') logVerbose('Loading embeds from cache')
const embedsArr = await database.embeds.toArray() const embedsArr = await database.embeds.toArray()
for (const { embedded: path, referencedBy: embeds } of embedsArr) { for (const { embedded: path, referencedBy: embeds } of embedsArr) {
for (const embed of embeds) { for (const embed of embeds) {

View File

@@ -5,7 +5,7 @@ import MiniSearch, {
} from 'minisearch' } from 'minisearch'
import type { DocumentRef, IndexedDocument, ResultNote } from '../globals' import type { DocumentRef, IndexedDocument, ResultNote } from '../globals'
import { chunkArray, logDebug, removeDiacritics } from '../tools/utils' import { chunkArray, logVerbose, removeDiacritics } from '../tools/utils'
import { Notice } from 'obsidian' import { Notice } from 'obsidian'
import type { Query } from './query' import type { Query } from './query'
import { sortBy } from 'lodash-es' import { sortBy } from 'lodash-es'
@@ -55,13 +55,12 @@ export class SearchEngine {
} { } {
const docsMap = new Map(docs.map(d => [d.path, d.mtime])) const docsMap = new Map(docs.map(d => [d.path, d.mtime]))
// console.log(this.indexedDocuments)
const toAdd = docs.filter( const toAdd = docs.filter(
d => d =>
!this.indexedDocuments.has(d.path) || !this.indexedDocuments.has(d.path) ||
this.indexedDocuments.get(d.path) !== d.mtime this.indexedDocuments.get(d.path) !== d.mtime
) )
// console.log(toAdd)
const toRemove = [...this.indexedDocuments] const toRemove = [...this.indexedDocuments]
.filter( .filter(
([path, mtime]) => !docsMap.has(path) || docsMap.get(path) !== mtime ([path, mtime]) => !docsMap.has(path) || docsMap.get(path) !== mtime
@@ -75,7 +74,7 @@ export class SearchEngine {
* @param paths * @param paths
*/ */
public async addFromPaths(paths: string[]): Promise<void> { public async addFromPaths(paths: string[]): Promise<void> {
logDebug('Adding files', paths) logVerbose('Adding files', paths)
let documents = ( let documents = (
await Promise.all( await Promise.all(
paths.map( paths.map(
@@ -83,7 +82,7 @@ export class SearchEngine {
) )
) )
).filter(d => !!d?.path) ).filter(d => !!d?.path)
logDebug('Sorting documents to first index markdown') logVerbose('Sorting documents to first index markdown')
// Index markdown files first // Index markdown files first
documents = sortBy(documents, d => (d.path.endsWith('.md') ? 0 : 1)) documents = sortBy(documents, d => (d.path.endsWith('.md') ? 0 : 1))
@@ -95,7 +94,7 @@ export class SearchEngine {
// Split the documents in smaller chunks to add them to minisearch // Split the documents in smaller chunks to add them to minisearch
const chunkedDocs = chunkArray(documents, 500) const chunkedDocs = chunkArray(documents, 500)
for (const docs of chunkedDocs) { for (const docs of chunkedDocs) {
logDebug('Indexing into search engine', docs) logVerbose('Indexing into search engine', docs)
// Update the list of indexed docs // Update the list of indexed docs
docs.forEach(doc => this.indexedDocuments.set(doc.path, doc.mtime)) docs.forEach(doc => this.indexedDocuments.set(doc.path, doc.mtime))
@@ -134,8 +133,8 @@ export class SearchEngine {
return [] return []
} }
logDebug('=== New search ===') logVerbose('=== New search ===')
logDebug('Starting search for', query) logVerbose('Starting search for', query)
let fuzziness: number let fuzziness: number
switch (settings.fuzziness) { switch (settings.fuzziness) {
@@ -151,7 +150,7 @@ export class SearchEngine {
} }
const searchTokens = this.tokenizer.tokenizeForSearch(query.segmentsToStr()) const searchTokens = this.tokenizer.tokenizeForSearch(query.segmentsToStr())
logDebug(JSON.stringify(searchTokens, null, 1)) logVerbose(JSON.stringify(searchTokens, null, 1))
let results = this.minisearch.search(searchTokens, { let results = this.minisearch.search(searchTokens, {
prefix: term => term.length >= options.prefixLength, prefix: term => term.length >= options.prefixLength,
// length <= 3: no fuzziness // length <= 3: no fuzziness
@@ -174,7 +173,7 @@ export class SearchEngine {
tokenize: text => [text], tokenize: text => [text],
}) })
logDebug(`Found ${results.length} results`, results) logVerbose(`Found ${results.length} results`, results)
// Filter query results to only keep files that match query.query.ext (if any) // Filter query results to only keep files that match query.query.ext (if any)
if (query.query.ext?.length) { if (query.query.ext?.length) {
@@ -212,7 +211,7 @@ export class SearchEngine {
return results.filter(r => r.id === options.singleFilePath) return results.filter(r => r.id === options.singleFilePath)
} }
logDebug( logVerbose(
'searching with downranked folders', 'searching with downranked folders',
settings.downrankedFoldersFilters settings.downrankedFoldersFilters
) )
@@ -252,7 +251,7 @@ export class SearchEngine {
// we don't want the filter to match the folder sources, e.g. // we don't want the filter to match the folder sources, e.g.
// it needs to match a whole folder name // it needs to match a whole folder name
if (path === filter || path.startsWith(filter + '/')) { if (path === filter || path.startsWith(filter + '/')) {
logDebug('searching with downranked folders in path: ', path) logVerbose('searching with downranked folders in path: ', path)
downrankingFolder = true downrankingFolder = true
} }
} }
@@ -277,7 +276,7 @@ export class SearchEngine {
for (const { name, weight } of settings.weightCustomProperties) { for (const { name, weight } of settings.weightCustomProperties) {
const values = metadata?.frontmatter?.[name] const values = metadata?.frontmatter?.[name]
if (values && result.terms.some(t => values.includes(t))) { if (values && result.terms.some(t => values.includes(t))) {
logDebug(`Boosting field "${name}" x${weight} for ${path}`) logVerbose(`Boosting field "${name}" x${weight} for ${path}`)
result.score *= weight result.score *= weight
} }
} }
@@ -290,14 +289,14 @@ export class SearchEngine {
} }
} }
} }
logDebug('Sorting and limiting results') logVerbose('Sorting and limiting results')
// Sort results and keep the 50 best // Sort results and keep the 50 best
results = results.sort((a, b) => b.score - a.score).slice(0, 50) results = results.sort((a, b) => b.score - a.score).slice(0, 50)
logDebug('Filtered results:', results) logVerbose('Filtered results:', results)
if (results.length) logDebug('First result:', results[0]) if (results.length) logVerbose('First result:', results[0])
const documents = await Promise.all( const documents = await Promise.all(
results.map( results.map(
@@ -308,7 +307,7 @@ export class SearchEngine {
// If the search query contains quotes, filter out results that don't have the exact match // If the search query contains quotes, filter out results that don't have the exact match
const exactTerms = query.getExactTerms() const exactTerms = query.getExactTerms()
if (exactTerms.length) { if (exactTerms.length) {
logDebug('Filtering with quoted terms: ', exactTerms) logVerbose('Filtering with quoted terms: ', exactTerms)
results = results.filter(r => { results = results.filter(r => {
const document = documents.find(d => d.path === r.id) const document = documents.find(d => d.path === r.id)
const title = document?.path.toLowerCase() ?? '' const title = document?.path.toLowerCase() ?? ''
@@ -327,7 +326,7 @@ export class SearchEngine {
// If the search query contains exclude terms, filter out results that have them // If the search query contains exclude terms, filter out results that have them
const exclusions = query.query.exclude.text const exclusions = query.query.exclude.text
if (exclusions.length) { if (exclusions.length) {
logDebug('Filtering with exclusions') logVerbose('Filtering with exclusions')
results = results.filter(r => { results = results.filter(r => {
const content = ( const content = (
documents.find(d => d.path === r.id)?.content ?? '' documents.find(d => d.path === r.id)?.content ?? ''
@@ -336,7 +335,7 @@ export class SearchEngine {
}) })
} }
logDebug('Deduping') logVerbose('Deduping')
// FIXME: // FIXME:
// Dedupe results - clutch for https://github.com/scambier/obsidian-omnisearch/issues/129 // Dedupe results - clutch for https://github.com/scambier/obsidian-omnisearch/issues/129
results = results.filter( results = results.filter(
@@ -410,7 +409,7 @@ export class SearchEngine {
// Map the raw results to get usable suggestions // Map the raw results to get usable suggestions
const resultNotes = results.map(result => { const resultNotes = results.map(result => {
logDebug('Locating matches for', result.id) logVerbose('Locating matches for', result.id)
let note = documents.find(d => d.path === result.id) let note = documents.find(d => d.path === result.id)
if (!note) { if (!note) {
// throw new Error(`Omnisearch - Note "${result.id}" not indexed`) // throw new Error(`Omnisearch - Note "${result.id}" not indexed`)
@@ -435,15 +434,15 @@ export class SearchEngine {
// Tags, starting with # // Tags, starting with #
...query.getTags(), ...query.getTags(),
] ]
logDebug('Matching tokens:', foundWords) logVerbose('Matching tokens:', foundWords)
logDebug('Getting matches locations...') logVerbose('Getting matches locations...')
const matches = this.plugin.textProcessor.getMatches( const matches = this.plugin.textProcessor.getMatches(
note.content, note.content,
foundWords, foundWords,
query query
) )
logDebug(`Matches for note "${note.path}"`, matches) logVerbose(`Matches for note "${note.path}"`, matches)
const resultNote: ResultNote = { const resultNote: ResultNote = {
score: result.score, score: result.score,
foundWords, foundWords,
@@ -454,7 +453,7 @@ export class SearchEngine {
return resultNote return resultNote
}) })
logDebug('Suggestions:', resultNotes) logVerbose('Suggestions:', resultNotes)
return resultNotes return resultNotes
} }

View File

@@ -1,6 +1,6 @@
import type { QueryCombination } from 'minisearch' import type { QueryCombination } from 'minisearch'
import { BRACKETS_AND_SPACE, chsRegex, SPACE_OR_PUNCTUATION } from '../globals' import { BRACKETS_AND_SPACE, chsRegex, SPACE_OR_PUNCTUATION } from '../globals'
import { logDebug, splitCamelCase, splitHyphens } from '../tools/utils' import { logVerbose, splitCamelCase, splitHyphens } from '../tools/utils'
import type OmnisearchPlugin from '../main' import type OmnisearchPlugin from '../main'
const markdownLinkExtractor = require('markdown-link-extractor') const markdownLinkExtractor = require('markdown-link-extractor')
@@ -22,7 +22,7 @@ export class Tokenizer {
try { try {
urls = markdownLinkExtractor(text) urls = markdownLinkExtractor(text)
} catch (e) { } catch (e) {
logDebug('Error extracting urls', e) logVerbose('Error extracting urls', e)
} }
} }

View File

@@ -11,7 +11,7 @@ import {
import { writable } from 'svelte/store' import { writable } from 'svelte/store'
import { K_DISABLE_OMNISEARCH } from './globals' import { K_DISABLE_OMNISEARCH } from './globals'
import type OmnisearchPlugin from './main' import type OmnisearchPlugin from './main'
import { enablePrintDebug } from './tools/utils' import { enableVerboseLogging } from './tools/utils'
import { debounce } from 'lodash-es' import { debounce } from 'lodash-es'
interface WeightingSettings { interface WeightingSettings {
@@ -687,7 +687,7 @@ export class SettingsTab extends PluginSettingTab {
.addToggle(toggle => .addToggle(toggle =>
toggle.setValue(settings.verboseLogging).onChange(async v => { toggle.setValue(settings.verboseLogging).onChange(async v => {
settings.verboseLogging = v settings.verboseLogging = v
enablePrintDebug(v) enableVerboseLogging(v)
await saveSettings(this.plugin) await saveSettings(this.plugin)
}) })
) )
@@ -869,7 +869,7 @@ export async function loadSettings(
await plugin.loadData() await plugin.loadData()
) )
showExcerpt.set(settings.showExcerpt) showExcerpt.set(settings.showExcerpt)
enablePrintDebug(settings.verboseLogging) enableVerboseLogging(settings.verboseLogging)
return settings return settings
} }

View File

@@ -40,7 +40,7 @@ export function getServer(plugin: OmnisearchPlugin) {
return { return {
listen(port: string) { listen(port: string) {
console.log(`Omnisearch - Starting HTTP server on port ${port}`) console.debug(`Omnisearch - Starting HTTP server on port ${port}`)
server.listen( server.listen(
{ {
port: parseInt(port), port: parseInt(port),

View File

@@ -5,7 +5,7 @@ import {
isFilePDF, isFilePDF,
isFileCanvas, isFileCanvas,
isFileExcalidraw, isFileExcalidraw,
warnDebug, warnVerbose,
} from './utils' } from './utils'
import { escapeHTML } from './text-processing' import { escapeHTML } from './text-processing'
@@ -38,7 +38,7 @@ export async function loadIconData(plugin: OmnisearchPlugin): Promise<any> {
} }
return iconData return iconData
} catch (e) { } catch (e) {
warnDebug('Failed to read data.json:', e) warnVerbose('Failed to read data.json:', e)
return {} return {}
} }
} }
@@ -74,7 +74,7 @@ export async function initializeIconPacks(
} }
} }
} catch (e) { } catch (e) {
warnDebug('Failed to list icon packs:', e) warnVerbose('Failed to list icon packs:', e)
} }
} }
@@ -142,7 +142,7 @@ export async function loadIconSVG(
const iconPackName = prefixToIconPack[prefix] const iconPackName = prefixToIconPack[prefix]
if (!iconPackName) { if (!iconPackName) {
warnDebug(`No icon pack found for prefix: ${prefix}`) warnVerbose(`No icon pack found for prefix: ${prefix}`)
return null return null
} }
@@ -153,12 +153,12 @@ export async function loadIconSVG(
if (iconEl) { if (iconEl) {
return iconEl.outerHTML return iconEl.outerHTML
} else { } else {
warnDebug(`Lucide icon not found: ${dashedName}`) warnVerbose(`Lucide icon not found: ${dashedName}`)
return null return null
} }
} else { } else {
if (!iconsPath) { if (!iconsPath) {
warnDebug('Icons path is not set. Cannot load icon SVG.') warnVerbose('Icons path is not set. Cannot load icon SVG.')
return null return null
} }
const iconPath = `${plugin.app.vault.configDir}/${iconsPath}/${iconPackName}/${name}.svg` const iconPath = `${plugin.app.vault.configDir}/${iconsPath}/${iconPackName}/${name}.svg`
@@ -166,7 +166,7 @@ export async function loadIconSVG(
const svgContent = await plugin.app.vault.adapter.read(iconPath) const svgContent = await plugin.app.vault.adapter.read(iconPath)
return svgContent return svgContent
} catch (e) { } catch (e) {
warnDebug(`Failed to load icon SVG for ${iconName} at ${iconPath}:`, e) warnVerbose(`Failed to load icon SVG for ${iconName} at ${iconPath}:`, e)
return null return null
} }
} }

View File

@@ -1,5 +1,5 @@
import { excerptAfter, excerptBefore, type SearchMatch } from '../globals' import { excerptAfter, excerptBefore, type SearchMatch } from '../globals'
import { removeDiacritics, warnDebug } from './utils' import { removeDiacritics, warnVerbose } from './utils'
import type { Query } from '../search/query' import type { Query } from '../search/query'
import { Notice } from 'obsidian' import { Notice } from 'obsidian'
import { escapeRegExp } from 'lodash-es' import { escapeRegExp } from 'lodash-es'
@@ -115,7 +115,7 @@ export class TextProcessor {
while ((match = reg.exec(text)) !== null) { while ((match = reg.exec(text)) !== null) {
// Avoid infinite loops, stop looking after 100 matches or if we're taking too much time // Avoid infinite loops, stop looking after 100 matches or if we're taking too much time
if (++count >= 100 || new Date().getTime() - startTime > 50) { if (++count >= 100 || new Date().getTime() - startTime > 50) {
warnDebug('Stopped getMatches at', count, 'results') warnVerbose('Stopped getMatches at', count, 'results')
break break
} }
const matchStartIndex = match.index const matchStartIndex = match.index

View File

@@ -230,23 +230,21 @@ export function splitHyphens(text: string): string[] {
return text.split('-').filter(t => t) return text.split('-').filter(t => t)
} }
export function logDebug(...args: any[]): void { export function logVerbose(...args: any[]): void {
printDebug(console.log, ...args) printVerbose(console.debug, ...args)
} }
export function warnDebug(...args: any[]): void { export function warnVerbose(...args: any[]): void {
printDebug(console.warn, ...args) printVerbose(console.warn, ...args)
} }
let printDebugEnabled = false let verboseLoggingEnabled = false
export function enablePrintDebug(enable: boolean): void { export function enableVerboseLogging(enable: boolean): void {
printDebugEnabled = enable verboseLoggingEnabled = enable
} }
function printDebug(fn: (...args: any[]) => any, ...args: any[]): void { function printVerbose(fn: (...args: any[]) => any, ...args: any[]): void {
if (printDebugEnabled) { if (verboseLoggingEnabled) {
const t = new Date() fn(...args)
const ts = `${t.getMinutes()}:${t.getSeconds()}:${t.getMilliseconds()}`
fn(...['Omnisearch -', ts + ' -', ...args])
} }
} }