Download the PHP package units/logger without Composer

On this page you can find all versions of the php package units/logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package logger

Units — Logger

A logger that can say which version of itself wrote the line.

A log unit: an identity (log, versioned) plus an injected adapter. The unit does not know where the line goes — console today, NATS, Redis or a WebSocket tomorrow — and because it carries DNA, whatever it writes can be attributed later: which logger, at which version.

Part of the Units collection: concrete unit implementations on the patterns/unit contract. One unit, one package.


Install

Quickstart

Two objects, one seam

Logger is a unit: it has an identity, and it takes the log line and the message and hands both to a collaborator. ILogger is that collaborator — the adapter contract.

Every call on the unit is a call on the adapter — nothing is swallowed, buffered or rewritten on the way through:

Call on the unit What it does
debug() · info() · warn() · error() forwards to the same method on the adapter
log(LogLevel::X, ...) forwards to adapter->log()
child($context) wraps adapter->child() in a new unit — not a view of the old one
dna() · whoami() answered by the unit; the adapter never sees them

Why the adapter is injected

The unit is constructed with the adapter, never for it, so the destination is a call-site decision:

Swapping console output for a broker is one line, and it is the caller's line. Nothing in this package depends on the console, and the unit never learns where the line ended up.

The unit does not filter

Logger delegates every call, including debug(). The threshold belongs to the adapter, next to the decision about what the output looks like:

Two responsibilities, two objects. The unit owns identity and delegation; the adapter owns filtering, formatting and transport.

Levels

Level Weight Meaning
Debug 0 detail you only want while investigating
Info 1 normal operation
Warn 2 surprising but handled
Error 3 something failed
Silent 4 a threshold only: nothing is severe enough to print

Child loggers

A child extends the context and keeps everything else:

child() returns a new unit wrapping a derived adapter. The parent is untouched — the child's writes never reach the parent's adapter — and the child's DNA is identical, because a child is a narrower logger, not a different one.

Provenance

This is the part the unit buys you. The logger can hand back its own identity, and that identity is a plain array you can persist:

A log line usually carries a timestamp and a context. When a threshold changed, a formatter changed or a destination changed, the version that was live at the time is the difference between a readable log and an archaeology project.

Logger::schema() gives you the same DNA without constructing a logger — useful for a health endpoint or an admin screen:

The console adapter

Messages interpolate {placeholders} from a leading array argument, and anything else you pass is appended:

Appended values are rendered with var_export(), so a string keeps its quotes and null, true and false stay distinguishable from '', 1 and 0:

An unknown placeholder is left as written. {id} stays {id} — a typo in a log message should be visible, not silent.

What is deliberately not in this package

Not here Because
File, syslog, NATS, Redis adapters implement ILogger — that is the whole point of the seam
A level threshold inside the unit filtering is the adapter's job (see above)
A global or static logger a unit is built by create() and handed to whoever needs it
Buffering, batching, retries transport concerns; the adapter or the broker owns them
A params()/config API configuration belongs to the adapter, exposed via adapterInfo()
Framework integration Logger is an object; wire it yourself, in one line

Writing an adapter

  1. Implement Units\Logger\ILogger — six methods, all returning void except child().
  2. Filter by level yourself if you have a threshold (LogLevel::shouldLog() is there for that).
  3. Return a new instance from child() with the extended context; do not mutate $this.
  4. Throw on transport failure. The unit does not catch anything for you, and a logger that silently swallows a failed write is worse than one that is noisy.
  5. Pass it in: Logger::create(['adapter' => new YourAdapter(...)]).
  6. Keep metadata in mind — Logger::create(['adapter' => ..., 'metadata' => [...]]) carries anything your adapter or your application wants to attach.

Testing

The suite runs without composer install — tests/bootstrap.php bridges to the sibling pattern packages when they are not installed. It covers the unit contract, DNA round-trip and provenance, delegation, child loggers, the level enum and the console adapter's output.

License

MIT


All versions of logger with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
patterns/unit Version ^1.0.1
patterns/value-object Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package units/logger contains the following files

Loading the files please wait ...