@squeep/log-helper v1.0.1
@squeep/log-helper
Utilities for standardized logging.
API
fileScope(filepath, options)Returns a function which will decorate function names with some combination of the source file path, package name, and package version. If the filepath isindex.js, it will be replaced by its containing directory. Defaults for what is included are determined by Squeep opinions on package layouts.Example:
// Assuming this file is located at 'project/lib/subdir/code.js' // Assuming project/package.json defines 'name' as 'project' const { fileScope } = require('@squeep/log-helper'); const _fileScope = fileScope(__filename, { includeVersion: false }); function example() { const _scope = _fileScope('example'); console.log(_scope); // Will show 'project:subdir/code:example' }Options:
includePackagePackage name frompackage.json.includeVersionPackage version frompackage.json. If this istrue,includePackagewill also becometrue.includePathThe path to the file, relative to thepackage.jsonfile.leftTrimHow much of the beginning of the path to elide. (e.g. 3 would renderfoo/baras/bar)delimiterPlaced between fields, defaults to:.prefixA field included before the package name.
Defaults, based on directory existing in project: | |
src|lib| other | |----------------|-------|-------|-------| | includePackage | false | true | false | | includeVersion | false | true | false | | includePath | true | true | false | | leftTrim | 4 | 4 | 0 |If any errors are encountered while trying to determine the path or package metadata, the scope will be prefixed with a '?'.