Skip to content

Maatify Slim Logger is a lightweight, PSR-7 compatible, Slim-friendly structured logger for PHP applications. It is part of the modular Maatify ecosystem.

License

Notifications You must be signed in to change notification settings

Maatify/slim-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maatify Slim Logger


Maatify.dev


Current version Packagist PHP Version Support Monthly Downloads Total Downloads Stars

Tests

Maatify Slim Logger is a lightweight, PSR-7 compatible, Slim-friendly structured logger for PHP applications. It is part of the modular Maatify ecosystem.


🚀 Features

  • ✅ PSR-7 request-aware logging (integrates with Slim Framework)
  • ✅ Uses LogLevelEnum (PHP 8.1+)
  • ✅ Logs to file in JSON format
  • ✅ File names include log level (_response_error_...)
  • ✅ Static access with Logger::recordStatic()
  • ✅ Automatically creates secure log directories
  • ✅ Works with Slim or pure PHP
  • ✅ GitHub Actions CI ready

📦 Installation

composer require maatify/slim-logger

🧱 Namespaces

  • Logger: Maatify\SlimLogger\Log\Logger
  • Enum: Maatify\SlimLogger\Log\LogLevelEnum
  • Path Helper: Maatify\SlimLogger\Store\File\Path

📁 Folder Structure

maatify-slim-logger/
├── src/
│   └── Log/
│       ├── Logger.php
│       └── LogLevelEnum.php
│   └── Store/
│       └── File/
│           └── Path.php

✅ Basic Usage (Slim or Plain PHP)

use Maatify\SlimLogger\Log\Logger;
use Maatify\SlimLogger\Log\LogLevelEnum;
use Maatify\SlimLogger\Store\File\Path;

$logger = new Logger(new Path(__DIR__));
$logger->record('User login', null, 'user/actions', LogLevelEnum::Info);

💡 Usage in Slim Route

$app->post('/action', function ($request, $response) use ($logger) {
    $logger->record('User posted action.', $request, 'user/submit', LogLevelEnum::Debug);
    return $response;
});

⚠️ Logging Exceptions

try {
    throw new \Exception('Oops');
} catch (\Throwable $e) {
    $logger->record($e, null, 'errors/runtime', LogLevelEnum::Error);
}

📣 Static Logging

Log from anywhere — no need to instantiate:

use Maatify\SlimLogger\Log\Logger;
use Maatify\SlimLogger\Log\LogLevelEnum;

Logger::recordStatic('Static log entry.', null, 'system/status', LogLevelEnum::Info);

✅ Static Exception Example

try {
    throw new \Exception("Static exception!");
} catch (\Throwable $e) {
    Logger::recordStatic($e, null, 'errors/fatal', LogLevelEnum::Error);
}

🧪 (Advanced) Overriding Static Instance for Testing

In PHPUnit or setup environments, use:

$testLogger = new Logger(new Path(__DIR__ . '/logs'));
Logger::setInstance($testLogger);

Then recordStatic() will use that injected instance and path.


🔍 Log File Naming Example

/logs/24/04/18/user/actions_response_info_20250418AM.log

⚙️ Configuration

Option Default Description
Path project root Base path for log files
Extension .log File extension for log files

🧪 Run Tests Locally

composer test

🚀 GitHub CI Integration

Tests run automatically on push via:

.github/workflows/run-tests.yml


📄 License

MIT License © 2025 Maatify.dev


🙋‍♂️ Questions?


About

Maatify Slim Logger is a lightweight, PSR-7 compatible, Slim-friendly structured logger for PHP applications. It is part of the modular Maatify ecosystem.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages