Skip to content

Commit

Permalink
fix: put logs inside a logs sub-folder
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron committed Oct 8, 2020
1 parent 90099d2 commit ef2711e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Log file name format: `{processname}.out.log` and `{processname}`.err.log,
In this example, your `stdout` log will be called `long-running-process.sh.out.log` and
your `stderr` log will be called `long-running-process.sh.err.log`.

Both files will be appended to, and will be created if they don't exist.
Both files will be appended to, and will be created if they don't exist, and both will be created inside a `logs` folder in your current working folder. Make sure you put your `logs` folder in your `.gitignore` in case there are secrets being logged.

Since the logs are appended to the file, it is recommended that your logs include a timestamp to differentiate between different runs of the process.

Expand Down
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const path = require('path')
const pkg = require(path.join(__dirname, '..', 'package.json'))
const fs = require('fs')

const LOGS_FOLDER = 'logs'

/**
* Run the commands specified in a detached process.
*
Expand All @@ -27,8 +29,12 @@ async function run (args = []) {

fs.accessSync(args[0], fs.constants.X_OK)

const outFile = `${args[0]}.out.log`
const errFile = `${args[0]}.err.log`
if (!fs.existsSync(LOGS_FOLDER)) {
fs.mkdirSync(LOGS_FOLDER)
}

const outFile = path.join(LOGS_FOLDER, `${args[0]}.out.log`)
const errFile = path.join(LOGS_FOLDER, `${args[0]}.err.log`)
debug(`Writing stdout to ${outFile}, stderr to ${errFile}`)

debug(`Running command detached: ${JSON.stringify(args)}`)
Expand Down

0 comments on commit ef2711e

Please sign in to comment.