GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - eotechlabs/eo-logger: Isomorphic JavaScript logger based on Elastic Common Schema

BranchesTags
Open more actions menu

Latest commit

 

History

125 Commits
125 Commits

Folders and files

NameName
Last commit message
Last commit date
images
images
 
 
packages
packages
 
 
.gitignore
.gitignore
 
 
.npmrc
.npmrc
 
 
.prettierrc
.prettierrc
 
 
LICENSE
LICENSE
 
 
lerna.json
lerna.json
 
 
package.json
package.json
 
 
readme.md
readme.md
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

eo-logger

Isomorphic logger based on Elastic Common Schema

✨ Features:

  • Tiny <1KB size gzip
  • Works in Node.js and in Browser
  • Built-in Typescript support
  • Google Web Vitals and Elastic Common Schema under the hood

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

import { Logger } from 'eo-logger/dist/client/logger';

export const logger = new 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:

import { ECS, Transport } from 'eo-logger';
import { Logger } from 'eo-logger/dist/client/logger';

class MyTransport extends Transport {
  public send(message: ECS.Message): void {
    fetch('/frontend-logs', {
      method: 'post',
      body: JSON.stringify(message),
    });
  }
}

export const logger = new Logger({
  transport: new MyTransport(),
});

How to use with express

  1. Create api endpoint for collect logs
import * as express from 'express';

const app = express();
app.use(express.json());

app.post('/frontend-logs', (req, res) => {
  return res.status(200).send();
});
  1. Add @elastic/elasticsearch
yarn add @elastic/elasticsearch
  1. Create elasticsearch client and transport instance
import * as express from 'express';
import { Client } from '@elastic/elasticsearch';
import { Transport as ElkTransport } from 'eo-logger/dist/server/logger';

const app = express();
app.use(express.json());

app.post('/frontend-logs', (req, res) => {
  elkTransport.send(req.body);

  return res.status(200).send();
});

const elasticClient = new Client({ node: 'http://localhost:9200' });

const elkTransport = new ElkTransport({
  client: elasticClient,
  indexBase: 'frontend-logs',
  maxQueueSize: 5,
});

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

About

Isomorphic JavaScript logger based on Elastic Common Schema

Topics

ecselastic-common-schemaelasticsearchlogger

Resources

Readme
MIT license
Activity
Custom properties

Stars

21 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.