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

WIP: Feature/override console with logger #2331

Merged
Merged
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"useUrlDispatcher": false
},
"console": {
"verbosityLevel": "only-errors"
"showErrorOnProduction" : true,
"verbosityLevel": "display-everything"
},
"redis": {
"host": "localhost",
Expand Down
8 changes: 1 addition & 7 deletions core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import RootState from '@vue-storefront/core/types/RootState'
import Vue from 'vue'
import buildTimeConfig from 'config'
import { isServer } from '@vue-storefront/core/helpers'
import { Logger } from '@vue-storefront/core/lib/logger'

// Plugins
import i18n from '@vue-storefront/i18n'
Expand Down Expand Up @@ -59,13 +60,6 @@ let router: VueRouter = null

Vue.use(VueRouter)

// Will be depreciated in 1.7. Now we are using Logger instead of logs
if (buildTimeConfig.console.verbosityLevel !== 'display-everything' && process.env.NODE_ENV === 'production') {
once('__TAKE_OVER_CONSOLE__', () => {
takeOverConsole(buildTimeConfig.console.verbosityLevel)
})
}

const createApp = async (ssrContext, config): Promise<{app: Vue, router: VueRouter, store: Store<RootState>}> => {
router = createRouter()
// sync router with vuex 'router' store
Expand Down
50 changes: 27 additions & 23 deletions core/client-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { prepareStoreView, storeCodeFromRoute, currentStoreView, localizedRoute
import { onNetworkStatusChange } from '@vue-storefront/core/modules/offline-order/helpers/onNetworkStatusChange'
import '@vue-storefront/core/service-worker/registration' // register the service worker
import { AsyncDataLoader } from './lib/asyncdataloader'
import { Logger } from '@vue-storefront/core/lib/logger'

declare var window: any

const invokeClientEntry = async () => {
Expand Down Expand Up @@ -103,7 +105,7 @@ const invokeClientEntry = async () => {
})
if (c.asyncData) {
c.asyncData({ store, route: to }).then(result => { // always execute the asyncData() from the top most component first
console.debug('Top-most asyncData executed')
Logger.debug('Top-most asyncData executed')()
_ssrHydrateSubcomponents(components, next, to)
}).catch(next)
} else {
Expand All @@ -119,7 +121,7 @@ const invokeClientEntry = async () => {
* @example
* const urls = ['/url1', '/url2', '/url3']
* serial(urls.map(url => () => $.ajax(url)))
* .then(console.log.bind(console))
* .then(Logger.log.bind(Logger))()
*/
const serial = funcs =>
funcs.reduce((promise, func) =>
Expand All @@ -129,7 +131,7 @@ const invokeClientEntry = async () => {
// TODO: move to external file
EventBus.$on('order/PROCESS_QUEUE', event => {
if (typeof navigator !== 'undefined' && navigator.onLine) {
console.log('Sending out orders queue to server ...')
Logger.log('Sending out orders queue to server ...')()

const storeView = currentStoreView()
const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : ''
Expand All @@ -153,7 +155,7 @@ const invokeClientEntry = async () => {
const orderData = order
const orderId = id

console.log('Pushing out order ' + orderId)
Logger.log('Pushing out order ' + orderId)()
return fetch(config.orders.endpoint,
{
method: 'POST',
Expand All @@ -165,49 +167,49 @@ const invokeClientEntry = async () => {
return response.json()
} else {
orderMutex[id] = false
console.error('Error with response - bad content-type!')
Logger.error('Error with response - bad content-type!')()
}
})
.then(jsonResponse => {
if (jsonResponse && jsonResponse.code === 200) {
console.info('SearchResponse for: ' + orderId + ' = ' + jsonResponse.result)
Logger.info('Response for: ' + orderId + ' = ' + JSON.stringify(jsonResponse.result))()
orderData.transmited = true
orderData.transmited_at = new Date()
ordersCollection.setItem(orderId.toString(), orderData)
} else {
console.error(jsonResponse)
Logger.error(jsonResponse)()
}
orderMutex[id] = false
}).catch(err => {
if (config.orders.offline_orders.notification.enabled) {
navigator.serviceWorker.ready.then(registration => {
registration.sync.register('orderSync')
.then(() => {
console.log('Order sync registered')
Logger.log('Order sync registered')()
})
.catch(error => {
console.log('Unable to sync', error)
Logger.log('Unable to sync', error)()
})
})
}
console.error('Error sending order: ' + orderId, err)
Logger.error('Error sending order: ' + orderId, err)()
orderMutex[id] = false
})
})
}
}, (err, result) => {
if (err) console.error(err)
console.log('Iteration has completed')
if (err) Logger.error(err)()
Logger.log('Iteration has completed')()

// execute them serially
serial(fetchQueue)
.then(res => {
console.info('Processing orders queue has finished')
Logger.info('Processing orders queue has finished')()
// store.dispatch('cart/serverPull', { forceClientState: false })
})
}).catch(err => {
// This code runs if there were any errors
console.log(err)
Logger.log(err)()
})
}
})
Expand Down Expand Up @@ -239,11 +241,11 @@ const invokeClientEntry = async () => {

usersCollection.getItem('current-token', (err, currentToken) => { // TODO: if current token is null we should postpone the queue and force re-login - only if the task requires LOGIN!
if (err) {
console.error(err)
Logger.error(err)()
}
cartsCollection.getItem('current-cart-token', (err, currentCartId) => {
if (err) {
console.error(err)
Logger.error(err)()
}

if (!currentCartId && store.state.cart.cartServerToken) { // this is workaround; sometimes after page is loaded indexedb returns null despite the cart token is properly set
Expand All @@ -254,8 +256,8 @@ const invokeClientEntry = async () => {
currentToken = store.state.user.token
}
const fetchQueue = []
console.debug('Current User token = ' + currentToken)
console.debug('Current Cart token = ' + currentCartId)
Logger.debug('Current User token = ' + currentToken)()
Logger.debug('Current Cart token = ' + currentCartId)()
syncTaskCollection.iterate((task, id, iterationNumber) => {
if (task && !task.transmited && !mutex[id]) { // not sent to the server yet
mutex[id] = true // mark this task as being processed
Expand All @@ -265,19 +267,21 @@ const invokeClientEntry = async () => {
mutex[id] = false
}).catch(err => {
mutex[id] = false
console.error(err)
Logger.error(err)()
})
})
}
}, (err, result) => {
if (err) console.error(err)
console.debug('Iteration has completed')
if (err) Logger.error(err)()
Logger.debug('Iteration has completed')()
// execute them serially
serial(fetchQueue)
.then(res => console.debug('Processing sync tasks queue has finished'))
.then(res => {
Logger.debug('Processing sync tasks queue has finished')()
})
}).catch(err => {
// This code runs if there were any errors
console.log(err)
Logger.log(err)()
})
})
})
Expand Down
22 changes: 11 additions & 11 deletions core/compatibility/lib/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Logger } from '@vue-storefront/core/lib/logger'

export function registerExtensions (extensions, app, router, store, config, ssrContext = null) {
for (let extEntryPoint of extensions) {
if (extEntryPoint !== null) {
if (extEntryPoint.default) extEntryPoint = extEntryPoint.default
let extDescriptor = extEntryPoint(app, router, store, config, ssrContext) // register module
if (extDescriptor != null) {
export function registerExtensions (extensions, app, router, store, config, ssrContext = null) {
for (let extEntryPoint of extensions) {
if (extEntryPoint !== null) {
if (extEntryPoint.default) extEntryPoint = extEntryPoint.default
let extDescriptor = extEntryPoint(app, router, store, config, ssrContext) // register module
if (extDescriptor != null) {
Logger.warn('Extension' + extDescriptor.EXTENSION_KEY + ' registered. Extensions are depreciated and will be removed from VS core. Use modules instead')()
app.$emit('application-after-registerExtensions', extDescriptor)
}
}
}
}
app.$emit('application-after-registerExtensions', extDescriptor)
}
}
}
}
3 changes: 2 additions & 1 deletion core/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import rootStore from '@vue-storefront/store'
import SearchQuery from '@vue-storefront/core/lib/search/searchQuery'
import { remove as removeAccents } from 'remove-accents'
import { Logger } from '@vue-storefront/core/lib/logger'

/**
* Create slugify -> "create-slugify" permalink of text
Expand Down Expand Up @@ -151,7 +152,7 @@ export function once (key, fn) {
const { process = {} } = global
const processKey = key + '__ONCE__'
if (!process.hasOwnProperty(processKey)) {
console.debug(`Once ${key}`)
Logger.debug(`Once ${key}`, 'helper')()
process[processKey] = true
fn()
}
Expand Down
3 changes: 2 additions & 1 deletion core/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import config from 'config'
import { Logger } from '@vue-storefront/core/lib/logger'

Vue.use(VueI18n)

Expand All @@ -27,7 +28,7 @@ export function loadLanguageAsync (lang: string): Promise<string> {
loadedLanguages.push(lang)
return setI18nLanguage(lang)
}).catch(err => {
console.debug('Unable to load translation')
Logger.debug('Unable to load translation')()
return ''
})
}
Expand Down
4 changes: 2 additions & 2 deletions core/lib/asyncdataloader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isServer } from '@vue-storefront/core/helpers'
import { Logger } from './logger'
import { Logger } from '@vue-storefront/core/lib/logger'

const DEFAULT_ACTION_CATEGORY = 'asyncData'
// Data loader queues all the data fetching operations and runs them at once - to be usedf for example in the `asyncData()` functions
Expand Down Expand Up @@ -44,4 +44,4 @@ const AsyncDataLoader = {
}
}

export { AsyncDataLoader, AsyncDataLoaderActionContext, AsyncDataLoaderAction }
export { AsyncDataLoader, AsyncDataLoaderActionContext, AsyncDataLoaderAction }
Loading