Skip to content

Instantly share code, notes, and snippets.

@kinchungwong
Last active March 3, 2019 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6 to your computer and use it in GitHub Desktop.
Save kinchungwong/ec25bc1eba99142e0be4509b0f67d0c6 to your computer and use it in GitHub Desktop.
LogTagManager behavior as-if specification

LogTagManager behavior as-if specification


Applies to:


About this document

This document is an attempt to specify the behavior of LogTagManager by way of a "model implementation" (i.e. the behavior shall match this model implementation) in order to remove bugs caused by relative order of log tag registration and log level config application.

Some of the bugs are exposed in the test cases added here.


About optimizations and/or shortcuts

Optimizations and/or shortcuts, whether explicitly mentioned or not, are allowed as long as the overall behavior is the same as the unoptimized behavior documented here.

Some optimization opportunities are mentioned here. However, these are not part of the behavior specification. The implementation shall match the behavior specification regardless of these optimization opportunities.


Pass 1

  • Pass 1 is executed if a "fullname" is specified for any command.

Step 1-1

  • For "fullname", ensure a table slot exists.
  • Assign or retrieve the unique ID for "fullname".
  • Optional optimization check.
    • If the table slot for "fullname" already exists, skip steps 1-2 and 1-3.

Step 1-2

  • For "firstPart", ensure a table slot exists.
  • For "firstPart", ensure the member list in the table slot contains the unique ID for "fullname".

Step 1-3

  • For each "anyPart", ensure a table slot exists.
  • For each "anyPart", ensure the member list in the table slot contains the unique ID for "fullname".

Pass 2

  • Pass 2 is executed if the caller specifies a log tag pointer with the command.

Step 2-1

  • For "fullname", compare log tag pointer contained in the table slot with the caller-specified log tag pointer.
  • If the log tag pointer is different, update the table slot.
  • Optional optimization check.
    • If the log tag pointer is the same, skip steps 2-2 and 2-3.

Step 2-2

  • For "firstPart", find the entry in the member list in the table slot.
  • Compare the log tag pointer contained in the member list with the caller-specified log tag pointer.
  • If the log tag pointer is different, update the pointer in the member list.

Step 2-3

  • For each "anyPart", find the entry in the member list in the table slot.
  • Compare the log tag pointer contained in the member list with the caller-specified log tag pointer.
  • If the log tag pointer is different, update the pointer in the member list.

Pass 3

  • Pass 3 is executed if the caller specifies a log level to be configured and cached.

Step 3-1

  • Step 3-1 is executed if the caller specifies that the log level is to be configured for "fullname".
  • Find the table slot for "fullname".
  • Update the table slot with the log level, and mark the log level config flag as "valid".

Step 3-2

  • Step 3-2 is executed if the caller specifies that the log level is to be configured for "firstPart".
  • Find the table slot for "firstPart".
    • Note that the member list for "firstPart" is not accessed within this step.
  • Updates the table slot with the log level, and mark the log level config flag as "valid".

Step 3-3

  • Step 3-2 is executed if the caller specifies that the log level is to be configured for one specific "anyPart".
  • Find the table slot for "anyPart".
    • Note that the member list for "anyPart" is not accessed within this step.
  • Updates the table slot with the log level, and mark the log level config flag as "valid".

Pass 4

  • Pass 4 is executed if it is a "sync" command, and if a "fullname" is given.
  • Remark. Notice that "anyPart" is examined in step 4-3 whereas "firstPart" is examined in step 4-4.
    • This may appear as a reversal of the order of examination compared to other passes, but this reversal is necessary to achieve the desired order of precedence when multiple log level configurations are found applicable to the same log tag.

Step 4-1

  • If it is a "sync" command for all log tags ever registered (that is, for all "fullname" contained in the table), apply steps 4-2 to 4-4 for each "fullname" in the table.

Step 4-2

  • For "fullname", find the table slot.
  • If a log level is configured with that table slot, AND if a log tag pointer is also configured with that table slot,
    • The log level is copied into the log tag.
    • The steps 4-3 to ... are skipped.

Step 4-3

[[TODO]]

Step 4-4

[[TODO]]


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment