> For the complete documentation index, see [llms.txt](https://docs.minilog.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.minilog.dev/sending-logs.md).

# Sending logs

Start sending logs to Minilog in 5 minutes

### 1️⃣ Create a project

Go to your [projects page ](https://minilog.dev/app/projects)and click the button `+ Create Project`

Give it a unique short name (lowercase letters, digits, and the characters '.', '\_', and '-')

### 2️⃣ Create a project token

After creating your first project, go to `Settings > Tokens`

Give the token a unique short name then click on `Create`

You can now copy the token by clicking the copy button next to the token.

{% hint style="info" %}
For security reasons, only the last few characters of the token is shown
{% endhint %}

### 🎉 Send your first log

To send logs to Minilog, make an authenticated HTTP POST request to the [Log API](/api-reference/log.md).

Check out the [Log API](/api-reference/log.md) for more details.

{% hint style="warning" %}
The HTTP request can fail (no internet, quota exceeded), make sure to handle exceptions according to your programming language.
{% endhint %}

{% hint style="warning" %}
HTTP requests can take some time to complete (a few hundred milliseconds), make sure to not block your main process while sending logs.
{% endhint %}

{% tabs %}
{% tab title="Javascript" %}

```javascript
await fetch("https://api.minilog.dev/v1/logs/<project-name>", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer <project-token>",
  },
  body: JSON.stringify({
    application: "myapp-1",
    severity: "DEBUG",
    data: "This is a debug message",
    metadata: { hostname: "vm-1" },
  }),
});
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.minilog.dev/v1/logs/<project-name>"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <project-token>",
}
data = {
    "application": "myapp-1",
    "severity": "DEBUG",
    "data": "This is a debug message",
    "metadata": {"hostname": "vm-1"},
}

response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.status_code)

```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
	static async Task Main()
	{
		var url = "https://api.minilog.dev/v1/logs/<project-name>";
		var token = "<project-token>";
		var json = "{\"application\": \"myapp-1\",\"severity\": \"DEBUG\",\"data\": \"This is a debug message\",\"metadata\": {\"hostname\": \"vm-1\"}}";

		using (var client = new HttpClient())
		{
			client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);

			var content = new StringContent(json, Encoding.UTF8, "application/json");
			var response = await client.PostAsync(url, content);

			Console.WriteLine(response.StatusCode);
		}
	}
}

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$url = 'https://api.minilog.dev/v1/logs/<project-name>';
$token = '<project-token>';
$data = array(
	'application' => 'myapp-1',
	'severity' => 'DEBUG',
	'data' => 'This is a debug message',
	'metadata' => array('hostname' => 'vm-1')
);

$options = array(
	'http' => array(
		'header'  => "Content-Type: application/json\r\n" .
					"Authorization: Bearer " . $token . "\r\n",
		'method'  => 'POST',
		'content' => json_encode($data),
	),
);

$context  = stream_context_create($options);
$response = file_get_contents($url, false, $context);

if ($response === false) {
	echo "Error fetching data";
} else {
	echo $response;
}

?>
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl -X POST https://api.minilog.dev/v1/logs/<project-name> \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <project-token>" \
-d '{
	"application": "myapp-1",
	"severity": "DEBUG",
	"data": "This is a debug message",
	"metadata": { "hostname": "vm-1" }
}'
```

{% endtab %}

{% tab title="PowerShell" %}

```powershell
$uri = 'https://api.minilog.dev/v1/logs/<project-name>'
$headers = @{
	'Content-Type' = 'application/json'
	'Authorization' = 'Bearer <project-token>'
}
$body = @{
	application = 'myapp-1'
	severity = 'DEBUG'
	data = 'This is a debug message'
	metadata = @{
		hostname = 'vm-1'
	}
}

Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body ($body | ConvertTo-Json)
```

{% endtab %}

{% tab title="Docker" %}

```bash
# Docker can send logs to Minilog via the Splunk logging driver.
# It comes pre-installed with docker.

docker run -p 3000:80 \
--log-driver=splunk \
--log-opt splunk-token=project-token \
--log-opt splunk-url=https://api.minilog.dev \
--log-opt tag="myapp-1" \
nginx:alpine
```

{% endtab %}

{% tab title="Docker Compose" %}

```yaml
services:
  mywebserver:
    image: nginx:alpine
    ports:
      - "3000:80"
    logging:
      driver: splunk
      options:
        splunk-url: "https://api.minilog.dev"
        splunk-token: "<project-token>"
        tag: "myapp-1"
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
As of today, we do not provide language specific libraries.
{% endhint %}
