All Projects → ibitcy → eo-logger

ibitcy / eo-logger

Licence: MIT license
Isomorphic JavaScript logger based on Elastic Common Schema

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to eo-logger

studio-log
👻 A tiny JSON logger with emoji support
Stars: ✭ 39 (+85.71%)
Mutual labels:  logger
gocs
GameObject Component System for Unity
Stars: ✭ 102 (+385.71%)
Mutual labels:  ecs
django-cdk
A CDK library that provides high-level constructs for hosting Django applications on AWS
Stars: ✭ 31 (+47.62%)
Mutual labels:  ecs
beautiful logger
Yet another logger API in Java with beautiful features
Stars: ✭ 60 (+185.71%)
Mutual labels:  logger
fluent-forward-go
A high-performance Go client for Fluentd and Fluent Bit
Stars: ✭ 26 (+23.81%)
Mutual labels:  logger
ecs-mesh-workshop
This handy workshop help the customers to quickly launch ECS with service mesh support on top of mixed type of instance in all commercial regions (include China), and also provides hands-on tutorials with best practices. It can be customized easily as per need.
Stars: ✭ 17 (-19.05%)
Mutual labels:  ecs
Proglog
📝 Logs and progress bars manager for Python
Stars: ✭ 87 (+314.29%)
Mutual labels:  logger
ECS-Phyllotaxis
Learning ECS - 100k Cubes in Phyllotaxis pattern
Stars: ✭ 17 (-19.05%)
Mutual labels:  ecs
guzzle-log-middleware
A Guzzle middleware to log request and responses automatically
Stars: ✭ 61 (+190.48%)
Mutual labels:  logger
dry-logger
[WIP] Logging library
Stars: ✭ 16 (-23.81%)
Mutual labels:  logger
Simple-Log
dnkpp.github.io/Simple-Log/
Stars: ✭ 13 (-38.1%)
Mutual labels:  logger
uecs
Micro ECS
Stars: ✭ 30 (+42.86%)
Mutual labels:  ecs
ecs-ssh
Tool that shows you cluster, services, and tasks to SSH into a container instance
Stars: ✭ 43 (+104.76%)
Mutual labels:  ecs
liquibase-slf4j
Liquibase SLF4J Logger.
Stars: ✭ 42 (+100%)
Mutual labels:  logger
Smoke
A pure, flexible, extendable log library for Android.
Stars: ✭ 12 (-42.86%)
Mutual labels:  logger
ham-go
Amateur radio related code written in go
Stars: ✭ 24 (+14.29%)
Mutual labels:  logger
ecs
🐰 Entity Component System
Stars: ✭ 62 (+195.24%)
Mutual labels:  ecs
microservices-demo.github.io
The Microservices Demo website.
Stars: ✭ 65 (+209.52%)
Mutual labels:  ecs
container-demo
How can I manage microservices using ecs-cli?
Stars: ✭ 30 (+42.86%)
Mutual labels:  ecs
gdk-for-unity-blank-project
SpatialOS GDK for Unity Blank Project
Stars: ✭ 33 (+57.14%)
Mutual labels:  ecs

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].