jul-log

1.0.0 • Public • Published

jul-log v1.0.0

Description of the package

Created logs for almost everything ✏️
(JSON / TXT / LOG)

simple to use

Usage

const InitLog = require('jul-log'); 

const Error = new InitLog(
    Path = "./logs", 
    NameFile = "error", 
    Format = "json",
)

const Auth = new InitLog(
    Path = "./logs", 
    NameFile = "auth", 
    Format = "json",
)

const login = async (email, password) => {
    try {
        const user = await User.findOne({ email: email });
        if (!user) {

            // It's Here
            Error.add({
                Level : 1,
                Message : "Connection attempt denied"
            })
            //////

            return { code: 400, data: "No account with this email has been registered." }
        }

        if (!bcrypt.compareSync(password, user.password))
            return { code: 401, data: "Invalid creadentials." }

        const token = jwt.sign({ id: user._id, exp: Date.now() + 604800000 }, secret);
        const response = {
            code: 200,
            data: {
                token,
                user: { id: user._id, name: user.name, email: user.email, default: "/"+(user.servers && user.servers[0] || "") }
            }
        }

        // It's Here
            Auth.add({
                Level : 1,
                Message : "User " + user._id + " Connected"
            })
        //////

        return response
    } catch (err) {
        return { code: 500, data: JSON.stringify(err) }
    }
}

router.post("/login", async (req, res) => {
    const { email, password } = req.body;
    if (!email || !password)
        res.status(400).json({ msg: "Password or Email Failed !." });
    else {
        let a = await login(email, password)
        res.status(a.code).json(a.data)
    }
});

Inisialisation Repo InitLog (Step 01)

const InitLog = require('jul-log'); 

const Error = new InitLog(
    Path = "./logs", // file location
    NameFile = "error", // File name
    Format = "json", // Format (txt || json || log)
)

Add Log (Step 02)

Error.add({
    Level : 1, // Level of log format Int 0 & 10
    Message : "Error user" // log
})

Clear Log

Error.clear() // Deletes the entire log file

Package Sidebar

Install

npm i jul-log

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

8.54 kB

Total Files

4

Last publish

Collaborators

  • shirokill