PHPackages                             marck-devs/simple-logger - 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. marck-devs/simple-logger

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

marck-devs/simple-logger
========================

Simple php logger library

1.0.2(4y ago)035MITPHPPHP &gt;=7.3.0

Since Sep 3Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Marck-Devs/simple-logger)[ Packagist](https://packagist.org/packages/marck-devs/simple-logger)[ RSS](/packages/marck-devs-simple-logger/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)DependenciesVersions (6)Used By (0)

Simple logger for php
=====================

[](#simple-logger-for-php)

Install
-------

[](#install)

Install via composer:

```
composer require marck-devs/simple-logger
```

Usage
-----

[](#usage)

### LogLevels

[](#loglevels)

This class contains all levels available for the logger:

- DEBUG
- LOG
- INFO
- WARN
- ERROR
- CRITICAL

Also have static method to parse string and get the corresponding level:

```
    LogLevels::log_level_from_string("debug");
```

With this method you can read the log level from .env or config file and load into logger.

### SimpleLogger

[](#simplelogger)

This is the main class.

#### Method: **public function \_\_construct($name, $level, $date\_format, $log\_format)**

[](#method-public-function-__constructname-level-date_format-log_format)

- **$name** is the name of the logger, defaults is *app*
- **$level** is the min log level that will show, default is `LogLevels::WARN`
- **$date\_format** is an *DateFormatter* interface implementation, defaults is *SimpleDateFormatter*
- **$log\_format** is an *LogForammtter* interface implementation, defaults is *SimpleFormatter*

---

#### **public function log($msg, $data=\[\])**

[](#public-function-logmsg-data)

#### **public function info($msg, $data=\[\])**

[](#public-function-infomsg-data)

#### **public function debug($msg, $data=\[\])**

[](#public-function-debugmsg-data)

#### **public function warn($msg, $data=\[\])**

[](#public-function-warnmsg-data)

#### **public function error($msg, $data=\[\])**

[](#public-function-errormsg-data)

#### **public function critical($msg, $data=\[\])**

[](#public-function-criticalmsg-data)

Write a line in the default output stream whit the passed message. This message can be formatted as python format function. In the message can put any key into braces and generate the array as dictionary whit the key and the value:

```
    class Foo{
        private static $log;

        public function __construct(){
            self::$log = new \MarckDevs\SimpleLogger\SimpleLogger("name", \MarckDevs\SimpleLogger\LogLeves::WARN);
        }

        public function fun(){
            self::$log->log("My message is {message}", ["message" => "hello"]);
            self::$log->warn("My message is {test}", ["test" => "test"]);
            self::$log->debug("My {cnt} is {message}", ["message" => "hello", "ctn"=>"message"]);
            self::$log->error("My message is {message}", ["message" => "hello"]);
        }
    }
```

There are same reserved keywords:

- {file} - get the file path
- {date} - the time date
- {user} - the current user
- {class} - the class that call logger
- {function} - the function that call logger
- {line} - the line from has been called
- {lvl} - the log level
- {msg} - the log message

If want a personal format for logger, you can create a class that implements **LogFormatter**.

Save into log files
-------------------

[](#save-into-log-files)

The *SimpleLogger* has two method to set the logs file and the errors file:

```
    SimpleLogger::set_log_file($path_to_file);
    SimpleLogger::set_error_file($path_to_file);
```

With this the default output stream will change to the files.

Make custom formatter
---------------------

[](#make-custom-formatter)

The log formatter set the way to print the log line into the main output stream. To create custom, you will need to implement the `LogFormatter` interface.

```
    class MyFormatter implements \MarckDevs\SimpleLogger\Interfaces\LogFormatter{
        public function format($string, $data = []){
            $my_format = "{date}- {lv}- {msg}";
            // generate the array with the necessaries keys
            $arr = \MarkDevs\SimpleLogger\SimpleFormatter::gen_arr($string, $data);
            // format the string
            return \MarkDevs\SimpleLogger\SimpleFormatter::set_data($string, $arr);
        }
    }
```

When you have your custon formatter you can set to the logger via static method or constructor:

```
\MarckDevs\SimpleLogger\SimpleLogger::set_log_format(new MyFormatter());
```

**In both case the formatter is set globally.**

Formating the date
------------------

[](#formating-the-date)

The default format for date is the Spanish format: `d-m-Y H:i:s`, but this can be change to custom format creatin an implementation from `DateFormatter` interface.

```
    class MyDateFormatter implements\MarckDevs\SimpleLogger\Interfaces\DateFormatter{

        public function get_date($date /*DateTime object*/): String {
            // custom format
            $format = "Y-m-d H:i:s"; // php format
            return $date->format($format);
        }
    }
```

To set to the logger, like before, you can set in the constructor or with the static method:

```
    \MarckDevs\SimpleLogger\SimpleLogger::set_date_format(new MyDateFormatter());
```

Set Log level
-------------

[](#set-log-level)

To set the log level for the logger we have the static method `set_log_level(int)`It need a **LogLevel** constant.

```
\MarckDevs\SimpleLoggerSimpleLogger::set_log_level(\MarckDevs\SimpleLogger\LogLevels::INFO)
```

File paths
----------

[](#file-paths)

When visualize the file path whit the `{file}` option, dont show full path, only the file name and same parent dir. The number of parent can be change by setting in the static method `set_dir_level(int)`. If is set 2 levels, only will show 2 dir parents.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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 ~3 days

Total

3

Last Release

1748d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/62903661?v=4)[MK Devs](/maintainers/marck-devs)[@Marck-Devs](https://github.com/Marck-Devs)

---

Top Contributors

[![marck-dev](https://avatars.githubusercontent.com/u/46191496?v=4)](https://github.com/marck-dev "marck-dev (16 commits)")

---

Tags

loglogginglogger

### Embed Badge

![Health badge](/badges/marck-devs-simple-logger/health.svg)

```
[![Health](https://phpackages.com/badges/marck-devs-simple-logger/health.svg)](https://phpackages.com/packages/marck-devs-simple-logger)
```

###  Alternatives

[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3511.6M24](/packages/analog-analog)[inpsyde/wonolog

Monolog-based logging package for WordPress.

184631.3k7](/packages/inpsyde-wonolog)[amphp/log

Non-blocking logging for PHP based on Amp, Revolt, and Monolog.

402.8M78](/packages/amphp-log)[apix/log

Minimalist, thin and fast PSR-3 compliant (multi-bucket) logger.

511.1M20](/packages/apix-log)[logtail/monolog-logtail

Logtail handler for Monolog

233.5M3](/packages/logtail-monolog-logtail)[dakatsuka/monolog-fluent-handler

Fluentd Handler for Monolog

11480.8k](/packages/dakatsuka-monolog-fluent-handler)

PHPackages © 2026

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