Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-log

Structured event logging for Pudu: message templates, enrichment, filtering, formatting, and sinks

0.1.0Apache-2.01

InstallClose

EventId.pudu

Pudu33 lines1001 B

GitHub ↗
1/** @Log.Domain.EventId.Module — a stable identifier for each template */2module PuduLangLog.Domain.EventId34import Std.Option as Option5import Std.Text as Text67/// Hexadecimal digits by value.8const HEX: Str = "0123456789abcdef"910/// A 32-bit one-at-a-time hash of the template text: events from the same template share it.11export fn compute(template: Str) -> UInt32 {12  var hash = 0u3213  for character in template.chars() {14    hash = hash &+ Option.unwrapOr(convertInteger[UInt32](character.code()), 0u32)15    hash = hash &+ (hash << 10)16    hash = hash ^ (hash >> 6)17  }18  hash = hash &+ (hash << 3)19  hash = hash ^ (hash >> 11)20  hash &+ (hash << 15)21}2223/// The identifier as eight lower-case hexadecimal digits.24export fn hex(id: UInt32) -> Str {25  var value = Option.unwrapOr(convertInteger[Int](id), 0)26  var digits: Array[Str] = []27  while value > 0 {28    digits = [HEX.slice(value % 16, value % 16 + 1)].concat(digits)29    value = value / 1630  }31  Text.padLeft(digits.join(""), 8, "0")32}33