{"id":17183395,"url":"https://github.com/geod24/dtext","last_synced_at":"2026-01-04T23:50:27.670Z","repository":{"id":65061111,"uuid":"469568588","full_name":"Geod24/dtext","owner":"Geod24","description":"A library providing a formatter and logger for D","archived":false,"fork":false,"pushed_at":"2025-01-24T09:49:50.000Z","size":104,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"v1.x.x","last_synced_at":"2025-01-24T10:29:27.541Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Geod24.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-14T03:34:07.000Z","updated_at":"2025-01-24T09:49:51.000Z","dependencies_parsed_at":"2023-01-13T15:24:18.066Z","dependency_job_id":null,"html_url":"https://github.com/Geod24/dtext","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geod24%2Fdtext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geod24%2Fdtext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geod24%2Fdtext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geod24%2Fdtext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Geod24","download_url":"https://codeload.github.com/Geod24/dtext/tar.gz/refs/heads/v1.x.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245388267,"owners_count":20607149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T00:40:28.023Z","updated_at":"2026-01-04T23:50:27.620Z","avatar_url":"https://github.com/Geod24.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dtext: Industry proven formatter / logger\n\nDtext consist of a format package, offering similar capabilities to `std.format`,\nand a `log` package, offering a powerful `Logger` class.\n\nBoth packages have been extracted from [ocean](https://github.com/sociomantic-tsunami/ocean/),\nand have been used in real-time bidding applications for the better part of a decade.\n\n## Formatter\n\nThe building block of Dtext is `dtext.format.Formatter`.\nIt is an implementation as a formatter that is guaranteed to minimally allocate,\nand never under some circumstances.\n\nIt consists of a few overloads:\n```D\n/// Pedestrian `format`: Returns a new, GC-allocated string\npublic string format (Args...) (in char[] fmt, Args args);\n\n/// Building block: Takes a delegate, allow to implement any allocation strategy,\n/// including using `malloc` or one of Phobos' allocators\npublic bool sformat (Args...) (scope FormatterSink sink, in char[] fmt, Args args);\n\n/// Similarly to `sprintf`, will write to `buffer` up to its available length\n/// Does not allocate on its own, but might lead to GC allocations if `args`\n/// has allocating `toString`.\npublic char[] snformat (Args...) (char[] buffer, in char[] fmt, Args args)\n\n/// Will append (using `~=`) to `buffer`. Intended to be used with `assumeSafeAppend`.\npublic char[] sformat (Args...) (ref char[] buffer, in char[] fmt, Args args)\n```\n\nIf you just intend to replace `std.format`, the basic `format` overload will work well.\n`dtext`'s Formatter main utility however comes from its `sformat` overload,\nwhich similarly to `formattedWrite` will output to a sink.\n\nThe Formatter uses a different format string than `std.format`:\nInstead of following the `printf` convention, which makes little sense in the presence\nof compiler-provided type information (as `[{s,sn}]format` use templates),\nthe simplest way to format an argument is to use `{}`, equivalent to `std.format`'s `%s`.\nDouble brace (\"{{\") is formatted as a single brace (\"{\"), positional arguments\n(`assert(format(\"{2} {1} {0}\", 1, 2, 3) == \"3 2 1\")`), width, and other options are available.\n\nFor more details, read [the module's extensive documentation](./source/dtext/format/Formatter.d).\n\n## Logger\n\nLike its Formatter, Dtext's Logger was built for real-time application.\nAs a result, message formatting takes place in a buffer (1024 chars by default, configurable)\nusing `snformat` and does not cause per-call invocation,\nunless the arguments or `Appender` allocate.\n\n`Logger` is a `class`, and each instance must have a name and belong to a `Hierarchy`.\nA `Hierarchy` is built the same way as a module hierarchy is, using dot (`.`) as delimiter.\n\nThe common idiom that was used with Loggers was:\n```D\nmodule some.awesome.project;\n\nimport dtext.log.Logger;\n\nprivate Logger log;\n\nstatic this ()\n{\n    log = Log.lookup(__MODULE__);\n}\n\nvoid main ()\n{\n    log.info(\"The answer is: {}\", 42);\n}\n```\n\nIn the above example, the first call to `Log.lookup` in the thread will allocate a new `Logger`,\nsubsequent calls will return the alread-instantiated `Logger`. Hierarchies are thread-local.\nLooking up a parent is possible (e.g. `Log.lookup(\"some.awesome\")`), and some configurations / operations\ncan be set to propagate to children (e.g. e.g. adding an `Appender` or setting a log level).\n\nThe root logger of the hierarchy is accessible via `Log.root`.\n\n### Layout \u0026 Appenders\n\n`Logger`s work in combination with two other classes: `Appender` and `Layout`.\n\nAn `Appender` defines *where* an event will go: this can be a file, the console,\n`syslog`, or any custom logic (e.g. the [AppendSterrStdout appender](./source/dtext/log/AppendStderrStdout.d)\nwill append to `stdout` below a certain level, and to `stderr` afterwards).\nA `Logger` can have multiple `Appender` (e.g. a `ConsoleAppender` and `FileAppender` are common),\nand `Appender` can be set to propagate when added to parents. \n\n`Layout` define how the messages will be printed. The most basic layout, `LayoutSimple`,\nwill just print the event's message, but `log` calls also include the `Level` at which\nthe message was emitted, the `time`, logger's name, etc...\n\n### Log levels\n\nLoggers have 7 normal log levels: `Debug`, `Trace`, `Verbose`, `Info`, `Warn`, `Error`, `Fatal`,\nin that order of importance. A special `None` value exists in `ILogger.Level` to disable any logging.\nThe `dtext.log.ILogger : ILogger.Level` is aliased as `dtext.log.Logger : Level`.\n\nEach log level has a corresponding lowercase function: `Logger.info`, `Logger.fatal`, etc...\nDue to `Debug` being a keyword, the matching function is `Logger.dbg`.\nProviding a log level at runtime can be done via `Logger.format(loglevel, format, args)`.\n\nIf a `Logger` is `enabled` for a certain level, messages of a higher levels will be emitted,\nbut messages for a lower level will be discarded without being formatted.\nFor example, for a `Logger` that is enabled for `Verbose` level,\ncalling `log.trace` will be  a no-op.\n\nThe default `Level` is `Level.Info`.\n\n### Limitations\n\nThe Formatter is currently not CTFE-able, not does it support passing a `FormatSpec`-like\nstruct to a `toString` method.\n\nThe `Logger` and `Formatter` alike are not attributes-friendly, and currently will not\nplay along well with them. As a compromise, `@safe` currently works,\nalthough it wrongly apply `@trusted` to the user-provided arguments.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeod24%2Fdtext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeod24%2Fdtext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeod24%2Fdtext/lists"}