Copyright © 2023 Astrohelm contributors.
Astrologger is MIT licensed.
Astrologger is part of Astrohelm.
astrohelm / astrologger Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Copyright © 2023 Astrohelm contributors.
Astrologger is MIT licensed.
Astrologger is part of Astrohelm.
Flush should lock itself until write end to avoid parallel data flush.
lock = false;
const flush = () => {
if(lock) return;
lock = true;
//... some flush logic
stream.write(buffer, () => {
lock = false;
//... other release logic
})
}
Types and structure of possible logger configuration:
// ?: means unnecessary or can be default value
const options: {
path?: string; // Absolute or relative path, by default no logs into files
keep?: number; // delete after N days, 0 - disable, (default: 1 if path specified else 0)
home?: string; // Remove that part from Error paths.
mark?: string; // Some additional information for the logs
logLevel?: number; // Disable logs under this log level
timeFormat?: string; // Stdout time format (default: h:m:s)
write?: { // Write settings
consoleMethod?: (...args: any) => void; // console.log or process.stdout.write (default: console.log)
interval?: [number, number] | number, // flush log to disk and console intervals (default: 300ms)
buffer?: number, // buffer size (default: 64kb)
};
methods?: { // Console methods
// ...defaultMethods
info?: { // By default all console methods
color: string; // R;G;B (default: 255;255;255) or some gray color
level?: number; // Important level (default: 0), bigger = more important.
parser?: (...args: any) => [string, string] | string; // Custom message parser, [stdout, file] | universal
callback?: async (...args: any) => void; // Custom callback function, can be used to provide logs to other API.
}
// Can be new methods such as myOwnLogMethod
};
};
My vision of logger usage:
const Logger = require('astrolog');
// Possible configuration
const opts = {
path: './log',
keep: 5,
home: process.cwd(),
mark: 'Worker №7',
logLevel: 0,
timeFormat: 'd:m:s.i', // i means millisecond
write: {
interval: [300, 3000],
buffer: 64 * 1024,
consoleMethod: process.stdout.write
},
methods: {
myOwnLogMethod: [
color: "0;0;255",
level: 3,
parser: (message) => message + ' custom handler',
callback: (message) => {},
]
}
}
(async () => {
const logger = await Logger.open(opts); // Static method
// const logger = await new Logger(opts) Or standard way
const { console } = logger;
console.log('Test message');
console.error('Error message');
// All console methods
// For the start - log, error, clear, dir, table, warn, info, debug, assert
await logger.close();
})();
No response
No response
console.error
and console.debug
This methods should parse thrown error to make Errors more readable.
const Logger = require('astrolog');
const console = Logger(/* Some options */);
console.error(new Error('Testing console.error'));
// Error: Testing console.error /path/to/executable-file.js:row:column
In configuration we have home options, its allow us to remove this part of path from Error.
Would be great if repeated messages will be replaced by message + counter
const Logger = require('astrolog');
const console = Logger(/* Some options */);
console.error(new Error('Testing console.error'));
console.error(new Error('Testing console.error'));
console.error(new Error('Testing console.error'));
// ... old messages, before first log
// Error: Testing console.error /path/to/executable-file.js:row:column #3
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.