Отправка логов
POST
/sendmess
Отправка лог-сообщения на сервер
Параметры запроса
Параметр
Тип
Обязательный
Описание
key
string
Да
Consumer key, полученный при регистрации
mess
any
Да
Сообщение для логирования (строка, число, объект, массив)
module
string
Нет
Название модуля/компонента, отправившего лог
mode
string
Нет
Режим отображения: regular (по умолчанию) или light
Примеры запросов на разных языках
cURL
Python
JavaScript
Node.js
PHP
Go
Java
curl -X POST https://logger.dp-projects.ru/sendmess \
-H "Content-Type: application/json" \
-d '{
"key": "ваш-consumer-key",
"module": "payment-service",
"mess": {
"event": "payment_processed",
"amount": 1000,
"currency": "RUB",
"status": "success"
},
"mode": "regular"
}'
import requests
import json
url = "https://logger.dp-projects.ru/sendmess"
payload = {
"key": "ваш-consumer-key",
"module": "payment-service",
"mess": {
"event": "payment_processed",
"amount": 1000,
"currency": "RUB",
"status": "success"
},
"mode": "regular"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
print("Лог отправлен успешно")
else:
print(f"Ошибка: {response.text}")
fetch('https://logger.dp-projects.ru/sendmess', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
key: 'ваш-consumer-key',
module: 'payment-service',
mess: {
event: 'payment_processed',
amount: 1000,
currency: 'RUB',
status: 'success'
},
mode: 'regular'
})
})
.then(response => response.json())
.then(data => console.log('Лог отправлен:', data))
.catch(error => console.error('Ошибка:', error));
const axios = require('axios');
const logData = {
key: 'ваш-consumer-key',
module: 'payment-service',
mess: {
event: 'payment_processed',
amount: 1000,
currency: 'RUB',
status: 'success'
},
mode: 'regular'
};
axios.post('https://logger.dp-projects.ru/sendmess', logData)
.then(response => {
console.log('Лог отправлен:', response.data);
})
.catch(error => {
console.error('Ошибка:', error.response?.data || error.message);
});
<?php
$url = 'https://logger.dp-projects.ru/sendmess';
$data = [
'key' => 'ваш-consumer-key',
'module' => 'payment-service',
'mess' => [
'event' => 'payment_processed',
'amount' => 1000,
'currency' => 'RUB',
'status' => 'success'
],
'mode' => 'regular'
];
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
echo "Ошибка отправки лога";
} else {
echo "Лог отправлен: " . $result;
}
?>
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
url := "https://logger.dp-projects.ru/sendmess"
payload := map[string]interface{}{
"key": "ваш-consumer-key",
"module": "payment-service",
"mess": map[string]interface{}{
"event": "payment_processed",
"amount": 1000,
"currency": "RUB",
"status": "success",
},
"mode": "regular",
}
jsonData, _ := json.Marshal(payload)
resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Ошибка:", err)
return
}
defer resp.Body.Close()
fmt.Println("Статус:", resp.Status)
}
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
public class LoggerClient {
public static void main(String[] args) {
try {
HttpClient client = HttpClient.newHttpClient();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> payload = Map.of(
"key", "ваш-consumer-key",
"module", "payment-service",
"mess", Map.of(
"event", "payment_processed",
"amount", 1000,
"currency", "RUB",
"status", "success"
),
"mode", "regular"
);
String jsonBody = mapper.writeValueAsString(payload);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://logger.dp-projects.ru/sendmess"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonBody))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println("Статус: " + response.statusCode());
System.out.println("Ответ: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Формат ответа
{
"status" : "ok" ,
"message" : "Message sent successfully" ,
"data" : {
"module" : "payment-service" ,
"msg" : "{\n \"event\": \"payment_processed\",\n \"amount\": 1000,\n \"currency\": \"RUB\",\n \"status\": \"success\"\n}" ,
"mode" : "regular" ,
"timestamp" : "2024-01-15T10:30:00.000Z"
}
}
Примеры использования
Простой текст
{
"key": "ваш-consumer-key",
"module": "app",
"mess": "Пользователь вошел в систему",
"mode": "regular"
}
Числовые значения
{
"key": "ваш-consumer-key",
"module": "metrics",
"mess": {
"cpu_usage": 45.2,
"memory_used": 1024,
"connections": 150
},
"mode": "regular"
}
Массив данных
{
"key": "ваш-consumer-key",
"module": "batch-processor",
"mess": [
{"id": 1, "status": "processed"},
{"id": 2, "status": "failed"},
{"id": 3, "status": "pending"}
],
"mode": "light"
}