Docs

Parameters

message string required
level string 0, 1, 2, 3, 4, 5
level_name string Severity level: INFO, DEBUG, NOTICE, WARNING, ERROR, CRITICAL
channel string Name of your app e.g. my_app
extra object Example
{
    "extra": {
        "user_id": 92836746
    }
}
context array|object Example
{
    "context": [
        {
            "file": "src/App/Controllers/Home.php",
            "line": 516,
            "function": "getUserAvatar"
            "args": [
                "(object) App\\Models\\User"
            ]
        }
    ]
}

Integrations

Curl

    curl -H 'Content-Type: application/json' -d '{"message":"Hello World"}' https://logfile.co/api/push/TOKEN

Go

package main

import (
    "bytes"
    "encoding/json"
    "net/http"
)

type log struct {
    Message string `json: message`
}

json, err := json.Marshal(log{Message: "Hello World"})
req, err := http.NewRequest("POST", "https://logfile.co/api/push/TOKEN", bytes.NewBuffer(json))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)

Python

#!/usr/bin/env python

# http://docs.python-requests.org/en/latest/user/install/#install
import requests

payload = {"message": "Hello World"}
r = requests.post("https://logfile.co/api/push/TOKEN", json=payload)

PHP

<?php

$session = curl_init();
curl_setopt_array($session, [
    CURLOPT_URL => 'https://logfile.co/api/push/TOKEN',
    CURLOPT_HEADER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json'
    ],
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => '{"message":"Hello World"}',
]);
$result = curl_exec($session);
curl_close($session);
var_dump($result);

Monolog

<?php

use Monolog\Logger;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\JsonFormatter;
use Monolog\Handler\Curl;

class LogfileHandler extends AbstractProcessingHandler
{
    const HOST = 'logfile.co';

    const ENDPOINT = 'api/push';

    protected $token;

    public function __construct(string $token, int $level = Logger::DEBUG, bool $bubble = true)
    {
        if (!extension_loaded('curl')) {
            throw new \LogicException('The curl extension is needed to use the LogfileHandler');
        }

        $this->token = $token;

        parent::__construct($level, $bubble);
    }

    protected function getDefaultFormatter(): FormatterInterface
    {
        return new JsonFormatter();
    }

    protected function write(array $record)
    {
        $this->send($record['formatted'], self::ENDPOINT);
    }

    protected function send(string $data, string $endpoint)
    {
        $url = sprintf('https://%s/%s/%s', self::HOST, $endpoint, $this->token);

        $headers = [
            'content-type: application/json',
        ];

        $session = curl_init();

        curl_setopt_array($session, [
            CURLOPT_URL => $url,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $data,
            CURLOPT_HTTPHEADER => $headers,
            CURLOPT_RETURNTRANSFER => true,
        ]);

        Curl\Util::execute($session);
    }
}

$logger = new Monolog\Logger('app');
$logger->pushHandler(new LogfileHandler('TOKEN'));

Rsyslog

New rsyslog conf file /etc/rsyslog.d/22-logfile.conf

template(name="logfile" type="list") {
    constant(value="TOKEN")
    constant(value=",")
    property(name="timereported" dateFormat="rfc3339")
    constant(value=",")
    property(name="hostname")
    constant(value=",")
    property(name="syslogseverity-text" caseConversion="upper")
    constant(value=",")
    property(name="syslogfacility-text")
    constant(value=",")
    property(name="syslogtag")
    constant(value=",")
    property(name="app-name")
    constant(value=",")
    property(name="msg")
    constant(value="\n")
}

*.* action(
    type="omfwd"
    template="logfile"
    target="logfile.co"
    port="514"
    protocol="tcp"
    action.resumeRetryCount="100"
    queue.type="linkedList"
    queue.size="10000"
)