umang_logger_module
v1.1.4
Published
Simple winston based logger that produces coloured logs on the console and provides masking of PII Fields.
Downloads
5
Readme
Umang_Logger_Module
Simple winston based logging module with colured logs and also the functionality to handle masking of PII data. []
Features
Standard logging based on environment, example: Production, Staging etc. using ‘winston’ module
Various log levels supported – info, warn, verbose, error, debug
Configuration for logging based on severity of log.
For prod and different environment
Different colours for levels of log using ‘chalk’ module.
Configuration for saving the logs in file.
Configurable log file path from home directory.
Identifying PII in simple string using regexes, example: card, phone, email.
Configurable file for identifying PII using fieldname in JSON
Masking identified PII using node module ‘maskdata’
Configurable file for how we want to mask the PII example by using * or x or $ etc.
Configurable file for how many characters needs to be masked at the start or end of the PII
Identifying PII using Regexes:
Email:
Emails are picked from the given string using the regex provided in the table below
Match function is used to return the array of emails fetched in this case which is masked further.
Phone:
- Match function is used to return the array of phone numbers fetched in this case which is masked further
- Regex used for phone picks up phone number in the following formats:
- +1 717-716-7676
- 7177167676
- (717) 716-7676
- +917177167676
- +91 7177167676
- +91-7177167676
- 717-716-7676
Card:
- Regex used for card number picks up card in the following formats:
- 4111111111111111
- 4111-1111-1111-1111
- 4111 1111 1111 1111
- 378282246310005
- 3782-822463-10005
- 3782 822463 10005
- These picked up numbers are validated by a node module ‘node-luhn’.
- If the card number picked is a valid card number, then the masking is done otherwise no masking is done.
Identifying PII using fieldnames in JSON:
We can mask the PII if we are provided with fieldname of the data that needs to be masked using the node module ‘maskdata’.
Installation and set up
Installing umang_logger_module
Link: https://www.npmjs.com/package/umang_logger_module Command: npm i umang_logger_module
Creating pii-fields.json file
- More fileds can be added or removed as per the masking requirement.
{ "gender": "", "age": "", "name": "", "email": "", "phone": "", "cc":"", "_id":"", "access_token":"" }
Creating maskConfig.json file
PII identified by regexes will be masked in the following fashion.
“maskWith”: Character to mask the data.
“unmaskedStartCharacters”: If the starting 'n' characters needs to be unmasked. Should be positive Integer
“unmaskedEndCharacters”: If the ending 'n' characters needs to be unmasked. Should be positive Integer
“maskAtTheRate”: If '@' needs to be masked. Default value is false (Will not mask). Should be Boolean
“maxMaskedCharactersBeforeAtTheRate”: To limit the *s in the response (Max *s before '@'). Should be positive Integer
“maxMaskedCharactersAfterAtTheRate”: To limit the *s in the response (Max *s after '@'). Should be positive Integer
{ "email": { "maskWith" : "x", "unmaskedStartCharacters" : "1", "unmaskedEndCharacters" : "2", "maskAtTheRate ": "false", "maxMaskedCharactersBeforeAtTheRate" : "10", "maxMaskedCharactersAfterAtTheRate" : "10" }, "phone": { "maskWith" : "x", "unmaskedStartDigits" : "5", "unmaskedEndDigits" : "1" }, "card": { "maskWith" : "x", "unmaskedStartDigits" : "4", "unmaskedEndDigits" : "1" }, "json": { "maskWith" : "x" }
} ```
Addition in .env file
#Environment identifier (setting default environment)
NODE_ENV="dev"
#identifier for choosing masking or no masking (default is set as true)
MASKING_FOR_PII_FLAG="true"
PII File Name
- PII_FILENAME = "pii-fields.json"
Log File Name (mandatory field)
- LOG_FILENAME = "master_"
Log File Path (mandatory field)
- LOG_FILEPATH = ''
identifier for saving in FILE (default is set as false)
- SAVE_IN_FILE = 'true'
Identifier for Log Level for current environment (default set to info)
- LOG_LEVEL = "debug"
Identifier for Log Level for production environment (default set to error)
- PRODUCTION_LOG_LEVEL = ‘error’