bare-file-logger 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/index.d.ts +9 -1
- package/index.js +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,21 @@ const log = new FileLog('console.log')
|
|
|
12
12
|
log.info('Hello %s', 'world!')
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## API
|
|
16
|
+
|
|
17
|
+
#### `const log = new FileLog(path[, options])`
|
|
18
|
+
|
|
19
|
+
Options include:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
options = {
|
|
23
|
+
// Maximum allowed byte size of the log file. This is a hint and not a hard
|
|
24
|
+
// limit; the logger will do its best to keep the file size within the limit,
|
|
25
|
+
// but provides no guarantees.
|
|
26
|
+
maxSize: 0
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
15
30
|
## License
|
|
16
31
|
|
|
17
32
|
Apache-2.0
|
package/index.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import Log from 'bare-logger'
|
|
2
2
|
|
|
3
|
+
interface FileLogOptions {
|
|
4
|
+
maxSize?: number
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
interface FileLog extends Log, Disposable {
|
|
4
8
|
append(label: string, ...data: unknown[]): void
|
|
5
9
|
close(): void
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
declare class FileLog {
|
|
9
|
-
constructor()
|
|
13
|
+
constructor(path: string, options?: FileLogOptions)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare namespace FileLog {
|
|
17
|
+
export { FileLogOptions }
|
|
10
18
|
}
|
|
11
19
|
|
|
12
20
|
export = FileLog
|
package/index.js
CHANGED
|
@@ -2,10 +2,18 @@ const Log = require('bare-logger')
|
|
|
2
2
|
const fs = require('bare-fs')
|
|
3
3
|
|
|
4
4
|
module.exports = class FileLog extends Log {
|
|
5
|
-
constructor(path) {
|
|
5
|
+
constructor(path, opts = {}) {
|
|
6
|
+
const { maxSize = 0 } = opts
|
|
7
|
+
|
|
6
8
|
super({ colors: false })
|
|
7
9
|
|
|
8
|
-
this.
|
|
10
|
+
this._path = path
|
|
11
|
+
this._maxSize = maxSize
|
|
12
|
+
this._fd = fs.openSync(this._path, 'a+')
|
|
13
|
+
|
|
14
|
+
if (this._maxSize > 0 && fs.fstatSync(this._fd).size > this._maxSize) {
|
|
15
|
+
this.clear()
|
|
16
|
+
}
|
|
9
17
|
}
|
|
10
18
|
|
|
11
19
|
append(label, ...data) {
|
|
@@ -37,6 +45,8 @@ module.exports = class FileLog extends Log {
|
|
|
37
45
|
|
|
38
46
|
clear() {
|
|
39
47
|
fs.ftruncateSync(this._fd)
|
|
48
|
+
fs.closeSync(this._fd)
|
|
49
|
+
this._fd = fs.openSync(this._path, 'a+')
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
close() {
|