Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve logging #28

Merged
merged 12 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/test-logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const http = require('http');
const fs = require('fs');
const process = require('process');

const options = {
hostname: 'localhost',
port: 9090,
path: '/',
method: 'POST',
};


const req = http.request(options, res => {
const buf = fs.readFileSync('log.txt').toString();
const expect = `POST / "Hello World"\n`
if (expect !== buf) {
console.error(`expected ${expect}, but got ${buf}`);
process.exit(1);
return;
}
})

req.on('error', error => {
console.error(error);
process.exit(1);
return;
});

req.write('Hello World');

req.end();
49 changes: 19 additions & 30 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ jobs:
{
"md": "text/markdown"
}
log: "log.txt"
-
run: |
node .github/test-default.js
cat log.txt
run: node .github/test-default.js

test-index-files:
strategy:
Expand All @@ -52,11 +49,8 @@ jobs:
no-cache: true
index-files: |
["PULL_REQUEST_TEMPLATE.md"]
log: "log.txt"
-
run: |
node .github/test-index-files.js
cat log.txt
run: node .github/test-index-files.js

test-allowed-methods:
strategy:
Expand All @@ -78,23 +72,8 @@ jobs:
no-cache: true
allowed-methods: |
["POST"]
log: "log.txt"
-
run: |
node .github/test-allowed-methods.js
cat log.txt

# draft your next release notes as pull requests are merged into "master"
# the configuration is at /.github/release-drafter.yml.
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
if: github.ref == 'refs/heads/master'
with:
config-name: release-drafter.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node .github/test-allowed-methods.js
test-logging:
strategy:
matrix:
Expand All @@ -115,10 +94,20 @@ jobs:
no-cache: true
allowed-methods: |
["GET", "POST"]
log: "log.txt"
log: log.txt
logTime: false
-
run: |
curl -vvvv http://localhost:9090/
curl --header "Content-Type: application/json" --request POST --data '[{"msg":"hello"},{"msg":"World"}]' http://localhost:9090/
- name: Show log
run: cat log.txt
run: node .github/test-logging.js


# draft your next release notes as pull requests are merged into "master"
# the configuration is at /.github/release-drafter.yml.
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
if: github.ref == 'refs/heads/master'
with:
config-name: release-drafter.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ Default:
}
```
### `log`
Create a log file with the given name (default is `off`) (*optional*)
Create a log file with the given name (default is ``, which means no logging) (*optional*)

### `logTime`
Include the time of access in the log file (default is `true`) (*optional*)

## Example
```yaml
Expand Down Expand Up @@ -73,6 +76,7 @@ steps:
"xml": "text/xml"
}
log: "log.txt"
logTime: "false"
-
run: |
curl -vvvv http://localhost:8080/index.html
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ inputs:
log:
description: 'Create a log file with given name'
required: false
default: 'off'
default: ''
logTime:
description: 'Whether to include the time of access in the log file or not'
required: false
default: true
runs:
using: 'node16'
main: 'main.js'
Expand Down
10 changes: 9 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ let config = {
indexFiles: null,
allowedMethods: null,
contentTypes: null,
log: null
log: null,
logTime: null
};

config.root = core.getInput('directory');
Expand Down Expand Up @@ -96,6 +97,13 @@ if (config.allowedMethods === null || config.allowedMethods.length == 0) {

config.log = core.getInput("log");

config.logTime = core.getInput('logTime');
if (config.logTime === null || config.logTime.length == 0) {
config.logTime = true;
} else {
config.logTime = config.logTime === 'true';
}

const cp = require('child_process');
const child = cp.fork(__filename, ['serve'], { detached: true, silent: true });
child.on('error', (err) => {
Expand Down
Loading