-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add donation button and rotating file example
- Loading branch information
Showing
4 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Logger, ILogObject } from "tslog"; | ||
import { createStream } from "rotating-file-stream"; | ||
|
||
const stream = createStream("tslog.log", { | ||
size: "10M", // rotate every 10 MegaBytes written | ||
interval: "1d", // rotate daily | ||
compress: "gzip", // compress rotated files | ||
}); | ||
|
||
function logToTransport(logObject: ILogObject) { | ||
stream.write(JSON.stringify(logObject) + "\n"); | ||
} | ||
|
||
const logger: Logger = new Logger(); | ||
logger.attachTransport( | ||
{ | ||
silly: logToTransport, | ||
debug: logToTransport, | ||
trace: logToTransport, | ||
info: logToTransport, | ||
warn: logToTransport, | ||
error: logToTransport, | ||
fatal: logToTransport, | ||
}, | ||
"debug" | ||
); | ||
|
||
logger.debug("I am a debug log."); | ||
logger.info("I am an info log."); | ||
logger.warn("I am a warn log with a json object:", { foo: "bar" }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "rotating-file", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.ts", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "ts-node index" | ||
}, | ||
"keywords": [], | ||
"author": "Eugene <opensource@terehov.de> (http://fullstack.build)", | ||
"license": "ISC", | ||
"dependencies": { | ||
"rotating-file-stream": "^3.0.4", | ||
"ts-node": "^10.8.2", | ||
"tslog": "^3.3.3" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.0.3" | ||
}, | ||
"funding": [ | ||
{ | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/fullstack-build" | ||
}, | ||
{ | ||
"type" : "github", | ||
"url" : "https://github.com/sponsors/fullstack-build" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"types": ["node"] | ||
} | ||
} |