PHPackages                             sohelaman/hello-log - 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. sohelaman/hello-log

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

sohelaman/hello-log
===================

Hello World kind of logger for PHP

0.0.1(7y ago)111MITPHPPHP &gt;=5.4.0

Since Nov 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/sohelaman/hello-log)[ Packagist](https://packagist.org/packages/sohelaman/hello-log)[ RSS](/packages/sohelaman-hello-log/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)DependenciesVersions (2)Used By (0)

HelloLog
========

[](#hellolog)

### Hello World kind of logger for PHP

[](#hello-world-kind-of-logger-for-php)

Features
--------

[](#features)

- Logs data in file or returns data for printing/storing.
- Additional information like timestamp, data type, serial number is added to log.
- Simple browser friendly formatting.
- Supports major data types, arrays, objects.
- Supports output in JSON format.
- Built in counter.
- Support for changing file name any time while logging.
- Time based file name suffix can be used to segregate log files.

Basic Usage
-----------

[](#basic-usage)

Grab the package using Composer

```
$ composer require sohelaman/hello-log
```

Then use it in your PHP script

```
// Composer autoload
require_once 'vendor/autoload.php';

use HelloLog\HelloLog;

// Create a HelloLog instance
$hellolog = new HelloLog('/home/sohel/Documents/Logfile.log');

// Simply print a message, this will not put message in log file
$hellolog->msg('Arthur Curry, I hear you can talk to fish.');

// Put some info in log file
$data = "Luke, I am your father!";
$hellolog->info($data);

// AND YESS!! There are shortcuts too!
$data = array("Diana" => "He said he'll fight with us?", "Bruce" => "More or less.");
$hellolog->i($data); // Same as info()

// Similarly put error or warning into the log
$hellolog->warn("So, you're fast?");
$hellolog->error("That feels like an over simplification.");

// Pass array or object
$hellolog->i($_SERVER);

// Return output instead of putting into log. Pass true as second parameter.
echo $hellolog->i("I'm real when it's useful.", true); // Prints instead of putting into log
```

Documentation
-------------

[](#documentation)

### Constructor

[](#constructor)

- Default constructor will use **/tmp** directory and a file called **hellolog.log**.
- *Note that in many systems, apache users like http or www-data create subdirectories under /tmp directory and then create files.*

```
$hellolog = new HelloLog();
```

- Instantiate with path and file segmentation configurations

```
$hellolog = new HelloLog(, );
$hellolog = new HelloLog('/home/sohel/Documents/Logfile.log', 'DAY');
```

- Third constructor parameter is the overwrite flag. If it's true, then the file will be overwritten on each log.

```
$hellolog = new HelloLog(, , );
$hellolog = new HelloLog('/home/sohel/Documents/Logfile.log', 'DAY', true);
```

- NOTE that, once overwrite flag is turned on, file will be overwritten EACH time you put anyting into log file. So, previous content will be gone from that file. Overwrite flag can be turned on or off using overwrite() method. If not explicitly specified, overwrite flag is truned off by default.

```
$hellolog->overwrite(false); // Turns off overwrite flag. So, logs will be appended after this call.
$hellolog->overwrite(true); // Turns on overwrite flag.
```

### File Segmentation

[](#file-segmentation)

- Log file segmentation puts a suffix in log file name based on time.
- For example, 'DAY' will add a suffix for a day, such as 2016-08-30, and make the file name like **Logfile\_2016-08-30.log**
- Suffix is added with the given file name, so if there's a file named **Logfle.log**, then a new file will be created with a name **Logfile\_2016-08-30.log** if not already exists,
- Other segmentations are 'NONE', 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'
- Default segmentation is 'NONE', which won't create any segments and put all logs in one file.

### Getters and Setters

[](#getters-and-setters)

- You can set file path and file segmentation using setter methods, and these will impact instantly.

```
$hellolog->setPath('/var/www/logs/New.log');
$hellolog->setSeg('MINUTE'); // 'NONE', 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'
```

- Get current path and segmentation configuration using getter methods.

```
$path = $hellolog->getPath();
$seg = $hellolog->getSeg();
```

### Logging Type

[](#logging-type)

- There are five similar yet different methods

```
$data = 'I can do this all day!';
$hellolog->info($data); // General info, uses print_r() output
$hellolog->error($data);
$hellolog->warn($data);
$hellolog->debug($data); // Extensive debug, uses var_export() output
$hellolog->json($_SERVER); // Uses JSON string
```

- All of these methods have short names.

```
$hellolog->i($data);
$hellolog->d($data);
$hellolog->j($data);
$hellolog->e($data);
$hellolog->w($data);
```

- Output can be returned instead of putting in log file. Passing **true** as second parameter will return the data.

```
$output = $hellolog->d($data, true);
$output = $hellolog->j($data, true);
```

### Output Format

[](#output-format)

- Output data is a string containing a preamble followed by formatted data.
- Preamble consists of log serial number, timestamp, log type and data type. Preamble looks like following,

```
[2] [2016-09-03 09:35:10] [DEBUG] [DATATYPE:object]

```

- When data is returned, by default it's wrapped inside `` tag, just to increase readability on browser.
- Pretty formatting can be disabled and enabled by calling **ugly()** and **pretty()** methods respectively.

```
$hellolog->ugly(); // Disables  wrapper
$hellolog->pretty();
```

- json() method has a third parameter, allowing raw output. Raw output does not have any preamble or pretty formatting.

```
$serverJSON = $hellolog->j($_SERVER, true, true); // Returns JSON string of $_SERVER variable.
```

### Counter

[](#counter)

- HelloLog has a built in counter. Counting starts from zero. Each time calling count() method will increment counter by one.

```
echo $hellolog->count(); // Increments the counter by one
```

- Counter has other actions, like decrement. reset and get current value. Action strings are passed as function parameter. For all actions, counter performs the action first and then returns the counter value.

```
echo $hellolog->count('DEC'); // Decrements the counter by one
echo $hellolog->count('RESET'); // Resets the counter to zero
echo $hellolog->count('GET'); // Get the current counter value
```

### Others

[](#others)

- Print timestamp. Timestamp can be returned by passing **true** as parameter.

```
$hellolog->time();
echo $hellolog->time(true);
```

- Print a simple message

```
$hellolog->msg('Winter is coming!');
$hellolog->msg(); // This will simply print 'Hello, World!'
```

**That'd be all. Thanks!**

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 72.7% 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

2728d ago

### Community

Maintainers

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

---

Top Contributors

[![sohelaman](https://avatars.githubusercontent.com/u/8879831?v=4)](https://github.com/sohelaman "sohelaman (8 commits)")[![SohelAmanKhan](https://avatars.githubusercontent.com/u/50540127?v=4)](https://github.com/SohelAmanKhan "SohelAmanKhan (3 commits)")

### Embed Badge

![Health badge](/badges/sohelaman-hello-log/health.svg)

```
[![Health](https://phpackages.com/badges/sohelaman-hello-log/health.svg)](https://phpackages.com/packages/sohelaman-hello-log)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

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