error_log

error_log(string $message, int $message_type = 0, ?string $destination = null, ?string $additional_headers = null): bool

Log routing: message_type sends to system logger (0) / email (1) / destination file append (3) / SAPI log (4); type=0 always returns true.

C C23

C23
#include <stdio.h>
#include <syslog.h>

int main(void) {
    /* syslog(3) routes to the system logger (POSIX); vs PHP error_log type 0.
       The daemon-side format varies, so print a fixed line of our own */
    openlog("demo", LOG_PID | LOG_NDELAY, LOG_USER);
    syslog(LOG_WARNING, "structured routing demo");
    closelog();
    printf("routed to syslog\n");
    return 0;
}
Output
routed to syslog

C++ C++26

C++26
#include <iostream>

int main() {
    // C++ has no built-in logging facility: std::cerr is the stderr stream;
    // real routing (file/syslog) needs OS APIs or libraries
    std::cerr << "stderr stream\n";
    std::cout << "routed to file by hand\n";
    return 0;
}
Output
routed to file by hand
stderr stream

C# v11.0.100

v11.0.100
// Console.Error is the raw error stream; structured routing uses ILogger
// (Microsoft.Extensions.Logging) in real apps - hand-route to a file here
Console.Error.WriteLine("stderr stream");
string path = Path.Combine(Path.GetTempPath(), "cslog_a18.txt");
File.AppendAllText(path, "routed to file" + Environment.NewLine);
Console.WriteLine(File.ReadAllText(path).TrimEnd());
File.Delete(path);
Output
routed to file
stderr stream

Go v1.27.4

v1.27.4
package main

import (
	"fmt"
	"log/slog"
	"os"
)

func main() {
	// log/slog (Go 1.21+) structured logging: route to a file via a
	// TextHandler; drop the time attr to keep output deterministic
	f, err := os.CreateTemp("", "golog")
	if err != nil {
		panic(err)
	}
	defer os.Remove(f.Name())
	logger := slog.New(slog.NewTextHandler(f, &slog.HandlerOptions{
		ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
			if a.Key == slog.TimeKey {
				return slog.Attr{}
			}
			return a
		},
	}))
	logger.Warn("routed to file", "code", 42)
	data, _ := os.ReadFile(f.Name())
	fmt.Print(string(data))
}
Output
level=WARN msg="routed to file" code=42

Java v27.0.1

v27.0.1
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.logging.FileHandler;
import java.util.logging.Logger;

public class Main {
    public static void main(String[] args) throws IOException {
        // java.util.logging routes via Handler (console/file/socket); disable the
        // parent console handler (it stamps timestamps) to keep output stable
        Path log = Files.createTempFile("javalog", ".txt");
        Logger lg = Logger.getLogger("demo");
        lg.setUseParentHandlers(false);
        FileHandler handler = new FileHandler(log.toString());
        lg.addHandler(handler);
        lg.warning("routed to file");
        handler.close();
        System.out.println("handler written: " + (Files.size(log) > 0));
        Files.delete(log);
        System.err.println("stderr stream");
    }
}
Output
handler written: true
stderr stream

JavaScript v26.13.1

v26.13.1
// console.error writes to stderr; real routing uses pino/winston from the
// ecosystem - here we route to a file by hand to stay dependency-free
console.error("stderr stream");
const fs = require("fs");
const path = require("os").tmpdir() + "/jslog_a18.txt";
fs.appendFileSync(path, "routed to file\n");
process.stdout.write(fs.readFileSync(path, "utf8"));
fs.unlinkSync(path);
Output
routed to file
stderr stream

PHP v8.6.0

v8.6.0
// message_type=0: routed by the error_log ini (system logger or file); always returns true
$f = tempnam(sys_get_temp_dir(), 'elog');
ini_set('error_log', $f);
var_dump(error_log('routed by ini', 0));
unlink($f);
// message_type=3: appended verbatim to destination, no auto newline; returns real success/failure
$f2 = tempnam(sys_get_temp_dir(), 'elog');
var_dump(error_log('direct', 3, $f2));
var_dump(error_log("\nsecond", 3, $f2));
echo file_get_contents($f2);
unlink($f2);
Output
bool(true)
bool(true)
bool(true)
direct
second

Python v3.15.2

v3.15.2
import logging
import os
import sys
import tempfile

# logging module routes via Handler (stream/file/socket); the format is configurable
path = os.path.join(tempfile.gettempdir(), "pylog_a18.txt")
logger = logging.getLogger("demo")
handler = logging.FileHandler(path)
handler.setFormatter(logging.Formatter("%(levelname)s %(message)s"))
logger.addHandler(handler)
logger.setLevel(logging.INFO)
logger.warning("routed to file")
handler.close()
with open(path) as fh:
    print(fh.read().rstrip())
os.remove(path)
print("stderr stream", file=sys.stderr)
Output
WARNING routed to file
stderr stream

Rust v1.99.1

v1.99.1
use std::fs::File;
use std::io::Write;

fn main() {
    // std has no logging facility: eprintln! is the stderr stream; real
    // routing uses the `tracing` or `log` crate - hand-route to a file here
    eprintln!("stderr stream");
    let path = std::env::temp_dir().join("rslog_a18.txt");
    let mut f = File::create(&path).unwrap();
    writeln!(f, "routed to file").unwrap();
    drop(f);
    println!("{}", std::fs::read_to_string(&path).unwrap().trim_end());
    std::fs::remove_file(&path).unwrap();
}
Output
routed to file
stderr stream

TypeScript v26.13.1

v26.13.1
// console.error writes to stderr; ecosystem libs (pino/winston) do real routing
import * as fs from "fs";
import * as os from "os";
console.error("stderr stream");
const path = os.tmpdir() + "/tslog_a18.txt";
fs.appendFileSync(path, "routed to file\n");
process.stdout.write(fs.readFileSync(path, "utf8"));
fs.unlinkSync(path);
Output
routed to file
stderr stream

Language differences

C: syslog(3) (POSIX) routes to the system logger - openlog/syslog/closelog; matches PHP's type=0 (OS logging mechanism); file routing is a hand-rolled fopen append.

C++: the language itself has no logging facility - std::cerr is just the stderr stream; real routing (file/syslog) needs OS APIs or third-party libs (spdlog, Boost.Log).

C#: Console.Error is the raw error stream; production routing uses ILogger (Microsoft.Extensions.Logging, pluggable providers: console/file/cloud); this example hand-routes to a file to stay dependency-free.

Go: log/slog (Go 1.21+) is the structured-logging standard - a Handler decides the destination (TextHandler/JSONHandler write to any io.Writer); the legacy log package can only prefix.

Java: java.util.logging routes via Handler (ConsoleHandler/FileHandler/SocketHandler); note it stamps timestamps by default (SimpleFormatter) - silence the parent handler or customize the Formatter for stable output; production usually swaps in SLF4J+Logback.

JavaScript: console.error only writes stderr; real log routing is ecosystem work - pino/winston provide transports (files/network); browsers have no file routing.

PHP: error_log is a router - type=0 follows the error_log ini (system logger or file, and always returns true regardless of success! per the manual); type=1 emails (with additional_headers); type=3 appends verbatim to destination (no auto newline, returns real success/failure); type=4 sends to the SAPI log. Manual warning: error_log is not binary safe (a null character truncates the message).

Python: the logging module is textbook design - logger (hierarchical names) -> handler (destination) -> formatter (format) cleanly decoupled; the level system (DEBUG-CRITICAL) makes filtering orthogonal to routing.

Rust: std has no logging facility - eprintln! is just stderr; the ecosystem standard is the log facade plus tracing (structured/async spans, the tokio-world standard).

TypeScript: same as JavaScript (console.error + pino/winston); on Node you can also process.stdout.write directly. Evolution note: every language has moved from "redirect stderr" to "structured logging" - slog/ILogger/tracing/logging are all "levels + key-value pairs + pluggable destinations", while PHP's type parameter is the most primitive routing switch.