AcLog is a simple, zero-dependency PHP package to log activity to files

Overview

AcLog

AcLog is a simple, zero-dependency PHP package to log activity to files.

This is not meant for logging errors, this is can be used for logging cronjobs, emails, user activity, etc.

Requirements

  • PHP 8.0+

Install

Add this to your existing project:

composer require xy2z/aclog

Basic Usage

use xy2z\AcLog\AcLog;

$aclog = new AcLog(__DIR__ . '/logs');
$aclog->log($var); // can be any type: object, array, string, int, etc.
$aclog->log($var, $foo, $bar, $etc); // as many arguments you want.

Set Options

$aclog = new AcLog(
    log_dir: __DIR__ . '/logs',
    log_date_format: false,
    include_trace: false,
    output_method: AcLog::VAR_DUMP,
    line_breaks_between_header: 4,
    // etc.
);

For more options see the constructor method of the AcLog.php file.

Static Class

It is also possible to use it as a static class, if you prefer.

use xy2z\AcLog\AcLogStatic;

AcLogStatic::setup(__DIR__ . '/logs');
AcLogStatic::log($var);

If you want to set options in the static class, you need to set them as an array.

AcLogStatic::setup([
    'log_dir' => __DIR__ . '/logs',
    'log_date_format' => false,
    'include_trace' => false,
    'output_method' => AcLog::VAR_DUMP,
    'line_breaks_between_header' => 4,
    // etc.
]);

Other than that, it should behave exactly the same as the AcLog class, and all public methods and properties are also available.

Static Alias

If you want a shorter name for the static class, you can alias it.

use xy2z\AcLog\AcLogStatic as acl;

acl::setup(__DIR__ . '/logs');
acl::log($var);

Log Callbacks

You can add callbacks that will be appended to each log() call, examples for this can be user information, request headers, etc. You can add as many callbacks you want.

$aclog = new AcLog($this->logdir);

$aclog->add_log_append_callback(function () {
    return 'callback-1.';
});

$aclog->add_log_append_callback(array('MyClass', 'myCallbackMethod'));

Tips

  • Consider to zip (7zip is best) the log files after a few days - it will save ALOT of diskspace.

Developing

Pull Requests are welcome, just make sure your code is tested, analysed and fixed - see below.

Remember to make tests for both classes: AcLog and AcLogStatic.

# Fix Coding Standards (php-cs-fixer)
vendor/bin/php-cs-fixer fix

# Analyse code (phpstan)
vendor/bin/phpstan analyse -c phpstan.neon

# Test code (phpunit)
vendor/bin/phpunit tests --testdox

Todo

  • badges
  • Later: Method for getting options values
  • examples dir?
You might also like...
Simple PHP Logger. Composer package

Basic PHP Logger đź“ť Simple logger. Composer package.

A Simple Logging Class For PHP

KLogger: Simple Logging for PHP A project written by Kenny Katzgrau and Dan Horrigan. About KLogger is an easy-to-use PSR-3 compliant logging class fo

PHP logging library that is highly extendable and simple to use.

Analog - Minimal PHP logging library Copyright: (c) 2012-Present Johnny Broadway License: MIT A minimal PHP logging package based on the idea of using

This package is for centralized logging of multiple Laravel application into one connection.

Laralogs This package is for centralized logging of multiple Laravel application into one connection. Installation You can install the package via com

Small package that can helps in debugging with API logs for Laravel Project.

Rest APIs Logger This is a small package that can helps in debugging with API logs. Installation Install the package via composer composer require tfs

Small laravel package for viewing api logs which can be used in debugging.
Small laravel package for viewing api logs which can be used in debugging.

This is a small package that can helps in debugging api logs. It can log request method, url, duration, request payload, which models are retrieved, controller and method.

A simple database logger for all outgoing emails sent by Laravel website.

Laravel Email Database Log A simple database logger for all outgoing emails sent by Laravel website.

temperature-pi: a simple Raspberry Pi based temperature logger using a DS18B20 1-Wire digital temperature sensor, & a local sqlite database
temperature-pi: a simple Raspberry Pi based temperature logger using a DS18B20 1-Wire digital temperature sensor, & a local sqlite database

temperature-pi temperature-pi is a simple Raspberry Pi based temperature logger using a DS18B20 1-Wire digital temperature sensor, & a local sqlite da

ChromePhp - a PHP library for the Chrome Logger Google Chrome extension

ChromePhp - a PHP library for the Chrome Logger Google Chrome extension

Comments
  • Custom log filename

    Custom log filename

    Filename shouldnt have to be dates, to make it more flexible it should just be a string the user sets. Eg. $aclog->set_filename('my-logs--' . date('Y-m-d') . '.log')

    opened by xy2z 0
Releases(2.0.0)
Owner
Twitter: @xy2z
null
DatabaseLog CakePHP plugin to log into DB instead of files. Better to filter and search.

CakePHP DatabaseLog Plugin DatabaseLog engine for CakePHP applications. This branch is for CakePHP 4.0+. See version map for details. Features Easy se

Mark Sch. 41 Jul 29, 2022
A simple and beautiful laravel log reader

Laravel Log Reader A simple and beautiful laravel log reader Documentation Get full documentation of Laravel Log Reader Other Packages Laravel H - A h

Md.Harun-Ur-Rashid 356 Dec 30, 2022
An effective,fast,stable log extension for PHP

SeasLog An effective,fast,stable log extension for PHP @author Chitao.Gao [[email protected]] Documentation On php.net 中文文档 Synopsis Why use seaslog What

Neeke Gao 76 Sep 28, 2022
Flexible and rock solid audit log tracking for CakePHP 3

AuditStash Plugin For CakePHP This plugin implements an "audit trail" for any of your Table classes in your application, that is, the ability of recor

José Lorenzo Rodríguez 68 Dec 15, 2022
Remove messages from the error log that are from a certain folder

Error-Focus A package to stay focused on relevant entries in your error-log Scope This package allows you to declare folders that are not under your d

Andreas Heigl 7 Jul 25, 2022
Log Laravel application request and response with a unique ID for easy debugging

Flexible and extendable logging of Laravel application request and responses Zero configuration logging of Requests and Responses to database or custo

Bilfeldt 37 Nov 6, 2022
123Solar is a set of PHP/JS files that make a web logger to monitor your photovoltaic inverter(s)

123Solar is a set of PHP/JS files that make a web logger to monitor your photovoltaic inverter(s). It just need a web server and PHP, no databases are even needed. The philosophy is: To keep it simple, fast, with a low foot print to run on cheap and low powered devices.

null 30 Jan 6, 2023
High-performance API performing logging for PHP applications into files or SysLog

Logging API Table of contents: About Configuration Binding Points Logging Installation Unit Tests Reference Guide Specifications How Are Log Lines For

Lucian Gabriel Popescu 0 Jan 9, 2022
Sends your logs to files, sockets, inboxes, databases and various web services

Monolog - Logging for PHP Monolog sends your logs to files, sockets, inboxes, databases and various web services. See the complete list of handlers be

Jordi Boggiano 20.1k Jan 8, 2023
Sends your logs to files, sockets, inboxes, databases and various web services

Monolog - Logging for PHP âš  This is the documentation for Monolog 3.x, if you are using older releases see the documentation for Monolog 2.x or Monolo

Jordi Boggiano 20.1k Jan 7, 2023