
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
activity-logger
Advanced tools
Log activities, showing the time it takes to complete them.
Track how long certain activities take in your application.
Think of it is a more powerful and expressive console.time
, one that lets you customize not only what is logged out but also where it goes. You can pipe messages to console.log
, process.stdout
, or write to the file system however you like!
Super inspired by react-native's Activity module.
$ npm install --save activity-logger
Basic usage.
const activity = require('activity-logger');
var ovenActivity = activity.start('Heating up the oven.');
// logs -> 'Heating up the oven';
setTimeout(function() {
activity.end(ovenActivity);
// logs -> 'Heating up the oven (1234ms)'
}, 1234);
You can customize what the output looks like.
activity.setStartFormatter(function(activity) {
return '[' + activity.id + '] ' + activity.message + ' @ ' +
new Date(activity.timestamps[0]).toLocaleTimeString();
});
var activityId = activity.start('Booting up');
// logs -> '[2] Booting up @ 9:51:26 AM'
activity.setEndFormatter(function(activity) {
return '[' + activity.id + '] ' + activity.message + ' @ ' +
new Date(activity.timestamps[0]).toLocaleTimeString() +
' - COMPLETED (' + (activity.timestamps[1] - activity.timestamps[0]) + 'ms)';
});
setTimeout(function() {
activity.end(activityId);
// logs -> '[2] Booting up @ 9:51:26 AM - COMPLETED (23ms)'
}, 23);
And you can change where the output is sent!
activity.setOutputHandlers(function(message) {
fs.appendFileSync('./log.txt', message, 'utf8');
});
// Now every message is appended to our log file.
Returns the activityId
you can later use to end the activity. Logs out to console
that the activity has started.
Type: string
The message you want outputted.
Ends the activity and returns the Activity
object. Logs out to the console the activity ended, showing the time it
took to complete.
Type: number
The id of the activity we want to end.
Returns the activityId
you can later use to end the activity. Does not create any
timestamp, just registers a new activity.
Type: string
The message you want outputted.
Adds a new timestamp to the Activity's array of timestamps.
Type: number
The id of the activity.
Returns Activity
object after removing it from internal cache of activities.
Does not modify Activity object at all.
Type: number
The id of the activity.
Disable output.
Enable output.
Change how start events are outputted.
Type: function
Formatter is given an activity
object. It must return a string as that is
given to each function in outputHandlers
array.
activity
{
"id": 21,
"message": "Message string given from activity.start",
"timestamps": [1453692902523]
}
Change how end events are outputted.
Type: function
Formatter is given an activity
object. It must return a string as that is
given to each function in the outputHandlers
array. In the end event the timestamps
array has a second value to calculate the time spread.
activity
{
"id": 21,
"message": "Message string given from activity.start",
"timestamps": [1453692902523, 1453692905599]
}
Returns all outputHandlers
.
Overwrite the existing outputHandlers
array.
Type: ...function
A variable number of new functions to set as outputHandlers
.
Add one handler to the outputHandlers
array.
Type: function
MIT © Harry Wolff
FAQs
track time to complete activities to any output
The npm package activity-logger receives a total of 28 weekly downloads. As such, activity-logger popularity was classified as not popular.
We found that activity-logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.