Skip to content

Commit b1fde7e

Browse files
committed
feat: add logger
1 parent 0daf0c9 commit b1fde7e

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

src/markdown-it/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createHash } from 'node:crypto'
33
import { template as _template } from 'radashi'
44
import { fromError } from 'zod-validation-error'
55
import * as vscode from 'vscode'
6+
import { logger } from '@/shared'
67

78
let counter = 0x39
89

@@ -30,7 +31,7 @@ export const parseFrontmatter = (data: Record<string, any> = {}, identifier: str
3031
const parsedData = frontmatterSchema.safeParse(data)
3132
if (!parsedData.success) {
3233
const validationError = fromError(parsedData.error)
33-
vscode.window.showErrorMessage(validationError.message)
34+
logger.error(validationError.message)
3435
}
3536
if (parsedData.data && !parsedData.data.id) {
3637
parsedData.data.id = generateShortId(identifier)

src/shared.ts renamed to src/shared/config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import * as vscode from 'vscode'
22

3-
export const MARKMAP_OPEN_RE = /^{%\s*markmap\s*(.*?)\s*%}$/
4-
export const MARKMAP_CLOSE = '{% endmarkmap %}'
5-
6-
73
const getGlobalOptions = () => vscode.workspace
84
.getConfiguration('markmap-universe')
95
.get('globalOptions', {})

src/shared/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./config"
2+
export * from "./rules"
3+
export * as logger from "./logger"

src/shared/logger.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as vscode from 'vscode'
2+
3+
type LogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR" | "NONE"
4+
5+
const outputChannel = vscode.window.createOutputChannel('Markmap Universe', { log: true })
6+
7+
export const clearLogger = () => {
8+
outputChannel.clear()
9+
}
10+
11+
export const appendLine = (level: LogLevel, message: string) => {
12+
outputChannel.append(`[${level}] ${message}\n`)
13+
}
14+
15+
export const info = (message: string) => {
16+
appendLine("INFO", message)
17+
}
18+
19+
export const error = (message: string) => {
20+
appendLine("ERROR", message)
21+
}

src/shared/rules.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const MARKMAP_OPEN_RE = /^{%\s*markmap\s*(.*?)\s*%}$/
2+
export const MARKMAP_CLOSE = '{% endmarkmap %}'

0 commit comments

Comments
 (0)