elastic-search-rest-log
Dependency-less http methods for pure nodejs. The motive for this project was for have a simple logger with elastic search without depending on any driver o special software.
How to install
npm install --save elastic-search-rest-log
ElasticSearchRestLogger
Logger class
Options
- host: Url where the elastic search server is hosted. Default: localhost.
- port: port throught which the elastic search server is exposed. Default: 9200.
- logType: Used to create the index name. It's objective is to identify the project using the logger.
- logIndexTemplate: The template object used to create the Elastic Search template.
- logIndexTemplateName: Name for the template to be created on Elastic Search.
- consoleLogger: Enables a console logger that prints on the console in parallel to the Elastic Search logging. Default: True.
Methods
-
init(): Verifies that the index and the template for the logs exist
-
getIndexName(): Obtains the log index name. By default, it follows the following format
log-${this.logType}-${day}-${month}-${year}
, if it does not satisfy your requirements, this method should be overriden. -
verifyTemplateExists(): Verifies if the template exists. If not, it calls the createTemplate() method.
-
createTemplate(): Creates the elastic Search template.
-
verifyIndexExists(): Verifies if the index exists. If not, it calls the createIndex() method.
-
createIndex(): Creates the elastic Search index.
-
log(level, data): Makes a post call to create the log in elastic search. If data is a simple string, it will be included in the message property of the log. If not, it will merge data with the default logger object.
-
info(data): Alias for the log method with info as the log level.
-
warn(data): Alias for the log method with warn as the log level.
-
error(data): Alias for the log method with error as the log level.
Examples
Initialization
const ElasticSearchRestLogger = ; const logger = loggerOptions;logger
Output
If the passed to the log method was a string:
If the passed to the log method was :```json