Skip to content

Commit

Permalink
Add donation button and rotating file example
Browse files Browse the repository at this point in the history
  • Loading branch information
terehov committed Aug 18, 2022
1 parent 3b47ff2 commit 9c57b47
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 0 deletions.
30 changes: 30 additions & 0 deletions example/rotating-file/index.ts
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" });
153 changes: 153 additions & 0 deletions example/rotating-file/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions example/rotating-file/package.json
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"
}
]
}
5 changes: 5 additions & 0 deletions example/rotating-file/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"types": ["node"]
}
}

0 comments on commit 9c57b47

Please sign in to comment.