is there an easier way to do basename/dirname when using file source #22657
-
I have the following minimal config file (experimented on the VRL playground) I want to extract the "only file name" bit (first part of I have the following so far, but was wondering if there is there a more "proper" way of doing this? (In the longer run I want to use the extracted name as a log label when forwarding to Loki. data_dir: /tmp/experiment/
sources:
logs:
type: file
include:
- /var/log/*.log
transforms:
modify:
type: remap
inputs:
- logs
source: |
parts = split!(.file, "/")
basename = split!(parts[-1], ".")
.service_name = basename[0]
sinks:
my_sink_id:
type: console
inputs:
- modify
encoding:
codec: json
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @shantanugadgil, I think what you have here is the correct way to achieve this: VRL playground example You can also open a new VRL enhancement request: https://github.com/vectordotdev/vrl/issues to request a new VRL function to produce the basename. |
Beta Was this translation helpful? Give feedback.
-
Done, opened a feature request: vectordotdev/vrl#1348 Thanks! |
Beta Was this translation helpful? Give feedback.
Hi @shantanugadgil, I think what you have here is the correct way to achieve this: VRL playground example
You can also open a new VRL enhancement request: https://github.com/vectordotdev/vrl/issues to request a new VRL function to produce the basename.