Skip to content

Commit fbbf8cd

Browse files
susnuxmax-nextcloud
authored andcommitted
Use @nextcloud/logger for all logging
The nextcloud logger take account for the configured logging level, so only messages the user / administrator wants are logged. This fixes #2846 (no debug messages are logged if not configured). Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent e04ba49 commit fbbf8cd

File tree

19 files changed

+128
-82
lines changed

19 files changed

+128
-82
lines changed

package-lock.json

Lines changed: 11 additions & 6 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
@@ -43,6 +43,7 @@
4343
"@nextcloud/event-bus": "^3.0.2",
4444
"@nextcloud/initial-state": "^2.0.0",
4545
"@nextcloud/l10n": "^1.6.0",
46+
"@nextcloud/logger": "^2.3.0",
4647
"@nextcloud/moment": "^1.2.1",
4748
"@nextcloud/router": "^2.0.0",
4849
"@nextcloud/vue": "^7.0.0-beta.2",

src/EditorFactory.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*
1+
/**
22
* @copyright Copyright (c) 2019 Julius Härtl <[email protected]>
33
*
44
* @author Julius Härtl <[email protected]>
55
*
6-
* @license GNU AGPL version 3 or any later version
6+
* @license AGPL-3.0-or-later
77
*
88
* This program is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Affero General Public License as
@@ -18,38 +18,46 @@
1818
* You should have received a copy of the GNU Affero General Public License
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
21-
*/
21+
*/
2222

2323
/* eslint-disable import/no-named-as-default */
2424
import History from '@tiptap/extension-history'
2525
import Placeholder from '@tiptap/extension-placeholder'
2626
/* eslint-enable import/no-named-as-default */
2727

2828
import TrailingNode from './nodes/TrailingNode.js'
29+
import EmojiListWrapper from './components/EmojiListWrapper.vue'
2930
import EditableTable from './nodes/EditableTable.js'
31+
import MentionSuggestion from './components/Mention/suggestion.js'
32+
33+
import tippy from 'tippy.js'
34+
import 'proxy-polyfill'
35+
3036
import { Editor } from '@tiptap/core'
31-
import { Emoji, Markdown, Mention, PlainText, RichText } from './extensions/index.js'
37+
import { VueRenderer } from '@tiptap/vue-2'
3238
import { translate as t } from '@nextcloud/l10n'
39+
import { emojiSearch } from '@nextcloud/vue/dist/Functions/emoji.js'
3340
import { listLanguages, registerLanguage } from 'lowlight/lib/core.js'
3441
import { emojiSearch } from '@nextcloud/vue/dist/Functions/emoji.js'
3542
import { VueRenderer } from '@tiptap/vue-2'
36-
import EmojiListWrapper from './components/EmojiListWrapper.vue'
43+
import EmojiList from './components/EmojiList.vue'
3744
import MentionSuggestion from './components/Mention/suggestion.js'
3845
import tippy from 'tippy.js'
3946

40-
import 'proxy-polyfill'
47+
import { logger } from './helpers/logger.js'
48+
import { Emoji, Markdown, Mention, PlainText, RichText } from './extensions/index.js'
4149

4250
const loadSyntaxHighlight = async (language) => {
4351
const list = listLanguages()
44-
console.info(list)
52+
logger.debug('Supported languages', { list })
4553
if (!listLanguages().includes(language)) {
4654
try {
4755
// eslint-disable-next-line n/no-missing-import
4856
const syntax = await import(/* webpackChunkName: "highlight/[request]" */'highlight.js/lib/languages/' + language)
4957
registerLanguage(language, syntax.default)
50-
} catch (e) {
51-
// No matching highlighing found, fallback to none
52-
console.debug(e)
58+
} catch (error) {
59+
// fallback to none
60+
logger.debug('No matching highlighing found', { error })
5361
}
5462
}
5563
}

src/components/Editor.provider.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*
1+
/**
22
* @copyright Copyright (c) 2022 Vinicius Reis <[email protected]>
33
*
44
* @author Vinicius Reis <[email protected]>
55
*
6-
* @license GNU AGPL version 3 or any later version
6+
* @license AGPL-3.0-or-later
77
*
88
* This program is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Affero General Public License as
@@ -20,6 +20,8 @@
2020
*
2121
*/
2222

23+
import { logger } from '../helpers/logger.js'
24+
2325
export const EDITOR = Symbol('tiptap:editor')
2426
export const FILE = Symbol('editor:file')
2527
export const ATTACHMENT_RESOLVER = Symbol('attachment:resolver')
@@ -84,7 +86,7 @@ export const useAttachmentResolver = {
8486
from: ATTACHMENT_RESOLVER,
8587
default: {
8688
resolve(src) {
87-
console.warn('No attachment resolver provided. Some attachment sources cannot be resolved.')
89+
logger.warn('No attachment resolver provided. Some attachment sources cannot be resolved.')
8890
return [src]
8991
},
9092
},

src/components/Editor.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import {
8585
SYNC_SERVICE,
8686
} from './Editor.provider.js'
8787
88+
import { logger } from '../helpers/logger.js'
8889
import { SyncService, ERROR_TYPE, IDLE_TIMEOUT } from './../services/SyncService.js'
8990
import AttachmentResolver from './../services/AttachmentResolver.js'
9091
import { extensionHighlight } from '../helpers/mappings.js'
@@ -568,8 +569,8 @@ export default {
568569
this.$nextTick(() => {
569570
this.$emit('sync-service:sync')
570571
})
571-
} catch (e) {
572-
console.error('Failed to update steps in collaboration plugin', e)
572+
} catch (error) {
573+
logger.error('Failed to update steps in collaboration plugin', { error })
573574
// TODO: we should recreate the editing session when this happens
574575
}
575576
this.document = document
@@ -663,8 +664,8 @@ export default {
663664
this.unlistenEditorEvents()
664665
this.$editor.destroy()
665666
this.$editor = null
666-
} catch (err) {
667-
console.warn(err)
667+
} catch (error) {
668+
logger.warn('Failed to destroy editor', { error })
668669
}
669670
}
670671
return true

src/components/Editor/MediaHandler.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-
44
- @author Vinicius Reis <[email protected]>
55
-
6-
- @license GNU AGPL version 3 or any later version
6+
- @license AGPL-3.0-or-later
77
-
88
- This program is free software: you can redistribute it and/or modify
99
- it under the terms of the GNU Affero General Public License as
@@ -43,6 +43,7 @@
4343
<script>
4444
import { getCurrentUser } from '@nextcloud/auth'
4545
import { showError } from '@nextcloud/dialogs'
46+
import { logger } from '../../helpers/logger.js'
4647
4748
import {
4849
useEditorMixin,
@@ -122,9 +123,9 @@ export default {
122123
})
123124
124125
return Promise.all(uploadPromises)
125-
.catch(err => {
126-
console.error(err)
127-
showError(err?.response?.data?.error || err.message)
126+
.catch(error => {
127+
logger.error('Uploading multiple images failed', { error })
128+
showError(error?.response?.data?.error || error.message)
128129
})
129130
.then(() => {
130131
this.state.isUploadingAttachments = false
@@ -141,7 +142,7 @@ export default {
141142
)
142143
})
143144
.catch((error) => {
144-
console.error(error)
145+
logger.error('Uploading image failed', { error })
145146
showError(error?.response?.data?.error)
146147
})
147148
.then(() => {
@@ -167,7 +168,7 @@ export default {
167168
null, response.data?.dirname
168169
)
169170
}).catch((error) => {
170-
console.error(error)
171+
logger.error('Failed to insert image path', { error })
171172
showError(error?.response?.data?.error || error.message)
172173
}).then(() => {
173174
this.state.isUploadingAttachments = false

src/components/Menu/MenuBar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- @author Vinicius Reis <[email protected]>
55
- @author Julius Härtl <[email protected]>
66
-
7-
- @license GNU AGPL version 3 or any later version
7+
- @license AGPL-3.0-or-later
88
-
99
- This program is free software: you can redistribute it and/or modify
1010
- it under the terms of the GNU Affero General Public License as

src/files.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*
1+
/**
22
* @copyright Copyright (c) 2019 Julius Härtl <[email protected]>
33
*
44
* @author Julius Härtl <[email protected]>
55
*
6-
* @license GNU AGPL version 3 or any later version
6+
* @license AGPL-3.0-or-later
77
*
88
* This program is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Affero General Public License as
@@ -21,11 +21,13 @@
2121
*/
2222

2323
import Vue from 'vue'
24-
import { registerFileActionFallback, FilesWorkspacePlugin } from './helpers/files.js'
25-
import FilesSettings from './views/FilesSettings.vue'
26-
import { loadState } from '@nextcloud/initial-state'
2724
import { linkTo } from '@nextcloud/router'
25+
import { loadState } from '@nextcloud/initial-state'
26+
2827
import store from './store/index.js'
28+
import FilesSettings from './views/FilesSettings.vue'
29+
import { logger } from './helpers/logger.js'
30+
import { registerFileActionFallback, FilesWorkspacePlugin } from './helpers/files.js'
2931

3032
__webpack_nonce__ = window.btoa(OC.requestToken) // eslint-disable-line
3133
__webpack_public_path__ = linkTo('text', 'js/') // eslint-disable-line
@@ -35,11 +37,11 @@ const workspaceEnabled = loadState('text', 'workspace_enabled')
3537

3638
document.addEventListener('DOMContentLoaded', () => {
3739
if (typeof OCA.Viewer === 'undefined') {
38-
console.error('Viewer app is not installed')
40+
logger.error('Viewer app is not installed')
3941
registerFileActionFallback()
4042
}
4143

42-
if (workspaceAvailable && OCA && OCA.Files && OCA.Files.Settings) {
44+
if (workspaceAvailable && OCA && OCA?.Files?.Settings) {
4345
Vue.prototype.t = window.t
4446
Vue.prototype.n = window.n
4547
Vue.prototype.OCA = window.OCA

src/helpers/links.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*
1+
/**
22
* @copyright Copyright (c) 2020 Azul <[email protected]>
33
*
44
* @author Azul <[email protected]>
55
*
6-
* @license GNU AGPL version 3 or any later version
6+
* @license AGPL-3.0-or-later
77
*
88
* This program is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Affero General Public License as
@@ -21,6 +21,8 @@
2121
*/
2222

2323
import { generateUrl } from '@nextcloud/router'
24+
25+
import { logger } from '../helpers/logger.js'
2426
import markdownit from './../markdownit/index.js'
2527

2628
const absolutePath = function(base, rel) {
@@ -105,7 +107,7 @@ const openLink = function(event, _attrs) {
105107
return
106108
}
107109
if (!markdownit.validateLink(htmlHref)) {
108-
console.error('Invalid link', htmlHref)
110+
logger.error('Invalid link', { htmlHref })
109111
return false
110112
}
111113
if (fragment) {

src/helpers/logger.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { getLoggerBuilder } from '@nextcloud/logger'
2+
3+
const logger = getLoggerBuilder()
4+
.setApp('text')
5+
.detectUser()
6+
.build()
7+
8+
export {
9+
logger,
10+
}

0 commit comments

Comments
 (0)