-
Notifications
You must be signed in to change notification settings - Fork 1
Examples
Grant Carthew edited this page Oct 25, 2024
·
15 revisions
There is an examples
directory with files you can use to get you started using perj
. If you have a good example you would like to add please raise an issue or send a pull request.
As a best practice write your own logger that wraps perj
and exports the root logger object.
The following Node.js example is to give you an idea on how you can integrate perj
into your application. See the app example for more ideas:
logger.js
import Perj from 'perj';
import os from 'os';
import path from 'path';
// Customize the variables below as needed. They are not required.
const ver = 1;
const name = 'QuickStart';
const host = os.hostname();
const pid = process.pid;
const file = path.basename(import.meta.url, '.js');
export default function newLogger (metaUrl) {
const file = basename(metaUrl, '.js');
return new Perj({ ver, host, pid, name, file })
}
Now to use this logger
module in your application:
app.js
import logFactory from './logger.js'
const log = logFactory(import.meta.url)
log.info('logger created')
// App code here...
One of the goals of the perj
package is 'Designed to be integrated (DIY)'. Use perj
as a lego block and build something spectacular.