Download the PHP package rcezea/httplogger without Composer
On this page you can find all versions of the php package rcezea/httplogger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rcezea/httplogger
More information about rcezea/httplogger
Files in rcezea/httplogger
Package httplogger
Short Description Lightweight and flexible logging library for PHP applications. It enables developers to send log data to a remote server and log to local files.
License MIT
Informations about the package httplogger
HTTPLogger Class Documentation
Class Name: HttpLogger
Namespace: Rcezea\HttpLogger
Implements: Tracy\ILogger
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
- Server-Side Logging: Sends logs to a configurable server endpoint.
- Optional File Logging: Logs success and failed attempts to local files for debugging.
- API Authentication: Supports optional credentials (
appIdandsecretKey) for secure logging. - Platform-Specific Logging: Configurable for
webormobile. - Environment Modes: Differentiates between Development and Production modes.
Static Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
$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
Method Signature:
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../logsif not provided.
Throws:
\RuntimeExceptionif the log directory cannot be created.
Static Methods
-
setEndpoint(string $url): void
Sets the logging server endpoint.
Throws:\InvalidArgumentExceptionif the URL is invalid. -
setMode(int $mode): void
Sets the environment mode:Debugger::DevelopmentorDebugger::Production.
Throws:\InvalidArgumentExceptionfor invalid modes. setPlatform(string $platform): void
Sets the platform type (webormobile).
Throws:\InvalidArgumentExceptionfor invalid platforms.
Instance Methods
-
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 (
developmentorproduction) based on the static property. - Writes to local files if file logging is enabled.
-
sendLogToServer(array $data): void
Sends the prepared log data to the server endpoint usingcURL. logToFile(string $filePath, array $data, string $response = ''): void
Writes logs to the specified file path.
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:
For failed attempts, curl_error and server responses will be included.
Usage Example
Requirements
- PHP 8.0+
- Composer dependencies:
tracy/tracy
Changelog
- Added platform configuration (
setPlatform). - Enhanced file logging to include success and failure logs.
- Integrated API authentication.
License
This package is licensed under the MIT License.
Contributing
Contributions are welcome! Feel free to submit pull requests or open issues for improvements or bug fixes.
Author
- Richard E - Github: rcezea
Support
For questions, issues, or support, please contact [email protected].