A beautiful nodejs logger.
To install euberlog, run:
$ npm install euberlog
const { Logger } = require('euberlog');
const logger = new Logger();
logger.info('Informazione');
logger.success('Successo!!!');
logger.debug('Debug');
logger.warning('Warning!!');
logger.error('Errore');
logger.info('My car is:', { constructor: 'Toyota', model: 'Yaris', year: 2004 });
There is a default export consisting in an instance of Logger
with default options
const logger = require('euberlog').default;
logger.info('Informazione');
logger.success('Successo!!!');
logger.debug('Debug');
logger.warning('Warning!!');
logger.error('Errore');
logger.info('My car is:', { constructor: 'Toyota', model: 'Yaris', year: 2004 });
const { Logger } = require('euberlog');
const logger = new Logger();
// Prints one line of '-'
logger.hr();
// Prints two empty lines
logger.br(2);
logger.info('My name is Eugenio');
// Prints two empty lines
logger.br(2);
// Prints five lines of red '*'
logger.hr(5, 'red', '*');
const { Logger } = require('euberlog');
const logger = new Logger('MAIN');
// Adds {MAIN} before the message
logger.info('Informazione');
logger.success('Successo!!!');
logger.error('The error is:', new Error('Errore'));
const { Logger } = require('euberlog');
const logger = new Logger({
scope: 'MYSCOPE',
debug: false, // Hides the debug logs
palette: { // Overrides the default colour palette
primary: {
info: 'orange',
success: '(146,133,255)'
},
secondary: {
info: '#ffd485',
success: 'blue'
}
}
});
logger.info('Informazione');
logger.success('Successo!!!');
logger.debug('This is not shown');
The documentation site is: euberlog documentation
The documentation for development site is: euberlog dev documentation
The logger class, its instances will be the euber loggers.
Syntax:
const logger = new Logger(options);
Options:
The options parameter is a string
or a Options
object. If it is a string, it like passing an Options
object with only the property scope
with that string as value.
Options parameters:
- scope: Optional. A
string
representing the scope of the logger. It is prepended between{}
before each message. If it isnull
the scope will not be printed. - debug: Optional. If
true
, the debug messages will be printed. - palette: Optional. An
object
of typePalette
representing the colours used by the logger.
Palette parameters:
- primary: Optional. An
object
ofPaletteDefinitions
type that defines the colours for the primary part of a message, namely the[TAG]
and an eventual{SCOPE}
. - secondary: Optional. An
object
ofPaletteDefinitions
type that defines the colours for the secondary part of a message, namely the message passed to the logger function.
PaletteDefinitions:
- info: The colour for the info logs. Note: the colour can be a valid
chalk
colour (such as'white'
), an hex colour (such as'#FFFFFF'
), an RGB colour (such as'(255,255,255)'
) or a css keyword (such as'orange'
) - success: The colour for the success logs. Note: the colour can be a valid
chalk
colour (such as'white'
), an hex colour (such as'#FFFFFF'
), an RGB colour (such as'(255,255,255)'
) or a css keyword (such as'orange'
) - debug: The colour for the debug logs. Note: the colour can be a valid
chalk
colour (such as'white'
), an hex colour (such as'#FFFFFF'
), an RGB colour (such as'(255,255,255)'
) or a css keyword (such as'orange'
) - warning: The colour for the warning logs. Note: the colour can be a valid
chalk
colour (such as'white'
), an hex colour (such as'#FFFFFF'
), an RGB colour (such as'(255,255,255)'
) or a css keyword (such as'orange'
) - error: The colour for the error logs. Note: the colour can be a valid
chalk
colour (such as'white'
), an hex colour (such as'#FFFFFF'
), an RGB colour (such as'(255,255,255)'
) or a css keyword (such as'orange'
)
Note: the default_options are:
const DEFAULT_OPTIONS = {
palette: {
primary: {
info: 'blue',
success: 'green',
debug: 'gray',
warning: 'yellow',
error: 'red'
},
secondary: {
info: '#81A2BE',
success: '#B5BD68',
debug: '#C5C8C6',
warning: '#F0C674',
error: '#CC6666'
}
},
debug: true,
scope: null
};
Methods:
- info(message: string, object?: any): void: Logs an info message. The format is
[INFO] |{SCOPE}| message |object|
, where|word|
is optional. - success(message: string, object?: any): void: Logs an success message. The format is
[SUCCESS] |{SCOPE}| message |object|
, where|word|
is optional. - debug(message: string, object?: any): void: Logs an debug message. The format is
[DEBUG] |{SCOPE}| message |object|
, where|word|
is optional. - warning(message: string, object?: any): void: Logs an warning message. The format is
[WARNING] |{SCOPE}| message |object|
, where|word|
is optional. - error(message: string, object?: any): void: Logs an error message. The format is
[ERROR] |{SCOPE}| message |object|
, where|word|
is optional. - br(n?: number): void: Logs
n
empty lines. The default value ofn
is1
. - hr(n?: number, color?: string, symbol: string): void: Logs
n
hr lines, coloured withcolor
and constituted bysymbol
characters. THe default value ofn
is1
, the default colour is'white'
and the default symbol is'-'
. - setOptions(options?: Options | string): void: It changes the options of the logger instance. It is almost as using the class constructor, with the difference that a new instance will not be created.
There is a default export consisting in an instance of Logger
with default options
Made with dree
euberlog
├── .eslintignore
├── .eslintrc.cjs
├─> .github
│ └─> workflows
│ ├── build.yml
│ ├── dree.yml
│ ├── lint.yml
│ └── test.yml
├── .gitignore
├── .prettierrc.cjs
├── .release-it.json
├── CHANGELOG.md
├── LICENSE
├── README.md
├── babel.config.cjs
├── build.mjs
├─> docs
│ ├── .gitignore
│ ├─> assets
│ │ ├── br_and_hr.png
│ │ ├── simple.png
│ │ ├── with_options.png
│ │ └── with_scope.png
│ └─> tree
│ └── dree.config.json
├── jest.config.ts
├── package-lock.json
├── package.json
├─> source
│ ├── index.ts
│ ├── tsconfig.json
│ ├─> types
│ │ ├─> deep-partial
│ │ │ └── index.ts
│ │ ├── index.ts
│ │ ├─> options
│ │ │ └── index.ts
│ │ └─> palette
│ │ └── index.ts
│ └─> utils
│ ├── colour.ts
│ ├── logger.ts
│ └── options.ts
├─> test
│ ├── .eslintrc.cjs
│ ├─> suites
│ │ ├─> colour
│ │ │ └── colour.test.ts
│ │ ├─> handleOptions
│ │ │ └── handleOptions.test.ts
│ │ └─> logger
│ │ ├─> constructor
│ │ │ └── constructor.test.ts
│ │ ├─> defaultInstance
│ │ │ └── defaultInstance.test.ts
│ │ ├─> logs
│ │ │ ├─> noDebug
│ │ │ │ ├─> debug
│ │ │ │ │ └── debug.test.ts
│ │ │ │ ├─> error
│ │ │ │ │ └── error.test.ts
│ │ │ │ ├─> info
│ │ │ │ │ └── info.test.ts
│ │ │ │ ├─> success
│ │ │ │ │ └── success.test.ts
│ │ │ │ └─> warning
│ │ │ │ └── warning.test.ts
│ │ │ ├─> scoped
│ │ │ │ ├─> debug
│ │ │ │ │ └── debug.test.ts
│ │ │ │ ├─> error
│ │ │ │ │ └── error.test.ts
│ │ │ │ ├─> info
│ │ │ │ │ └── info.test.ts
│ │ │ │ ├─> success
│ │ │ │ │ └── success.test.ts
│ │ │ │ └─> warning
│ │ │ │ └── warning.test.ts
│ │ │ ├─> simple
│ │ │ │ ├─> debug
│ │ │ │ │ └── debug.test.ts
│ │ │ │ ├─> error
│ │ │ │ │ └── error.test.ts
│ │ │ │ ├─> info
│ │ │ │ │ └── info.test.ts
│ │ │ │ ├─> success
│ │ │ │ │ └── success.test.ts
│ │ │ │ └─> warning
│ │ │ │ └── warning.test.ts
│ │ │ └─> specials
│ │ │ └── specials.test.ts
│ │ └─> setOptions
│ │ └── setOptions.test.ts
│ └─> utils
│ └── getDefaultOptions.ts
├── tsconfig.json
├── typedoc.cjs
└── typedoc.dev.cjs
To build the module make sure you have the dev dependencies installed.
The project is written in Typescript
, bundled with EsBuild
and linted with ESLint
.
In order to lint the code:
$ npm run lint
In order to lint and fix the code:
$ npm run lint:fix
There are also the :source
and :test
suffix after lint
in order to lint only the source code or the test code.
To transpile both the source and the test code:
$ npm run transpile:all
The source
and the test
folders will be transpiled in the dist
folder. Also the type declarations
will be generated.
To transpile only the source code:
$ npm run transpile:source
The source
folder will be transpiled in the dist
folder. Also the type declarations
will be generated.
After having transpiled the code, run:
$ npm test
in order to run the tests with jest
.
If a coverage report is to be generated, run:
$ npm run cover:generate
The bundler bundles both a commonjs
and an esm
version of the module. Also a dts
file is generated, via dts-bundle-generator
.
$ npm run bundle
The source
folder will be compiled in the bundled
folder. It will contain the bundled index.js
, index.esm.js
and index.d.ts
files.
Note: since chalk
is only an esm, for the commonjs version it is bundled within the module itself.