PHPackages                             stange/slog - 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. stange/slog

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

stange/slog
===========

A simple PHP logging class

1.0.1(9y ago)01251MITPHPPHP ^5.3.3 || ^7.0

Since Mar 11Pushed 9y ago1 watchersCompare

[ Source](https://github.com/pthreat/slog)[ Packagist](https://packagist.org/packages/stange/slog)[ RSS](/packages/stange-slog/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (2)Used By (1)

Slog (Simple Log)
=================

[](#slog-simple-log)

**A simple PHP logging class**

Preface
-------

[](#preface)

Slog is a simple PHP logging class which you can easily include in any of your projects.

Installing Slog
---------------

[](#installing-slog)

### You can clone the latest version from GIT

[](#you-can-clone-the-latest-version-from-git)

```
git clone https://github.com/pthreat/slog.git

```

### Or just add Slog to your project via composer

[](#or-just-add-slog-to-your-project-via-composer)

```
composer require stange/slog

```

Features
--------

[](#features)

- ANSI output coloring
- Log to a file
- Log tags (see below)
- Prepend or append a log string
- Prefix your log messages with a specific date format

Examples
--------

[](#examples)

### Basic Example

[](#basic-example)

```
use \stange\logging\Slog;

$log	=	new Slog();
$log->log('Scotty, beam me up!');
```

---

### Using specific log types types and ANSI coloring capabilities

[](#using-specific-log-types-types-and-ansi-coloring-capabilities)

Slog contains different methods for you to inform different types of log messages. Also, by default, SLog will colorize your log output

```
use \stange\logging\Slog;

$log	=	new Slog();

$log->log('test message');
$log->debug('Debug');
$log->info('Info');
$log->warning('Warning');
$log->error('Error');
$log->emergency('Emergency');
$log->success('Success');
```

Result:

[![alt tag](https://raw.githubusercontent.com/pthreat/slog/master/screenshots/colors.png)](https://raw.githubusercontent.com/pthreat/slog/master/screenshots/colors.png)

You can of course, disable output coloring

```
use \stange\logging\Slog;

$log	=	new Slog([
                   'colors' => FALSE
]);

//You can disable colors at runtime too

//$log->useColors(FALSE);

$log->debug('Debug');
```

---

### Log to a file

[](#log-to-a-file)

```
use \stange\logging\Slog;

$log	=	new Slog([
                   'file'=>'out.log'
]);

$log->log('Log to a file (and to stdout)');
```

**NOTE:** ANSI colors will not be logged into the file

---

### File only output example

[](#file-only-output-example)

In case you don't want to output to stdout, you can pass in **'echo'=&gt;FALSE** in the constructor or disable stdout output by using **Slog::setEcho(FALSE)**.

```
use \stange\logging\Slog;

$log	=	new Slog([
                   'file'   => 'out.log',
                   'echo'   => FALSE

]);

$log->log("No stdout log, file only");
```

---

Log Tagging
-----------

[](#log-tagging)

###### Logging is a great thing, however sometimes the amount of logged information can be cumbersome.

[](#logging-is-a-great-thing-however-sometimes-the-amount-of-logged-information-can-be-cumbersome)

\*\* A cool feature of Slog is that you can tag your logs. \*\*

### Tag your logs? What do you mean?

[](#tag-your-logs-what-do-you-mean)

I mean that you can use certain "tags" in your log messages for logging messages of a certain kind but not others of a different kind.

Here is a brief example of two tagged log messages:

```
use \stange\logging\Slog;

$log	=	new Slog([
                   'tagId'=>'@@@'
]);

$log->log('tagOne@@@Hello! this is a tagged message with the tag tagOne');
$log->log('tagTwo@@@This is another tagged message with the tagTwo');
```

In the previous example, both messages will be logged and shown through stdout.

However, now, if we add a log tag to slog things will be a bit different.

Only messages which match the tag "tagOne" will be logged. Messages containing the tag "tagTwo" will be discarded, i.e: not logged.

```
$log	=	new Slog([
                       'tagId' => '@@@',   //Set the tag identifier to @@@
                       'tags'  => 'tagOne' //Log messages only from tagOne
]);

$log->log('tagOne@@@Hello! this is a tagged message with the tag tagOne');

//The next message will not be logged since we specified that only messages
//containing the tag "tagOne" will be logged.

$log->log('tagTwo@@@This is another tagged message with the tagTwo');
```

You can log multiple tags if you need to, this would be a good idea when you want to increase your log verbosity

```
$log	=	new Slog([
                       'tagId' => '@@@',              //Set the tag identifier to @@@
                       'tags'  => ['tagOne','tagTwo'] //Log messages from tagOne AND tagTwo
]);

$log->log('tagOne@@@Hello! this is a tagged message with the tag tagOne');
$log->log('tagTwo@@@This is another tagged message with the tagTwo');
```

### Adding or removing log tags on the run

[](#adding-or-removing-log-tags-on-the-run)

You can add or remove a tag at any given point in time through the methods:

- **Slog::removeTag($tag)** Removes a tag
- **Slog::addTag($tag)** Specifies that messages containing a tag should be logged
- **Slog::unsetTags()** Log everything

### Loggable Trait and Loggable Interface

[](#loggable-trait-and-loggable-interface)

As an extra, I have included a simple logging trait which will enable you to use said trait in your own classes to make said class "Loggable", this trait contains three main methods:

- **Loggable::setLog(LogInterface $log)**
- **Loggable::getLog()**
- **Loggable::log($message,$type=NULL)**

**NOTE:** The trait will also prepend the **CLASS** name to the log, in this way, if you have multiple classes which make use of the loggable trait, you can identify which logs come from one class and which other logs come from another

### Trait and Loggable interface implementation example

[](#trait-and-loggable-interface-implementation-example)

```
namespace myProject{

	/**
	 * Add the loggable interface to indicate to other class methods
	 * that this class has logging capabilities.
	 */

	use \stange\logging\slog\iface\Loggable	as	LoggableInterface;

	class MyClass implements LoggableInterface{

		//Make the class "Loggable" by using the loggable trait
		use \stange\logging\slog\traits\Loggable;

		public function doStuff(){

			$this->log('stuff@@@Doing stuff!');

		}

		public function doOtherStuff(){

			$this->log('otherStuff@@@Doing other stuff!','info');

		}

	}

	class MyOtherClass implements LoggableInterface{

		use \stange\logging\slog\traits\Loggable;

		public function doSomething(){

			$this->log('Doing something!','success');

		}

	}

}
```

### With the previous code we could easily do the following implementation

[](#with-the-previous-code-we-could-easily-do-the-following-implementation)

```
	namespace myProject;

	use \stange\logging\Slog();

	$log     =  new Slog([
                              'tagId'	=>	'@@@',
										'tags'	=>	'stuff'
	]);

	$myClass      = new MyClass();
	$myOtherClass = new MyOtherClass();

	$myClass->setLog($log);
	$myOtherClass->setLog($log);

	$myClass->doStuff();
	$myClass->doingOtherStuff();
	$myOtherClass->doSomething();
```

---

TODO (next release)
-------------------

[](#todo-next-release)

- Create an adapter pattern for logging messages in different places
- Add logging adapters (Socket, File, Memory, etc)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3398d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c58f421340779f50b5cf5e0e1f0501692ee5141889dbe406509d795f0a728e3e?d=identicon)[pthreat](/maintainers/pthreat)

---

Top Contributors

[![pthreat](https://avatars.githubusercontent.com/u/8527076?v=4)](https://github.com/pthreat "pthreat (8 commits)")

---

Tags

consolelogloggingphpsimplelogconsolelogging

### Embed Badge

![Health badge](/badges/stange-slog/health.svg)

```
[![Health](https://phpackages.com/badges/stange-slog/health.svg)](https://phpackages.com/packages/stange-slog)
```

###  Alternatives

[monolog/monolog

Sends your logs to files, sockets, inboxes, databases and various web services

21.4k997.8M7.9k](/packages/monolog-monolog)[symfony/monolog-bundle

Symfony MonologBundle

2.9k258.2M1.7k](/packages/symfony-monolog-bundle)[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k240.0M315](/packages/sentry-sentry)[sentry/sentry-laravel

Laravel SDK for Sentry (https://sentry.io)

1.3k122.6M186](/packages/sentry-sentry-laravel)[rap2hpoutre/laravel-log-viewer

A Laravel log reader

3.2k15.2M77](/packages/rap2hpoutre-laravel-log-viewer)[sentry/sdk

This is a meta package of sentry/sentry. We recommend using sentry/sentry directly.

327137.6M163](/packages/sentry-sdk)

PHPackages © 2026

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