eo-logger
- Isomorphic logger based on Elastic Common Schema
- Elastic Common Schema typings out of the box
How to install
yarn add eo-logger
Or
npm install eo-logger --save
How to use in browser
For start using required to create instance of class Logger
; ;
Now you can import logger in any place of your application and use one of next methods
logger.error
- for errors
logger.debug
- for debug some information
logger.warning
- for warnings
logger.collectMetrics
- for collect performance metrics of your web application (this method available only for client logger)
By default logger transport just display ECS.Message
in console.
If you want to collect logs, you have to implement your own Transport
class.
Actually it is quite simple, look at example below:
;; ;
How to use with express
- Create api endpoint for collect logs
; ;app.useexpress.json; app.post'/frontend-logs',;
- Add
@elastic/elasticsearch
yarn add @elastic/elasticsearch
- Create elasticsearch client and transport instance
;;; ;app.useexpress.json; app.post'/frontend-logs',; ; ;
Advanced
Logger contains 3 main components:
- Context
- Transport
- Formatter
Client utilities
getPerformanceMetrics
- function returns object with performance metrics of page speed loading
Server utilities
parseUserAgent
- function returns ECS.UserAgent
object with information based on user-agent
string
parseGeo
- function return ECS.Geo
object with information based on ip string