OxL Справочник OxL
РусскийEnglish

data log

Namespace of the logging functions: log.info("…").

Example:

oxl✓ проверяется в CI
use std.obs { log }

fn main() io {
  let id = 42
  log.info("order {id} paid")
  print("logged")
}
Вывод
logged

Примеры#

Рецепты логирования: уровни, метрики и спаны.

Уровни, метрики, спаны#

Записи log.* идут в stderr; metric.counter/gauge/histogram и span.with дополняют логи.

oxl✓ проверяется в CI
use std.obs { log, Level, metric, span }

fn handle(id: i64) -> i64  io {
  log.info("handling request {id}")  // записи идут в stderr, не в stdout
  id * 2
}

fn main() io {
  log.setLevel(Level.Info)
  let served = metric.counter("requests_total", "requests served")
  let inflight = metric.gauge("inflight", "requests in flight")
  var total = 0
  for id in 1..=3 {
    inflight.inc()
    total += span.with("handle", () => handle(id))  // span измеряет участок и попадает в трассу
    served.inc()
    inflight.dec()
  }
  log.debug("not printed: level is Info")
  print("total {total}, served {served.value()}, in flight {inflight.value()}")
  print("debug enabled: {log.enabled(Level.Debug)}")
}
Вывод
total 12, served 3.0, in flight 0.0
debug enabled: false
pub(api) data log

Потокобезопасность. safe from any task; records of different tasks may interleave, each one is written whole.

С версии. 1.0.0-beta

Методы

trace(msg: str) io
Very detailed diagnostics.
debug(msg: str) io
Diagnostics for developers.
info(msg: str) io
Normal events worth recording.
warn(msg: str) io
Something unexpected that the program handled.
error(msg: str) io
An operation failed.
at(level: Level, msg: str) io
Logs at a level chosen at run time (log.at(Level.Warn, "…")).
level() -> Level io
Current threshold
setLevel(level: Level) io
Changes the threshold of this process (the start-up value comes from --log-level / OXL_LOG).
enabled(level: Level) -> bool io
True when a record at level would be written; guard expensive field computation with it.
setJson(on: bool) io
Switches between text (false) and JSON-lines (true) output.
isJson() -> bool io
True when the output is JSON lines.

Определено в: std/obs/obs.oxl:101

См. также

OxL 1.0.0-beta · Версия документации 1.0.0-beta© OxwaldLink · сгенерировано из Стандарта, исходников std и руководства