{"size": 759, "ext": "js", "max_stars_repo_path": "src/log.js", "max_stars_repo_name": "thegitm8/firestarter-tools", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/log.js", "max_issues_repo_name": "thegitm8/firestarter-tools", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/log.js", "max_forks_repo_name": "thegitm8/firestarter-tools", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.9736842105, "max_line_length": 80, "alphanum_fraction": 0.5599472991}
const net = require('net')

let connected = false
let socket

function fireLoggerConnect() {

    return new Promise((resolve, reject) => {
        socket = net.createConnection({ path: '.fire_log.sock'}, () => {
            connected = true
            resolve()
        })


        socket.on('error', err => {
            connected = false
            reject(err)
        })

    })
    .catch(err => {
        console.error(`Unable to establish fire log connection: ${err.message}`)
    })

}

function fireLoggerLog(msg) {

    const data = typeof msg !== 'string' ? JSON.stringify(msg) : msg

    connected
        ? socket.write(data)
        : console.log(`LOCAL: ${data}`)
}
module.exports = {
    connect: fireLoggerConnect,
    log: fireLoggerLog
}