Skip to content

Commit

Permalink
Debug-log functions to Context and Recorder, making it easier to repo…
Browse files Browse the repository at this point in the history
…rt issues.
  • Loading branch information
zorbathut committed Nov 6, 2024
1 parent eb8d9b5 commit 9da4324
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ All notable changes to this project will be documented in this file.

## [Unreleased]
### Added
* Added SetupDependsOnAttribute, which allows you to define ConfigErrors/PostLoad dependencies between Dec classes. This is a prototype and will probably change in the future.
* Added a general-purpose stable dag evaluator, which is exposed mostly because it's often convenient.
* Added Recorder.InputContext, which gives contextual diagnostic information useful for reporting Recorder issues.
* Added the ability to reference class objects contained within Decs. Right now the path generation works only for members, lists, and arrays; this will probably be improved later.
* SetupDependsOnAttribute, which allows you to define ConfigErrors/PostLoad dependencies between Dec classes. This is a prototype and will probably change in the future.
* A general-purpose stable dag evaluator, which is exposed mostly because it's often convenient.
* Recorder.InputContext, which gives contextual diagnostic information useful for reporting Recorder issues.
* The ability to reference class objects contained within Decs. Right now the path generation works only for members, lists, and arrays; this will probably be improved later.
* Debug-log functions to Context and Recorder, making it easier to report issues.

### Breaking
* Dec doesn't guarantee what order Decs are initialized in, and it still doesn't . . . but it was *pretty consistent*, and boy, did the above change seriously scramble the order they tend to get initialized in! If you have load dependencies, even if you don't realize that you do, don't be surprised if stuff breaks. Future versions of Dec might include a Dev Mode that intentionally randomizes load order (within the bounds of dependencies) to help catch these issues.
Expand Down
27 changes: 27 additions & 0 deletions src/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,38 @@ internal Context(string filename = null, System.Xml.Linq.XElement element = null
this.path = path;
}

/// <summary>
/// Returns the best guess at the path of this Record query.
/// </summary>
public string PathString()
{
return path?.Serialize() ?? "[unknown]";
}

/// <summary>
/// Post a proper Context-decorated message to the info log.
/// </summary>
public void Inf(string message)
{
Dbg.Inf($"{this}: {message}");
}

/// <summary>
/// Post a proper Context-decorated message to the warning log.
/// </summary>
public void Wrn(string message)
{
Dbg.Wrn($"{this}: {message}");
}

/// <summary>
/// Post a proper Context-decorated message to the error log.
/// </summary>
public void Err(string message)
{
Dbg.Err($"{this}: {message}");
}

public override string ToString()
{
if (this.element != null)
Expand Down
24 changes: 24 additions & 0 deletions src/Recorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,30 @@ internal IRecordable CreateRecordableFromFactory(Type type, string name, ReaderN
/// </summary>
public abstract Context Context { get; }

/// <summary>
/// Post a proper Context-decorated message to the info log.
/// </summary>
public void Inf(string message)
{
Context.Inf(message);
}

/// <summary>
/// Post a proper Context-decorated message to the warning log.
/// </summary>
public void Wrn(string message)
{
Context.Wrn(message);
}

/// <summary>
/// Post a proper Context-decorated message to the error log.
/// </summary>
public void Err(string message)
{
Context.Err(message);
}

/// <summary>
/// Serialize or deserialize a member of a class.
/// </summary>
Expand Down

0 comments on commit 9da4324

Please sign in to comment.