PHPackages                             phptars/tars-log - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. phptars/tars-log

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

phptars/tars-log
================

tars的远程日志

0.1.6(5y ago)19.9k45PHPPHP &gt;=5.5

Since Sep 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/TarsPHP/tars-log)[ Packagist](https://packagist.org/packages/phptars/tars-log)[ RSS](/packages/phptars-tars-log/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (1)Versions (4)Used By (5)

tars-log
========

[](#tars-log)

---

`Tarlog` is a `phptars` remote log module

Install
-------

[](#install)

Install using `composer`

`composer install phptars/tars-log`

Usage
-----

[](#usage)

### Configuration

[](#configuration)

Instantiate communicator config, which can be configured one by one or through the configuration files distributed by the platform

-Configure a parameter separately

```
$config  = new \Tars\client\CommunicatorConfig();
$config->setLocator("tars.tarsregistry.QueryObj@tcp -h 172.16.0.161 -p 17890");
$config->setModuleName("tedtest");
$config->setCharsetName("UTF-8");
$config->setLogLevel("INFO");	//log level：`INFO`、`DEBUG`、`WARN`、`ERROR` default INFO
$config->setSocketMode(2);		//Remote log connection mode：1：socket，2：swoole tcp client 3: swoole coroutine tcp client
```

- Profile initialization parameters

```
$config = new \Tars\client\CommunicatorConfig();
$sFilePath = 'project address/src/conf'; //Profile distribution path
$config->init($sFilePath);
```

### Output log

[](#output-log)

There are two ways to output logs: one is to directly call the 'logger' mode of 'logservice' to output remote logs, and the other is to output remote logs in combination with 'monitoring' (recommended)

-Calling 'logger' method of 'logservant'

```
$logServant  = new \Tars\log\LogServant($config);
$appName = "App";	//app name
$serverName = "server";	//service name
$file = "test.log";	//file name
$format = "%Y%m%d";	//log time
$buffer = ["hahahahaha"];	//Log content, array, each element is a log
$result = $logServant->logger($appName,$serverName,$file,$format,$buffer);
```

- Combined with 'monolog' method (recommended)

```
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use Tars\client\CommunicatorConfig;
use Tars\log\LogServant;

class TarsHandler extends AbstractProcessingHandler
{
    protected $app = 'Undefined';
    protected $server = 'Undefined';
    protected $dateFormat = '%Y%m%d';

    private $logServant;
    private $logConf;

    public function __construct(CommunicatorConfig $config, $servantName = "tars.tarslog.LogObj", $level = Logger::WARNING, $bubble = true)
    {
        parent::__construct($level, $bubble);
        $this->logConf = $config;
        $this->logServant = new LogServant($config, $servantName);

        $moduleName = $this->logConf->getModuleName();
        $moduleData = explode('.', $moduleName);
        $this->app = $moduleData ? $moduleData[0] : $this->app;
        $this->server = isset($moduleData[1]) ? $moduleData[1] : $this->server;
    }

    /**
     * @return string
     */
    public function getApp()
    {
        return $this->app;
    }

    /**
     * @param string $app
     */
    public function setApp($app)
    {
        $this->app = $app;
    }

    /**
     * @return string
     */
    public function getServer()
    {
        return $this->server;
    }

    /**
     * @param string $server
     */
    public function setServer($server)
    {
        $this->server = $server;
    }

    /**
     * @return string
     */
    public function getDateFormat()
    {
        return $this->dateFormat;
    }

    /**
     * @param string $dateFormat
     */
    public function setDateFormat($dateFormat)
    {
        $this->dateFormat = $dateFormat;
    }

    /**
     * Writes the record down to the log of the implementing handler
     *
     * @param  array $record
     * @return void
     * @throws \Exception
     */
    protected function write(array $record)
    {
        $this->logServant->logger($this->app, $this->server, $record['channel'], $this->dateFormat, [$record['formatted']]);
    }
}
```

```
$logger = new \Monolog\Logger("tars_logger");
//remote log
$tarsHandler = new TarsHandler($config);
//local log Here you can add other handlers according to business needs，such as StreamHandler、ElasticSearchHandler
$streamHandler = new \Monolog\Handler\StreamHandler(ENVConf::$logPath . "/" . __CLASS__  . ".log");

$logger->pushHandler($tarsHandler);
$logger->pushHandler($streamHandler);

$array = [
    "key1" => "value1",
    "key2" => "value2",
    "key3" => "value3"
];
$logger->debug("add a debug message", $array);
$logger->info("add a info message", $array);
$logger->notice("add a notice message", $array);
$logger->warning("add a warning message", $array);
$logger->error("add a error message", $array);
$logger->critical("add a critical message", $array);
$logger->emergency("add a emergency message", $array);
```

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 55.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~459 days

Total

3

Last Release

1879d ago

PHP version history (2 changes)0.1.4PHP &gt;=5.3

0.1.5PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/bf1b3ee26ddb9ebe4490a8f1bcd84a7450fa70cf0bf367fd6c267ba7d353d3fd?d=identicon)[phptars](/maintainers/phptars)

---

Top Contributors

[![meijing0114](https://avatars.githubusercontent.com/u/2072584?v=4)](https://github.com/meijing0114 "meijing0114 (5 commits)")[![copyrenzhe](https://avatars.githubusercontent.com/u/2667735?v=4)](https://github.com/copyrenzhe "copyrenzhe (2 commits)")[![danielzheng-Tencent](https://avatars.githubusercontent.com/u/60135050?v=4)](https://github.com/danielzheng-Tencent "danielzheng-Tencent (1 commits)")[![dpp2009](https://avatars.githubusercontent.com/u/5278911?v=4)](https://github.com/dpp2009 "dpp2009 (1 commits)")

---

Tags

tarstars-logtarsphp

### Embed Badge

![Health badge](/badges/phptars-tars-log/health.svg)

```
[![Health](https://phpackages.com/badges/phptars-tars-log/health.svg)](https://phpackages.com/packages/phptars-tars-log)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.1k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M137](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
