A standard yet lightweight NCC logging library for logging events both big and small with real-time tracing for debugging purposes.
Find a file
2024-10-29 14:18:30 -04:00
.github/workflows Added PhpUnit test files 2024-10-29 00:40:04 -04:00
.idea Added PhpUnit test files 2024-10-29 00:40:04 -04:00
src/LogLib This update introduces a critical bug fix where Console logging was enabled in web environments 2024-10-29 14:18:30 -04:00
tests Updated LogTest 2024-10-29 00:38:37 -04:00
.gitignore Updated .gitignore 2024-10-29 00:40:18 -04:00
.gitlab-ci.yml Updated .gitlab-ci.yml 2023-10-12 00:35:39 -04:00
bootstrap.php Added PhpUnit test files 2024-10-29 00:40:04 -04:00
CHANGELOG.md This update introduces a critical bug fix where Console logging was enabled in web environments 2024-10-29 14:18:30 -04:00
LICENSE Updated LICENSE formatting 2023-10-11 18:46:27 -04:00
Makefile Updated build system 2024-10-13 16:40:55 -04:00
phpdoc.dist.xml Updated Build System 2024-10-13 16:36:35 -04:00
phpunit.xml Added PhpUnit test files 2024-10-29 00:40:04 -04:00
project.json This update introduces a critical bug fix where Console logging was enabled in web environments 2024-10-29 14:18:30 -04:00
README.md Updated README.md 2023-10-12 23:45:34 -04:00

LogLib

A logging library for PHP/ncc, this was quickly thrown together to provide a simple logging interface and to test out NCC's capabilities for PHP.

Table of Contents

Installation

The library can be installed using ncc:

ncc install -p "nosial/libs.log=latest@n64"

A static version of the library can be installed using ncc, the --skip-dependencies flag is option but prevents additional dependencies from being installed.

ncc install -p "nosial/libs.log=latest@n64" --static --skip-dependencies

or by adding the following to your project.json file under the build.dependencies section:

{
  "name": "net.nosial.loglib",
  "version": "latest",
  "source": "nosial/libs.log=latest@n64"
}

If you don't have the n64 source configured you can add it by running the following command:

ncc source add --name n64 --type gitlab --host git.n64.cc

Compiling from source

The library can be compiled from source using ncc:

ncc build --config release

or by running the following command:

make release

Usage

The usage of this library is very simple, there are multiple error levels that can be used to log messages

<?php
  
  require 'ncc';
  import('net.nosial.loglib');

  \LogLib\Log::debug('com.example.lib', 'This is a debug message');
  \LogLib\Log::verbose('com.example.lib', 'This is a verbose message');
  \LogLib\Log::info('com.example.lib', 'This is an info message');
  \LogLib\Log::warning('com.example.lib', 'This is a warning message');
  \LogLib\Log::error('com.example.lib', 'This is an error message');
  \LogLib\Log::fatal('com.example.lib', 'This is a fatal message');

To display the log messages, you can run your program with the --log-level argument, this will display all messages with a level equal to or higher than the one specified.

myprogram --log-level info

The log level can be set to one of the following:

  • debug, 6, dbg
  • verbose, 5, vrb
  • info, 4, inf
  • warning, 3, wrn
  • error, 2, err
  • fatal, 1, ftl
  • silent, 0, sil

The default log level is info.

Note: Log messages are only displayed if the program is run from the command line, if you are running the program from a web server, the log messages will be shown

Changelog

See CHANGELOG.md

License

LogLib is licensed under the MIT license, see LICENSE