@mpyw, pronounced as "mappy." Web Backend Developer/Engineer. Laravel Contributor.
More introduced in mpyw/laravel-packages.
More introduced in Repositories.
Save your browser console logs to AWS CloudWatch (Inspired by agea/console-cloud-watch)
License: MIT License
@mpyw, pronounced as "mappy." Web Backend Developer/Engineer. Laravel Contributor.
More introduced in mpyw/laravel-packages.
More introduced in Repositories.
First, thanks to share your work.
Could you have a function for each log level Error, Warn, Info, Debug, Trace mapped on console functions?
Can you put args to logs? When I use console.log('test', var) I get only message "test"
accessKeyId
, secretAccessKey
, region
and logGroupName
.setLevels()
and setInterval()
.install()
with more options: logStreamNameResolver
and messageFormatter
.enable()
, disable()
, mute()
and unmute()
.It's too stateful and has so complex interface.
import { CloudWatchLogsClient } from '@aws-sdk/client-cloudwatch-logs';
import { LoggerFactory, Channel } from 'cloudwatch-front-logger';
const client = new CloudwatchLogsClient({
credentials: {
accessKeyId: ...,
secretAccessKey: ...,
}
region: ...,
});
const factory = new LoggerFactory({
client,
logGroupName: ...,
logStreamNameResolver: ...,
messageFormatter: ...,
interval: ...,
muted: ...,
});
factory.addChannel(new Channel('error'));
factory.addChannel(new Channel('warn', {
// All parameters can be overridden here
client,
logGroupName: ...,
logStreamNameResolver: ...,
messageFormatter: ...,
interval: ...,
muted: ...,
));
const logger = factory.createLogger();
const channels = logger.channels(); // Return channel collection
channels.mute(); // Mute all channels
channels.get('error').mute(); // Mute all error channels
channels.get('error')[0].mute(); // Mute only single error channel
Or you can create using default channels.
const logger = new LoggerFactory({
client,
logGroupName: ...,
logStreamNameResolver: ...,
messageFormatter: ...,
interval: ...,
muted: ...,
}).setDefaultChannels();
I follow your instructions but I could not change at all the log stream name.
try several approaches but I don't know what I'm doing wrong.
I'm using vuejs and trying to use in app file.
First Approach, using the same code as you suggest
const logger = new Logger(process.env.VUE_APP_CLOUDWATCH_ACCESS_KEY, process.env.VUE_APP_CLOUDWATCH_SECRET_ACCESS_KEY, 'eu-west-2', process.env.VUE_APP_CLOUDWATCH_LOG_GROUP);
logger.install({
async logStreamNameResolver() {
const fp = await FingerprintJS.load()
const { visitorId } = await fp.get()
return visitorId
},
});
The second Approach was to return a string
const logger = new Logger(process.env.VUE_APP_CLOUDWATCH_ACCESS_KEY, process.env.VUE_APP_CLOUDWATCH_SECRET_ACCESS_KEY, 'eu-west-2', process.env.VUE_APP_CLOUDWATCH_LOG_GROUP);
logger.install({
logStreamNameResolver() {
return 'test';
},
});
It seems the function is not replaced somehow. Am I missing something?
i had used cloudwatch-front-logger package for Ionic/angular
It works perfectly and send logs to cloudwatch but sometimes it return custom errors like
message: "Log events in a single PutLogEvents request must be in chronological order."
message: "The given sequenceToken is invalid. The next expected sequenceToken is: 49624933166923263368354481303481754674738400532447100946"
Is there any way to avoid that?
It hits below api
https://logs.eu-west-1.amazonaws.com/
Payload ->
logEvents: [{,…}]
logGroupName: "Demo"
logStreamName: "front"
sequenceToken: "49628590183593312425478787996364355797"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.