Skip to content

Commit 07b0714

Browse files
authored
Suppress logging with NODE_ENV (digitalocean#332)
1 parent cddfdc7 commit 07b0714

File tree

14 files changed

+100
-58
lines changed

14 files changed

+100
-58
lines changed

.github/workflows/do-spaces-workflow.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828

2929
- name: Build tool
3030
run: npm run build
31+
env:
32+
NODE_ENV: production
3133

3234
- name: Deploy commit to DigitalOcean Spaces
3335
run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/commits/nginxconfig/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com --acl public-read --content-encoding utf8

.github/workflows/gh-pages-workflow.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434

3535
- name: Build tool
3636
run: npm run build
37+
env:
38+
NODE_ENV: production
3739

3840
- name: Deploy master to GitHub Pages
3941
uses: JamesIves/[email protected]

package-lock.json

Lines changed: 30 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"stylelint-config-standard-scss": "^3.0.0",
8686
"stylelint-order": "^5.0.0",
8787
"vue-template-compiler": "^2.6.14",
88+
"webpack": "^5.69.1",
8889
"webpack-bundle-analyzer": "^4.5.0"
8990
},
9091
"overrides": {

src/nginxconfig/build/webpack-dynamic-import.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2021 DigitalOcean
2+
Copyright 2022 DigitalOcean
33
44
This code is licensed under the MIT License.
55
You may obtain a copy of the License at
@@ -24,8 +24,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
THE SOFTWARE.
2525
*/
2626

27+
import { info } from '../util/log';
28+
2729
const originalSrcDir = document.currentScript.src.split('/').slice(0, -2).join('/') + '/';
2830
window.__webpackDynamicImportURL = () => {
29-
console.info(`Using ${originalSrcDir} for webpack dynamic import`);
31+
info(`Using ${originalSrcDir} for webpack dynamic import`);
3032
return originalSrcDir;
3133
};

src/nginxconfig/templates/app.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ THE SOFTWARE.
134134
import analytics from '../util/analytics';
135135
import browserLanguage from '../util/browser_language';
136136
import { defaultPack, availablePacks } from '../util/language_packs';
137+
import { info, error } from '../util/log';
137138

138139
import { setLanguagePack } from '../i18n/setup';
139140
import generators from '../generators';
@@ -243,16 +244,15 @@ THE SOFTWARE.
243244
// Update the locale
244245
setLanguagePack(data.computed).then(() => {
245246
// Done
246-
console.log('Language set to', data.computed);
247+
info('Language set to', data.computed);
247248
this.$data.languagePrevious = data.computed;
248249
this.$data.languageLoading = false;
249250

250251
// Analytics
251252
this.languageSetEvent(!interactive);
252253
}).catch((err) => {
253254
// Error
254-
console.log('Failed to set language to', data.computed);
255-
console.error(err);
255+
error(`Failed to set language to ${data.computed}`, err);
256256

257257
// Fallback to last known good
258258
data.value = this.$data.languagePrevious;
@@ -358,9 +358,9 @@ THE SOFTWARE.
358358
file,
359359
];
360360
});
361-
} catch (e) {
361+
} catch (err) {
362362
// If diff generation goes wrong, don't show any diff
363-
console.error(e);
363+
error('Failed to compute and highlight diff', err);
364364
this.$data.confFilesOutput = Object.entries(newConf).map(([ name, content ]) => {
365365
const safeName = escape(name);
366366
const safeContent = escape(content);

src/nginxconfig/templates/prism/bash.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright 2021 DigitalOcean
2+
Copyright 2022 DigitalOcean
33

44
This code is licensed under the MIT License.
55
You may obtain a copy of the License at
@@ -31,13 +31,15 @@ THE SOFTWARE.
3131
</template>
3232

3333
<script>
34+
import { info } from '../../util/log';
35+
3436
export default {
3537
name: 'BashPrism',
3638
props: {
3739
cmd: String,
3840
},
3941
mounted() {
40-
console.info(`Highlighting ${this.$props.cmd}...`);
42+
info(`Highlighting ${this.$props.cmd}...`);
4143
window.Prism.highlightAllUnder(this.$el);
4244
},
4345
methods: {

src/nginxconfig/templates/prism/docker.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright 2021 DigitalOcean
2+
Copyright 2022 DigitalOcean
33

44
This code is licensed under the MIT License.
55
You may obtain a copy of the License at
@@ -33,6 +33,7 @@ THE SOFTWARE.
3333

3434
<script>
3535
import 'prismjs/components/prism-docker';
36+
import { info } from '../../util/log';
3637

3738
export default {
3839
name: 'DockerPrism',
@@ -42,7 +43,7 @@ THE SOFTWARE.
4243
half: Boolean,
4344
},
4445
mounted() {
45-
console.info(`Highlighting ${this.$props.name}...`);
46+
info(`Highlighting ${this.$props.name}...`);
4647
window.Prism.highlightAllUnder(this.$el);
4748
},
4849
methods: {

src/nginxconfig/templates/prism/nginx.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright 2021 DigitalOcean
2+
Copyright 2022 DigitalOcean
33

44
This code is licensed under the MIT License.
55
You may obtain a copy of the License at
@@ -32,6 +32,8 @@ THE SOFTWARE.
3232
</template>
3333

3434
<script>
35+
import { info } from '../../util/log';
36+
3537
export default {
3638
name: 'NginxPrism',
3739
props: {
@@ -40,7 +42,7 @@ THE SOFTWARE.
4042
half: Boolean,
4143
},
4244
mounted() {
43-
console.info(`Highlighting ${this.$props.name}...`);
45+
info(`Highlighting ${this.$props.name}...`);
4446
window.Prism.highlightAllUnder(this.$el);
4547
},
4648
methods: {

src/nginxconfig/templates/prism/yaml.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright 2021 DigitalOcean
2+
Copyright 2022 DigitalOcean
33

44
This code is licensed under the MIT License.
55
You may obtain a copy of the License at
@@ -33,6 +33,7 @@ THE SOFTWARE.
3333

3434
<script>
3535
import 'prismjs/components/prism-yaml';
36+
import { info } from '../../util/log';
3637

3738
export default {
3839
name: 'YamlPrism',
@@ -42,7 +43,7 @@ THE SOFTWARE.
4243
half: Boolean,
4344
},
4445
mounted() {
45-
console.info(`Highlighting ${this.$props.name}...`);
46+
info(`Highlighting ${this.$props.name}...`);
4647
window.Prism.highlightAllUnder(this.$el);
4748
},
4849
methods: {

src/nginxconfig/util/analytics.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2021 DigitalOcean
2+
Copyright 2022 DigitalOcean
33
44
This code is licensed under the MIT License.
55
You may obtain a copy of the License at
@@ -24,8 +24,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
THE SOFTWARE.
2525
*/
2626

27+
import { info } from './log';
28+
2729
export default ({ category, action, label, value, nonInteraction }) => {
28-
console.info('Analytics event:', { category, action, label, value, nonInteraction });
30+
info('Analytics event:', { category, action, label, value, nonInteraction });
2931

3032
/*try {
3133
// Google Analytics

src/nginxconfig/util/log.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2022 DigitalOcean
3+
4+
This code is licensed under the MIT License.
5+
You may obtain a copy of the License at
6+
https://github.com/digitalocean/nginxconfig.io/blob/master/LICENSE or https://mit-license.org/
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions :
14+
15+
The above copyright notice and this permission notice shall be included in
16+
all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
THE SOFTWARE.
25+
*/
26+
27+
export const info = process.env.NODE_ENV !== 'production' ? console.info.bind(console) : () => {};
28+
export const log = process.env.NODE_ENV !== 'production' ? console.log.bind(console) : () => {};
29+
30+
export const warn = console.warn.bind(console);
31+
export const error = console.error.bind(console);

0 commit comments

Comments
 (0)