Introduction
This document is mainly used to describe some features and usage of the logger utility.
formatLogger
use formatLogger
function to format logger.
Functions Overview and Limitations:
- Use cases: Single log parsing, custom configuration needed
- Limitations: Not for bulk processing, requires config params each time
- Resource usage: Low
Show code
vue
<script setup lang="ts">
import { formatLogger } from 'view-shadcn-ui'
const formatLoggerValue = formatLogger("2024-12-04 23:14:27,765 INFO [main] io.edurt.datacap.service.initializer.InitializerConfigure [InitializerConfigure.java:100] Datacap registration enable: true")
</script>
formatMultipleLines
use formatMultipleLines
function to format multiple lines.
Functions Overview and Limitations:
- Use cases: Batch processing of known log volume
- Limitations: Requires loading all logs at once, high memory usage for large volumes
- Resource usage: High, but fast processing
Show code
vue
<script setup lang="ts">
import { formatMultipleLines } from 'view-shadcn-ui'
const formatMultipleLinesValue = formatMultipleLines([
"2024-12-04 23:14:27,765 INFO [main] io.edurt.datacap.service.initializer.InitializerConfigure [InitializerConfigure.java:100] Datacap registration enable: true",
"2024-12-04 23:14:27,765 INFO [main] io.edurt.datacap.service.initializer.InitializerConfigure [InitializerConfigure.java:100] Datacap registration enable: true",
"2024-12-04 23:14:27,765 INFO [main] io.edurt.datacap.service.initializer.InitializerConfigure [InitializerConfigure.java:100] Datacap registration enable: true"
])
formatFromExample
use formatFromExample
function to format from example.
Functions Overview and Limitations:
- Use cases: Unknown formats with sample logs, format learning required
- Limitations: Depends on sample quality, potential mismatches
- Resource usage: Medium
Show code
vue
<script setup lang="ts">
import { formatFromExample } from 'view-shadcn-ui'
const formatFromExampleValue = formatFromExample(
'12-01 23:59 ERROR MyApp: Hello',
'01-01 12:00 INFO MyApp: Example',
{
timestamp: '01-01 12:00',
level: 'INFO',
logger: 'MyApp'
}
)
</script>
formatLoggerFromStream
use formatLoggerFromStream
function to format from stream.
Functions Overview and Limitations:
- Use cases: Real-time processing of large logs, memory-constrained environments
- Limitations: Generator syntax required, no parallel processing
- Resource usage: Low, memory-efficient
Show code
vue
<script setup lang="ts">
import { formatLoggerFromStream } from 'view-shadcn-ui'
const rows = [
'12-01 23:59 ERROR MyApp: Hello',
'12-01 23:59 INFO MyApp: World'
]
const formatLoggerFromStreamValue = [...formatLoggerFromStream(rows)]
</script>
Selection Guide
- Single log →
formatLogger
- Special format learning →
formatFromExample
- Large logs/Memory sensitive →
formatLoggerFromStream
- Medium log volume/Quick processing →
formatMultipleLines