# Getting started

# Installation

npm install -g typescript
npm install @tsed/logger
npm install source-map-support
1
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

Will be procude 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

# 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
7
8