
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Flexible distributed logger module with hot-reload support
Install with npm:
$ npm install logia
const Logia = require("logia");
const dbLogger = Logia("database");
const parserLogger = Logia("parser");
dbLogger.setLevel("trace");
parserLogger.setLevel("debug");
dbLogger.trace("Number of entries are 0.");
parserLogger.debug("Invoked with no arguments.");
dbLogger.info("Retrieving data...");
parserLogger.warn("Note that something is missing!");
dbLogger.error("Something exploded!");
parserLogger.fatal("something went terribly wrong :(");
Above code will give below output:
(31-03-2017 11:54:06) TRACE [database]:Number of entries are 0.
(31-03-2017 11:54:06) DEBUG [parser] :Invoked with no arguments.
(31-03-2017 11:54:06) INFO [database]:Retrieving data...
(31-03-2017 11:54:06) WARN [parser] :Note that something is missing!
(31-03-2017 11:54:06) ERROR [database]:Something exploded!
(31-03-2017 11:54:06) FATAL [parser] :something went terribly wrong :(
Logs can also be parameterized
const pi = 3.14;
const e = 2.72;
logger.info("Value of 'pi' is '{0}' and value of 'e' is '{1}'", pi, e);
When requiring the logia module a logia.json configuration file is created under a config folder of the current working directory.
Alternatively we can set the LOGIA_CONFIG_FILE_PATH environment variable if we want to change the default configuration filename and location.
Every change we make in the configuration file is immediately applied to the configuration of the loggers without the need of rebooting our application
{
"level": {
".*": null
},
"appenders": {
"$_fill_logger_name_regexp": {
"filepath": null,
"maxSize": null
}
},
"remotes": {
"$_fill_logger_name_regexp": {
"protocol": null,
"url": null
}
},
"mode": {
"type": null,
"host": null,
"port": null
},
"stdout": false,
"dateFormat": "(DD-MM-YYYY HH:mm:ss)",
"overwritable": true
}
In this section we can set the logging level of our loggers. We target loggers by writing a javascript regexp string which matches the name of the loggers and set its level.
For example, below configuration will set all loggers that start with the substring "database" to level info and all loggers that contain the substring "handler" to level error;
"level": {
"^database": "info",
"*handler": "error"
}
By setting the level of a logger we also activate the logger and we enable others features(e.g appenders, remotes) to further configure them.
In the appenders section we can define where the logs will be stored in our filesystem. We target the loggers by writing a javascript regexp string, the same way we did for the level section but instead for setting the logging level we specify the output file. Moreover we can set the maxSize property in which we specify the maximum size in MBs of the log file. If the size of that file reaches the specified limit then the first half of its contents will be deleted. The filepath is treated as an absolute path unless it starts with ./ which then is resolved as a relative path to the current working directory.
For example, below configuration will append the logs of the loggers which name starts with the "database-mongo" and "database-redis" substring to the "/temp/redis.log" and "/temp/mongo.log" files respectively and limit their size to 20MBs. Similarly, the logs of the loggers which contain the "handler" substring in their name will end up in "cwd/logs/handler-errors.log" file.
"appenders": {
"^database-mongo": {
"filepath": "/temp/mongo.log",
"maxSize": 20
},
"^database-redis": {
"filepath": "/temp/redis.log",
"maxSize": 20
},
"*handler": {
"filepath": "./logs/handler-errors.log"
}
}
The remotes section is similar to the appenders section but instead of appending the logs in a file it allows us to send them in a remote location. We need to provide a destination url and a protocol. Supported protocols are ws(websockets) and http and both use JSON format.
For example, below configuration will send the logs of the loggers which name starts with the "database" substring to the websocket server that runs on "websocket.server.com:8989". Similarly, the logs of loggers with the "handler" substring in their name will be send to the http server that runs on "http.server.com:8080".
"remotes": {
"^database": {
"url": "websocket.server.com:8989",
"protocol": "ws"
},
"*handler": {
"url": "http.server.com:8080",
"protocol": "http"
}
}
Logia can run both as a master or as a slave node.
Below configuration will boot up a master node on localhost:8080.
"mode": {
"type": "master",
"host": "master.server.com",
"port": 8080
}
By running a logia instance as a master node it allows to control all connected slaves through the masters node configuration file.
Below configuration will boot up a slave node that will be connected and controlled by the the master node specified above.
"mode": {
"type": "slave",
"host": "master.server.com",
"port": 8080
}
The master/slave setup uses websockets which preserves the order of the logs. This enables us to gather logs for client-server applications and still read them from top to bottom without the need of applying any type of sorting.
By setting this properrty to true all logs will be printed in standard output.
Set the date format. Uses Moment.js display format.
All aforementioned features are also accesible through a programming interface. Check the API documentation in Markdown or HTML
Copyright (c) 2016 Ioannis Tzanellis
Released under the MIT license
FAQs
Flexible distributed logger module with hot-reload support
We found that logia 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.