Folder-Logger
Easy log management.
Categorized by folder according to importance
Categorized by date/time, automatic file classification
Beautiful basic text formatting
This logger module is easy to use in Node.js.
Use example
Folder-Logger has the basic functionality of applying even text formatting to all logs. This feature can be customized to suit user needs, and can be turned off or processed as written to files, not as displayed on the console.
Example of using Bash
This is what you see when you use Bash on Windows and Mac. It is recommended to use the Bash-based console whenever possible.
Example of using Windows CMD
Folder-Logger's default text formatting is configured to take CMD of Windows Basics with no variation.
Example of log data categorized as folders
Folder-Logger categorizes logs in log importance and stores them in different folders. Because these folders are stored according to the date, the logs that correspond to the criticality and date and time you are looking for can be easily found in any editor by physical folder and file classification without plug-ins or searches.
Example of log data stored
If any ANSI color is used in the text or special characters are used, Unicode displayed in the console is neatly organized with time without breaking the log. The user can customize the saved log type, and these log formatting can be turned off and on freely according to the log.
How to use
Installing a module
npm install --save folder-logger
Create Logger
You do not need to pre-create a folder path to store logs or create a new log file. If there is no folder hierarchy in the specified folder path, the folder is created and the log file is automatically created (although the program is turned on again, the log is not initialized, and continuous log creation is performed).
// ES5const FolderLogger = // Folder location to store logsconst path = `/logs/` // Create a logger instanceconst logger = path
Send logger message
var message = `Lorem ipsum dolor sit amet` // Prints a basic info message.logger // Prints a system message.logger // Prints a warning message.logger // Prints a error message.logger // Prints a critical error message.logger // Prints a debugging message.logger
Logger level classifications
There are a total of 6 different log classifications for Folder-Logger, and there are 0 to 5 criticality classifications.
const level = info: 0 system: 1 warn: 2 error: 3 critical: 4 debug: 5
These 'level' objects can be imported from the logger at any time in the following way:
// Returns the level object above.logger // Returns the keys of a level object.logger
Setting the Logger Level
Folder-Logger has the ability to set the level of log messages displayed on the console. For example, if 3
is set, a higher level log will not be displayed on the console. Regardless of the set log level, all logs are normally recorded on the file. (The default logger level is 5
)
// In this case, the debug message will not be displayed.logger // In this case, only the info message will be displayed.logger
Advanced How to Use
Apply logger message options
logger
The options can be configured as a second parameter object in all functions info
, system
, warn
, error
, critical
,debug
. The options are described below.
noPrint
If the option is treated as true
, the message will not be output on the console. With these options, you can implement log messages that are logged only on the file and not on the screen.
noWrite
If the option is treated as true
, the message will not be logged in the file. You can use these options to implement log messages that are only on-screen and are not recorded in the file.
noFormat
If the option is treated as true
, default text formatting is not applied to the message. This is the same as the message stored in the file and all messages displayed on the console. If saves the log with the option enabled, the time when the message occurred is not recorded, so use it with carelessly.
Change the location of the logger message
The function below allows the module to change the storage location of the logger message during execution. Existing log files are automatically closed and folder hierarchies and files are automatically created if no log folder path exists.
// New Folder Location to Save Logsconst path = `/logs/` // Change the location where the logs are stored.logger
Using the log function
If you do not want to use the function name differently depending on the level classification, you can also specify the log level as an option using the log function as shown below. (If no log level is specified, the info
level is applied automatically.)
logger
Customizing method
Change log file extension
The log file extension stored by default is .log
. If you want to use a different extension, you can designate it as a second parameter object when you create a logger instance.
// Create a logger instanceconst logger = path ext: `txt` // In this case, it is saved with a .txt extension.
Change Log File Time Formatting
In Folder-Logger, the time format used for log files depends on the moment.js
module and can be freely converted to a 'date format' compatible with moment.js
. In other words, you can specify a date shape in the form of a string. By default, the designated date format is YYYY-MM-DD.
// Create a logger instanceconst logger = path timeFormat: `YYYY-MM-DD` // Ex: 2019-02-06
Apply moment.js option to log file time format
If there is a moment.js
option, such as setting the time zone while using Folder-Logger, which requires direct use in the form of moment(/* here */)
, it can be applied as follows:
// Create a logger instanceconst logger = path momentOption: `2090-11-11T11:11:11`
Change Log Text Formatting
Text formatting used to customize Folder-Logger can be freely customized by the user. Here's how to use it:
// This color representation module// will be used for formatting.const chalk = // Formating function// (Basic function is enclosed as an example).const myLogFormat = { let defaultFormat ='%time% %level% \t\b\b\b\b' + '%log%' let time = let levelName = StringloggerlevelNameslevel let text = defaultFormat return text} // Create a logger instanceconst logger = path logFormat: myLogFormat
Logo Icon Source
License
MIT Licensed.