mirror of https://github.com/adamdruppe/arsd.git
make it work again
This commit is contained in:
parent
eb9abb180e
commit
bdb7372488
65
core.d
65
core.d
|
@ -271,6 +271,16 @@ auto ref T castTo(T, S)(auto ref S v) {
|
|||
///
|
||||
alias typeCast = castTo;
|
||||
|
||||
/++
|
||||
Treats the memory of one variable as if it is the type of another variable.
|
||||
|
||||
History:
|
||||
Added January 20, 2025
|
||||
+/
|
||||
ref T reinterpretCast(T, V)(return ref V value) @system {
|
||||
return *cast(T*)& value;
|
||||
}
|
||||
|
||||
/++
|
||||
Does math as a 64 bit number, but saturates at int.min and int.max when converting back to a 32 bit int.
|
||||
|
||||
|
@ -8040,6 +8050,9 @@ unittest {
|
|||
================
|
||||
+/
|
||||
/++
|
||||
DO NOT USE THIS YET IT IS NOT FUNCTIONAL NOR STABLE
|
||||
|
||||
|
||||
The arsd.core logger works differently than many in that it works as a ring buffer of objects that are consumed (or missed; buffer overruns are possible) by a different thread instead of as strings written to some file.
|
||||
|
||||
A library (or an application) defines a log source. They write to this source.
|
||||
|
@ -8059,24 +8072,66 @@ unittest {
|
|||
|
||||
Examples:
|
||||
---
|
||||
mixin LoggerOf!X mylogger;
|
||||
auto logger = new shared LoggerOf!GenericEmbeddableInterpolatedSequence;
|
||||
|
||||
mylogger.log(i"$this heartbeat"); // creates an ad-hoc log message
|
||||
mylogger.info(i"$this heartbeat");
|
||||
---
|
||||
|
||||
History:
|
||||
Added May 27, 2024
|
||||
+/
|
||||
mixin template LoggerOf(T) {
|
||||
void log(LogLevel l, T message) {
|
||||
|
||||
Not actually implemented until February 6, 2025, when it changed from mixin template to class.
|
||||
+/
|
||||
class LoggerOf(T, size_t bufferSize = 16) {
|
||||
private LoggedMessage!T[bufferSize] ring;
|
||||
private uint writeBufferPosition;
|
||||
|
||||
void log(LoggedMessage!T message) shared {
|
||||
synchronized(this) {
|
||||
auto unshared = cast() this;
|
||||
unshared.ring[writeBufferPosition] = message;
|
||||
unshared.writeBufferPosition += 1;
|
||||
|
||||
// import std.stdio; std.stdio.writeln(message);
|
||||
}
|
||||
}
|
||||
|
||||
void log(LogLevel level, T message, SourceLocation sourceLocation = SourceLocation(__FILE__, __LINE__)) shared {
|
||||
log(LoggedMessage!T(LogLevel.Info, sourceLocation, 0, message));
|
||||
}
|
||||
|
||||
void info(T message, SourceLocation sourceLocation = SourceLocation(__FILE__, __LINE__)) shared {
|
||||
log(LogLevel.Info, message, sourceLocation);
|
||||
}
|
||||
}
|
||||
|
||||
struct SourceLocation {
|
||||
string file;
|
||||
size_t line;
|
||||
}
|
||||
|
||||
struct LoggedMessage(T) {
|
||||
LogLevel level;
|
||||
SourceLocation sourceLocation;
|
||||
ulong timestamp;
|
||||
T message;
|
||||
|
||||
// process id?
|
||||
// thread id?
|
||||
// callstack?
|
||||
}
|
||||
|
||||
//mixin LoggerOf!GenericEmbeddableInterpolatedSequence GeisLogger;
|
||||
|
||||
enum LogLevel {
|
||||
Info
|
||||
}
|
||||
|
||||
unittest {
|
||||
auto logger = new shared LoggerOf!GenericEmbeddableInterpolatedSequence;
|
||||
logger.info(GenericEmbeddableInterpolatedSequence(i"hello world"));
|
||||
}
|
||||
|
||||
/+
|
||||
=====================
|
||||
TRANSLATION FRAMEWORK
|
||||
|
|
|
@ -710,9 +710,9 @@ struct Terminal {
|
|||
version(Posix) {
|
||||
private int fdOut;
|
||||
private int fdIn;
|
||||
private int[] delegate() getSizeOverride;
|
||||
void delegate(in void[]) _writeDelegate; // used to override the unix write() system call, set it magically
|
||||
}
|
||||
private int[] delegate() getSizeOverride;
|
||||
|
||||
bool terminalInFamily(string[] terms...) {
|
||||
version(Win32Console) if(UseWin32Console)
|
||||
|
|
Loading…
Reference in New Issue