bump package version to 1.0.1
[squeep-log-helper] / README.md
1 # @squeep/log-helper
2
3 Utilities for standardized logging.
4
5 ## API
6
7 - `fileScope(filepath, options)`
8 Returns a function which will decorate function names with some combination of the source file path, package name, and package version. If the filepath is `index.js`, it will be replaced by its containing directory. Defaults for what is included are determined by Squeep opinions on package layouts.
9
10 Example:
11
12 ```javascript
13 // Assuming this file is located at 'project/lib/subdir/code.js'
14 // Assuming project/package.json defines 'name' as 'project'
15 const { fileScope } = require('@squeep/log-helper');
16 const _fileScope = fileScope(__filename, { includeVersion: false });
17
18 function example() {
19 const _scope = _fileScope('example');
20 console.log(_scope); // Will show 'project:subdir/code:example'
21 }
22 ```
23
24 Options:
25 - `includePackage` Package name from `package.json`.
26 - `includeVersion` Package version from `package.json`. If this is `true`, `includePackage` will also become `true`.
27 - `includePath` The path to the file, relative to the `package.json` file.
28 - `leftTrim` How much of the beginning of the path to elide. (e.g. 3 would render `foo/bar` as `/bar`)
29 - `delimiter` Placed between fields, defaults to `:`.
30 - `prefix` A field included before the package name.
31
32 Defaults, based on directory existing in project:
33 | | `src` | `lib` | other |
34 |----------------|-------|-------|-------|
35 | includePackage | false | true | false |
36 | includeVersion | false | true | false |
37 | includePath | true | true | false |
38 | leftTrim | 4 | 4 | 0 |
39
40 If any errors are encountered while trying to determine the path or package metadata, the scope will be prefixed with a '?'.