Skip to content

Caallum/Nodejs-Logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nodejs Logger

Getting started

To get started with calling the logger, make sure to choose the correct file type. If you need to import the file, eg import Logger from "logger.js" then use Logger.import.js. If you need to require the file, eg const Logger = require("logger.js") then use Logger.require.js.

Once you have uploaded these files to your project, you can now start to call the logger class!

Calling the Logger Class

To call the class, make sure to import the file using either

import Logger from "./{file}/{dir}/Logger.import.js

or

const Logger = require("./${file/${dir}/Logger.require.js

Once you have imported or required the logger file, you can easily log something by putting

new Logger({
  message: "This is a normal message"
})

This will return
Alt Text

More styles

There is more styles, for such things as logging stuff based on important and overall just keeping the console tidy, the different styles are: info, success, warning, error.

The way to call these are:

Info

new Logger({
  info: true,
  message: "This is an info message"
})
Returns

Alt Text

Success

new Logger({
  success: true,
  message: "This is a success message"
})
Returns

Alt Text

Warning

new Logger({
  warning: true,
  message: "This is a warning message"
})
Returns

Alt Text

Error

new Logger({
  error: true,
  message: "This is an error message"
})
Returns

Alt Text

Extra Options

Writing WARNING and ERROR logs into a log file

To get started, first go to the top of the file, you should see

let FileName = `./src/development.logs`;
let WriteToFile = true;

In these variables, you can edit to if you want to write logs to a file, and where you want to write the logs too.

If you want to disable this feature, simply set WriteToFile to false using:

let WriteToFile = false;

If you want to enable it, leave it as it is.

To set the location of the log file, simply edit FileName to where you wish to store the log file. Example:

let FileName = `./logs/ErrorAndWarning.log`

Ending

And that's it! I created this for a project I was working on and thought it was pretty handy to have as a GitHub repo. With a little help from google and some brainpower I made this inside about 10 minutes so "no errors will occur at all"!

Made by Caallum for public usage

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published