log
This page explains how to use the log function in APL.
Use the log function in APL to compute the natural logarithm (base-e) of a positive numeric value. The function is the inverse of exp.
log is one of the most commonly used mathematical functions in observability. Log-transforming latency, error counts, or request rates compresses wide value ranges into a more manageable scale, reduces the influence of extreme outliers, and can reveal patterns that are linear on a log scale. It's also the basis for computing geometric means with exp(avg(log(x))).
Usage
Syntax
APL
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
x | real | Yes | A positive real number (x > 0). |
Returns
- The natural logarithm of
x. nullifxis negative, zero, or can't be converted to a real value.
Example
Use log to compress request durations onto a natural log scale.
Query
Output
| _time | id | req_duration_ms | log_duration |
|---|---|---|---|
| 2024-11-14 10:00:00 | user-1 | 1.0 | 0.0000 |
| 2024-11-14 10:01:00 | user-2 | 100.0 | 4.6052 |
| 2024-11-14 10:02:00 | user-3 | 10000.0 | 9.2103 |
List of related functions
- exp: Returns e^x. Use it as the inverse of
logto return to the original scale. - log2: Returns the base-2 logarithm. Use it for binary-scale analysis such as bit depth or memory sizing.
- log10: Returns the base-10 logarithm. Use it for order-of-magnitude analysis or decibel calculations.
- loggamma: Returns the log of the absolute value of the gamma function. Use it to avoid overflow when computing
gammaon large inputs. - sqrt: Returns the square root. Use it as a lighter alternative to
logfor compressing small value ranges.