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:
string
representing the scope of the logger. It is prepended between {}
before each message. If it is null
the scope will not be printed.true
, the debug messages will be printed.object
of type Palette
representing the colours used by the logger.Palette parameters:
object
of PaletteDefinitions
type that defines the colours for the primary part of a message, namely the [TAG]
and an eventual {SCOPE}
.object
of PaletteDefinitions
type that defines the colours for the secondary part of a message, namely the message passed to the logger function.PaletteDefinitions:
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'
)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'
)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'
)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'
)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] |{SCOPE}| message |object|
, where |word|
is optional.[SUCCESS] |{SCOPE}| message |object|
, where |word|
is optional.[DEBUG] |{SCOPE}| message |object|
, where |word|
is optional.[WARNING] |{SCOPE}| message |object|
, where |word|
is optional.[ERROR] |{SCOPE}| message |object|
, where |word|
is optional.n
empty lines. The default value of n
is 1
.n
hr lines, coloured with color
and constituted by symbol
characters. THe default value of n
is 1
, the default colour is 'white'
and the default symbol is '-'
.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
├── package.json
├── pnpm-lock.yaml
├─> 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
├── tsconfig.test.json
├── typedoc.cjs
├── typedoc.dev.cjs
└── vitest.config.ts
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 vitest run
.
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.