@squeep/log-helper
v1.0.1
Published
Simple helpers for standardized logging
Downloads
3
Readme
@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:
includePackage
Package name frompackage.json
.includeVersion
Package version frompackage.json
. If this istrue
,includePackage
will also becometrue
.includePath
The path to the file, relative to thepackage.json
file.leftTrim
How much of the beginning of the path to elide. (e.g. 3 would renderfoo/bar
as/bar
)delimiter
Placed between fields, defaults to:
.prefix
A 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 '?'.