# Configure promtail to extract timestamp from log line

**URL:** <https://community.grafana.com/t/configure-promtail-to-extract-timestamp-from-log-line/89928>\
**Category:** Prometheus\
**Tags:** promtail\
**Created:** [June 20, 2023, 12:18pm UTC](https://community.grafana.com/t/configure-promtail-to-extract-timestamp-from-log-line/89928 "2023-06-20T12:18:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![telbana2](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@telbana2](https://community.grafana.com/u/telbana2)\
**Post date:** [June 20, 2023, 12:18pm UTC](https://community.grafana.com/t/configure-promtail-to-extract-timestamp-from-log-line/89928/1 "2023-06-20T12:18:20Z")

</div>

I’m using grafana enterprise version 10 on windows 11

I want to extract the timestamp of the log line , from the line itself ,  
here is a sample log line :  
**2023-06-13 13:48:26.7314** 293092600282 GetPassportFromStorage() GetSensorStatus.success = False

## I used the following config :

server:  
http\_listen\_port: 9080  
grpc\_listen\_port: 0

positions:  
filename: D:/tmp/positions.yaml

clients:

- url: [http://localhost:3100/loki/api/v1/push](http://localhost:3100/loki/api/v1/push)

scrape\_configs:

- job\_name: windows-logs  
pipeline\_stages:
  - timestamp:  
source: timestamp  
format: ‘2006-01-02 15:04:05.0000’ # Adjust the format based on your log timestamp format  
static\_configs:
  - targets:
    - localhost  
labels:  
job: OmarLaptop  
agent: promtail  
**path** : D:/MyLogs/\*.log

* * *

but it seems that log shown in Grafana Loki , not preserve the right timestamp

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/b/f/bf60034a8d8bc62eacca0f3ba3fce872d5fe23ee.png)

How to extract the timestamp from the Log Line itself ,

I read the pipeline docs for promtail and found the following for timestamp stage ,

> **[timestamp | Grafana Loki documentation](https://grafana.com/docs/loki/latest/send-data/promtail/stages/timestamp/)**
>
> The 'timestamp' Promtail pipeline stage.

but I’m confused how to use it

Thank You.

---

<div class="post-metadata">

**Author:** ![palw3ey](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/palw3ey/32/34119_2.png) [@palw3ey](https://community.grafana.com/u/palw3ey)\
**Post date:** [July 5, 2023, 1:13pm UTC](https://community.grafana.com/t/configure-promtail-to-extract-timestamp-from-log-line/89928/2 "2023-07-05T13:13:20Z")

</div>

Bonjour,  
To extract the timestamp from a log line. First use a regex expression (golang flavor) that will extract the characters that match the timestamp. Then, we can use an appropriate format in the timestamp stage, adding the time zone if necessary.  
For your example, replace the timestamp section with this :

```auto
  - regex:
      expression: '^(?P<timestamp>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}.\d{3})'
  - timestamp:
      source: timestamp
      format: '2006-01-02 15:04:05.000'
      location: 'Etc/GMT-0'

```
