Last active
January 12, 2024 18:35
-
-
Save rinchik/a9f6aa8ae1a5868bd68d9cf751d4bb96 to your computer and use it in GitHub Desktop.
Bitmask JavaScript Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logger() { | |
//MASKS | |
this.ADMIN = this.permissions.CAN_SEE_ERRORS | this.permissions.CAN_SEE_DEBUGS | this.permissions.CAN_SEE_INFOS; | |
this.SUPERUSER = this.permissions.CAN_SEE_DEBUGS | this.permissions.CAN_SEE_INFOS; | |
this.USER = this.permissions.CAN_SEE_INFOS; | |
} | |
// FLAGS | |
logger.prototype.permissions = { | |
CAN_SEE_ERRORS: 1, // 0001 | |
CAN_SEE_DEBUGS: 2, // 0010 | |
CAN_SEE_INFOS: 4, // 0100 | |
} | |
logger.prototype.setUserGroup = function(group) { | |
this.USER = group; | |
} | |
logger.prototype.error = function(errorMessage) { | |
if (this.USER & this.permissions.CAN_SEE_ERRORS) | |
console.log("%cERROR: " + errorMessage, "color: #FF033E; font-weight:bold;"); | |
} | |
logger.prototype.debug = function(debugMessage) { | |
if (this.USER & this.permissions.CAN_SEE_DEBUGS) | |
console.log("%cDEBUG: " + debugMessage, "color: #0000FF; font-weight:bold;"); | |
} | |
logger.prototype.info = function(infoMessage) { | |
if (this.USER & this.permissions.CAN_SEE_INFOS) | |
console.log("%cINFO: " + infoMessage, "color: #C8A2C8; font-weight:bold;"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment