amattu2/event-logger

A lightweight, basic PHP 7+ event message logger that eases the workload of writing and generating timestamped events.

v1.0.0 2023-03-09 22:38 UTC

This package is not auto-updated.

Last update: 2025-01-11 05:38:22 UTC


README

This is a basic PHP event logger class for writing HTML based event logs.

Usage

addEvent

This function is used to add a new event log. Optionally override the default timestamp (now).

/**
 * Add a new event to the log
 *
 * @param string $text event content
 * @param ?DateTime $timestamp event timestamp
 * @return boolean success
 * @author Alec M.
 */
public function addEvent(string $text, \DateTime $timestamp = null) : bool

getStartTime

This function returns the exact DateTime for the timestamp of the first event added.

/**
 * Return first event timestamp
 *
 * @return \DateTime
 */
public function getStartTime() : \DateTime

getEndTime

This function returns the timestamp as a DateTime for the last time an event was added to the log.

/**
 * Return last event timestamp
 *
 * @return \DateTime
 */
public function getEndTime() : \DateTime

getEvents

This returns the event log as an array.

/**
 * Return collection of events
 *
 * @return array
 */
public function getEvents() : array

getEventsTable

This returns the event log formatted as an HTML table. Optionally override the DateTime format for events.

/**
  * Return the event list as a HTML table
  *
  * @param string $date_format DateTime format string
  * @return string HTML table
  */
public function getEventsTable(string $date_format = "Y-m-d G:i:s") : string

Requirements & Dependencies

PHP 7+ or above