npm.io
1.3.0 • Published 7 years ago

@tne/logger

Licence
MIT
Version
1.3.0
Deps
5
Size
15 kB
Vulns
2
Weekly
0
DeprecatedThis package is deprecated

@tne/logger

A basic logger for Node.js applications, completely written with typescript, is not only the basic logger for the entire @tne platform, since being completely decoupled from tne is free to use for any other application Node.js

Menu

Installation

@tne/logger
interfaces

Back to Menu

Installation

You can install through the node package managers:

NPM
$ npm i -S @tne/logger
Yarn
$ yarn add @tne/logger

Back to Menu

@tne/logger

@tne/logger is the main library which is responsible for making 'winston' coverage and standardizing the use for @tne. @tne/logger

Example basic usage

just create an instance without providing arguments

import { TneLogger } from '@tne/logger';

// create a simple console logger
const logger = new TneLogger;

logger.info('hello!')	// outputs-> [timestamp] info: hello!
logger.info('message 1537574380254');	// outputs -> [timestamp] info: message 1537574380254
logger.warn('message 1537574380254');	// outputs -> [timestamp] warn: message 1537574380254
logger.error('message 1537574380254');	// outputs -> [timestamp] error: message 1537574380254
Example usage with file logger

provide a config object that implements the ISettings interface

import { TneLogger } from '@tne/logger';

// ISettings
const config = {
	fileCfg: {
		logsPath: process.pwd() + '/logs',
		logFile: 'someFileName',
	}
};


// create a console logger with file persistence
const logger = new TneLogger(config);

logger.info('hello!')	// outputs-> [timestamp] info: hello!
logger.info('message 1537574380254');	// outputs -> [timestamp] info: message 1537574380254
logger.warn('message 1537574380254');	// outputs -> [timestamp] warn: message 1537574380254
logger.error('message 1537574380254');	// outputs -> [timestamp] error: message 1537574380254

The above code will also dump logs to a several logs files placed on path specified by logsPath argument.


Back to Menu

Interfaces

The interfaces that this library provides and that are described here provide help to the developer that will consume this library to build incredible web applications.

Constraints

The interfaces mentioned in this section will be importable only if you are developing your web application with typescript.


Back to Menu

ISettings

Used as a constructor argument for TneLogger class.

Parameters
Param Type Required? Description
level string false winston logging level
fileCfg IFileSettings false IFileSettings object
customTransports Transport[] false A custom winston-transport Array.

IFileSettings Back to Menu

IFileSettings

Used as a nested config on constructor argument for TneLogger class.

When you provide this config object a log file will be created per day.

Parameters
Param Type Required? Description
logsPath string true valid path where TneLogger will create the log files.
logFile string false filename for the further log files default: 'log.log'
datePattern string false data pattern for the further log files default: 'YYYMMDD'

Back to Menu

Keywords