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))).
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.Splunk SPL users
Splunk SPL users
In Splunk SPL, the natural logarithm is called
ln() rather than log(). The SPL log() function computes the base-10 logarithm by default. In APL, log() always means the natural logarithm.ANSI SQL users
ANSI SQL users
In ANSI SQL,
LN() computes the natural logarithm and LOG() computes the base-10 logarithm in most dialects. In APL, log() means the natural logarithm, matching SQL’s LN().Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
x | real | Yes | A positive real number (x > 0). |
Returns
- The natural logarithm of
x. nullifxis negative, zero, or cannot be converted to a real value.
Example
Uselog to compress request durations onto a natural log scale.
Query
| _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.