PHPackages                             rcezea/httplogger - 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. rcezea/httplogger

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

rcezea/httplogger
=================

Lightweight and flexible logging library for PHP applications. It enables developers to send log data to a remote server and log to local files.

v1.0.0(1y ago)03MITPHP

Since Dec 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/rcezea/http-logger)[ Packagist](https://packagist.org/packages/rcezea/httplogger)[ RSS](/packages/rcezea-httplogger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

### **HTTPLogger Class Documentation**

[](#httplogger-class-documentation)

**Class Name:** `HttpLogger`
**Namespace:** `Rcezea\HttpLogger`
**Implements:** `Tracy\ILogger`

---

### **Overview**

[](#overview)

The `HttpLogger` class implements the `ILogger` interface to send error logs to a server endpoint while providing optional local file logging. It supports both web and mobile platforms and enables environment-based logging modes (Development or Production).

---

### **Features**

[](#features)

1. **Server-Side Logging:** Sends logs to a configurable server endpoint.
2. **Optional File Logging:** Logs success and failed attempts to local files for debugging.
3. **API Authentication:** Supports optional credentials (`appId` and `secretKey`) for secure logging.
4. **Platform-Specific Logging:** Configurable for `web` or `mobile`.
5. **Environment Modes:** Differentiates between Development and Production modes.

---

### **Static Properties**

[](#static-properties)

PropertyTypeDefault ValueDescription`$endpoint``string``'http://127.0.0.1:5000/errorhandler'`Server endpoint URL for logs.`$mode``bool``Debugger::Development`Logging mode: Development or Production.`$platform``string``'web'`Specifies platform: `web` or `mobile`.---

### **Constructor**

[](#constructor)

**Method Signature:**

```
public function __construct(
    ?string $appId = NULL,
    ?string $secretKey = NULL,
    bool $logToFile = FALSE,
    ?string $logDir = NULL
)
```

**Parameters:**

- `$appId` (`string|null`): Optional API authentication ID.
- `$secretKey` (`string|null`): Optional API secret key.
- `$logToFile` (`bool`): Enables or disables file logging.
- `$logDir` (`string|null`): Directory path for storing log files. Defaults to `../logs` if not provided.

**Throws:**

- `\RuntimeException` if the log directory cannot be created.

---

### **Static Methods**

[](#static-methods)

1. **`setEndpoint(string $url): void`**
    Sets the logging server endpoint.
    **Throws:** `\InvalidArgumentException` if the URL is invalid.
2. **`setMode(int $mode): void`**
    Sets the environment mode: `Debugger::Development` or `Debugger::Production`.
    **Throws:** `\InvalidArgumentException` for invalid modes.
3. **`setPlatform(string $platform): void`**
    Sets the platform type (`web` or `mobile`).
    **Throws:** `\InvalidArgumentException` for invalid platforms.

---

### **Instance Methods**

[](#instance-methods)

1. **`log(mixed $value, string $level = ILogger::INFO): void`**
    Logs messages or exceptions to the server and optionally to local files.

    - `$value` (`mixed`): The message or exception to log.
    - `$level` (`string`): Log level, e.g., `ILogger::INFO`.

    **Behavior:**

    - Sends logs to the configured endpoint using `cURL`.
    - Includes optional API credentials.
    - Determines the mode (`development` or `production`) based on the static property.
    - Writes to local files if file logging is enabled.
2. **`sendLogToServer(array $data): void`**
    Sends the prepared log data to the server endpoint using `cURL`.
3. **`logToFile(string $filePath, array $data, string $response = ''): void`**
    Writes logs to the specified file path.

---

### **Logging to Files**

[](#logging-to-files)

If `$logToFile` is enabled during object instantiation, logs will be written to:

- **Success Logs:** `success_log.txt`
- **Failed Logs:** `failed_log.txt`

**Format of File Logs:**

```
[2024-06-17 10:45:00]
LEVEL: info
Message: Sample log message
Stack: N/A
Platform: web
Environment: development
-----------------------------------

```

For failed attempts, `curl_error` and server responses will be included.

---

### **Usage Example**

[](#usage-example)

```
require_once dirname(__DIR__) . '/vendor/autoload.php'; // map to exact autoload location
use Rcezea\HttpLogger\HttpLogger;
use Tracy\Debugger;
use Tracy\ILogger

// Initialize Logger
$logger = new HttpLogger(
    appId: 'myAppId',
    secretKey: 'mySecretKey',
    logToFile: true
);

// Set optional configurations
HttpLogger::setEndpoint('https://api.example.com/logs');
HttpLogger::setPlatform('mobile');
HttpLogger::setMode(Debugger::Production);

// Log an exception
try {
    throw new \Exception('Something went wrong!');
} catch (\Throwable $e) {
    $logger->log($e, ILogger::ERROR);
}

// Log a message
$logger->log('This is an informational message.', ILogger::INFO);
```

---

### **Requirements**

[](#requirements)

- PHP 8.0+
- Composer dependencies: `tracy/tracy`

---

### **Changelog**

[](#changelog)

- Added platform configuration (`setPlatform`).
- Enhanced file logging to include success and failure logs.
- Integrated API authentication.

---

### License

[](#license)

This package is licensed under the MIT License.

---

### Contributing

[](#contributing)

Contributions are welcome! Feel free to submit pull requests or open issues for improvements or bug fixes.

---

### Author

[](#author)

- **Richard E** - Github: [rcezea](https://github.com/rcezea)

---

### Support

[](#support)

For questions, issues, or support, please contact .

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance40

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

509d ago

### Community

Maintainers

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

---

Top Contributors

[![rcezea](https://avatars.githubusercontent.com/u/63243893?v=4)](https://github.com/rcezea "rcezea (16 commits)")

### Embed Badge

![Health badge](/badges/rcezea-httplogger/health.svg)

```
[![Health](https://phpackages.com/badges/rcezea-httplogger/health.svg)](https://phpackages.com/packages/rcezea-httplogger)
```

###  Alternatives

[kdyby/monolog

Integration of Monolog into Nette Framework

33684.0k10](/packages/kdyby-monolog)[contributte/newrelic

NewRelic PHP agent integration for Nette Framework

19822.4k](/packages/contributte-newrelic)[mangoweb/monolog-tracy-handler

Integrates Tracy into Monolog, supports uploading Tracy bluescreens to AWS S3

20327.5k1](/packages/mangoweb-monolog-tracy-handler)[nextras/tracy-monolog-adapter

Nextras Tracy-Monolog Adapter

1128.1k](/packages/nextras-tracy-monolog-adapter)

PHPackages © 2026

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