# Getting started
# Installation
npm install -g typescript
npm install @tsed/logger
npm install source-map-support
1
2
3
2
3
# Quick start
Minimalist version:
import {$log} from "@tsed/logger";
$log.level = "debug";
$log.name = "APP";
$log.debug("Some debug messages");
1
2
3
4
5
2
3
4
5
Will be produce the following log output:
[2017-06-17 11:43:37.987] [DEBUG] [APP] - Some debug messages
1
# Create your own logger
import {Logger} from "@tsed/logger";
const logger = new Logger("loggerName");
logger.appenders
.set("std-log", {
type: "stdout",
levels: ["debug", "info", "trace"]
})
.set("error-log", {
type: "stderr",
levels: ["fatal", "error", "warn"],
layout: {
type: "pattern",
pattern: "%d %p %c %X{user} %m%n"
}
})
.set("all-log-file", {
type: "file",
filename: `${__dirname}/app.log`,
layout: {
type: "json",
separator: ","
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Shutdown
Shutdown return a Promise that will be resolved when logger has closed all appenders and finished writing log events. Use this when your programme exits to make sure all your logs are written to files, sockets are closed, etc.
import {Logger} from "@tsed/logger";
const logger = new Logger("loggerName");
logger.shutdown().then(() => {
console.log("Complete");
});
1
2
3
4
5
6
2
3
4
5
6
Last Updated: 10/26/2023, 6:30:07 AM
Other topics
- Console Appender
- File Appender
- Date Rolling File Appender
- Connect Appender
- Standard Out Appender
- Standard Error Appender
- Insight Appender
- LogEntries Appender
- LogStash HTTP Appender
- LogStash UDP Appender
- Loggly Appender
- RabbitMQ Appender
- Seq Appender
- Slack Appender
- SMTP Appender
- Basic layout
- Colored layout
- Dummy layout
- Message Pass-Through layout
- Object layout
- Json layout
- Pattern layout