Unless I am missing something, it doesn’t seem to be necessary to break your timestamp string. Here is what I am using for testing (copied your two lines of logs and changed time to 0000, +0700, and -0700):
{"time":"2023-09-18T06:56:15.068572+00:00","seve":"INFO","mesg":"Logged in user: root (::1)","data":null}
{"time":"2023-09-18T07:02:08.141130+00:00","seve":"INFO","mesg":"Api request handled. Runtime(0.060374975204468), Status(200)","data":null}
{"time":"2023-09-18T06:56:15.068572+07:00","seve":"INFO","mesg":"Logged in user: root (::1)","data":null}
{"time":"2023-09-18T07:02:08.141130+07:00","seve":"INFO","mesg":"Api request handled. Runtime(0.060374975204468), Status(200)","data":null}
{"time":"2023-09-18T06:56:15.068572-07:00","seve":"INFO","mesg":"Logged in user: root (::1)","data":null}
{"time":"2023-09-18T07:02:08.141130-07:00","seve":"INFO","mesg":"Api request handled. Runtime(0.060374975204468), Status(200)","data":null}
Promtail configuration:
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://loki:3100/loki/api/v1/push
scrape_configs:
- job_name: sys3
static_configs:
- targets:
- localhost
labels:
job: backend_logs
__path__: /tmp/test.log
pipeline_stages:
- json:
expressions:
time: time
#- template:
# source: time
# template: '{{ regexReplaceAll "(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6}-\d{2}):(\d{2})" .Value "${1}${2}" }}'
- timestamp:
source: time
format: '2006-01-02T15:04:05.000000-07:00'
Dry run results:
level=warn ts=2023-09-18T16:18:39.530963821Z caller=promtail.go:263 msg="enable watchConfig"
2023-09-18T06:56:15.068572+0000{filename="/tmp/test.log", job="backend_logs"} {"time":"2023-09-18T06:56:15.068572+00:00","seve":"INFO","mesg":"Logged in user: root (::1)","data":null}
2023-09-18T07:02:08.14113+0000 {filename="/tmp/test.log", job="backend_logs"} {"time":"2023-09-18T07:02:08.141130+00:00","seve":"INFO","mesg":"Api request handled. Runtime(0.060374975204468), Status(200)","data":null}
2023-09-18T06:56:15.068572+0700{filename="/tmp/test.log", job="backend_logs"} {"time":"2023-09-18T06:56:15.068572+07:00","seve":"INFO","mesg":"Logged in user: root (::1)","data":null}
2023-09-18T07:02:08.14113+0700 {filename="/tmp/test.log", job="backend_logs"} {"time":"2023-09-18T07:02:08.141130+07:00","seve":"INFO","mesg":"Api request handled. Runtime(0.060374975204468), Status(200)","data":null}
2023-09-18T06:56:15.068572-0700{filename="/tmp/test.log", job="backend_logs"} {"time":"2023-09-18T06:56:15.068572-07:00","seve":"INFO","mesg":"Logged in user: root (::1)","data":null}
2023-09-18T07:02:08.14113-0700 {filename="/tmp/test.log", job="backend_logs"} {"time":"2023-09-18T07:02:08.141130-07:00","seve":"INFO","mesg":"Api request handled. Runtime(0.060374975204468), Status(200)","data":null}
level=info ts=2023-09-18T16:18:44.531199126Z caller=filetargetmanager.go:361 msg="Adding target" key="/tmp/test.log:{job=\"backend_logs\"}"