replace debug() with our custom logger
mostly we want trace() and log(). trace() can be enabled whenever we want by flipping a flag and restarting box
This commit is contained in:
@@ -4,7 +4,7 @@ import backupSites from './backupsites.js';
|
||||
import BoxError from './boxerror.js';
|
||||
import constants from './constants.js';
|
||||
import dashboard from './dashboard.js';
|
||||
import debugModule from 'debug';
|
||||
import logger from './logger.js';
|
||||
import domains from './domains.js';
|
||||
import dockerRegistries from './dockerregistries.js';
|
||||
import directoryServer from './directoryserver.js';
|
||||
@@ -23,7 +23,7 @@ import system from './system.js';
|
||||
import users from './users.js';
|
||||
import volumes from './volumes.js';
|
||||
|
||||
const debug = debugModule('box:appstore');
|
||||
const { log, trace } = logger('appstore');
|
||||
|
||||
// These are the default options and will be adjusted once a subscription state is obtained
|
||||
// Keep in sync with appstore/routes/cloudrons.js
|
||||
@@ -129,7 +129,7 @@ async function getSubscription() {
|
||||
if (!token) throw new BoxError(BoxError.LICENSE_ERROR, 'Missing token');
|
||||
|
||||
const [stateError, state] = await safe(getState());
|
||||
if (stateError) debug('getSubscription: error getting current state', stateError);
|
||||
if (stateError) log('getSubscription: error getting current state', stateError);
|
||||
|
||||
const [error, response] = await safe(superagent.post(`${await getApiServerOrigin()}/api/v1/subscription3`)
|
||||
.query({ accessToken: token })
|
||||
@@ -157,8 +157,8 @@ async function getSubscription() {
|
||||
// cron hook
|
||||
async function checkSubscription() {
|
||||
const [error, result] = await safe(getSubscription());
|
||||
if (error) debug('checkSubscription error:', error);
|
||||
else debug(`checkSubscription: Cloudron ${result.cloudronId} is on the ${result.plan.name} plan.`);
|
||||
if (error) log('checkSubscription error:', error);
|
||||
else log(`checkSubscription: Cloudron ${result.cloudronId} is on the ${result.plan.name} plan.`);
|
||||
}
|
||||
|
||||
function isFreePlan(subscription) {
|
||||
@@ -236,7 +236,7 @@ async function getAppUpdate(app, options) {
|
||||
|
||||
// do some sanity checks
|
||||
if (!safe.query(updateInfo, 'manifest.version') || semver.gt(curAppVersion, safe.query(updateInfo, 'manifest.version'))) {
|
||||
debug('Skipping malformed update of app %s version: %s. got %j', app.id, curAppVersion, updateInfo);
|
||||
log('Skipping malformed update of app %s version: %s. got %j', app.id, curAppVersion, updateInfo);
|
||||
throw new BoxError(BoxError.EXTERNAL_ERROR, `Malformed update: ${response.status} ${response.text}`);
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ async function updateCloudron(data) {
|
||||
if (response.status === 401) throw new BoxError(BoxError.LICENSE_ERROR, 'Invalid appstore token');
|
||||
if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `Bad response: ${response.status} ${response.text}`);
|
||||
|
||||
debug(`updateCloudron: Cloudron updated with data ${JSON.stringify(data)}`);
|
||||
log(`updateCloudron: Cloudron updated with data ${JSON.stringify(data)}`);
|
||||
}
|
||||
|
||||
async function registerCloudron3() {
|
||||
@@ -277,7 +277,7 @@ async function registerCloudron3() {
|
||||
|
||||
const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY);
|
||||
if (token) { // when installed using setupToken, this updates the domain record when called during provisioning
|
||||
debug('registerCloudron3: already registered. Just updating the record.');
|
||||
log('registerCloudron3: already registered. Just updating the record.');
|
||||
await getSubscription();
|
||||
return await updateCloudron({ domain, version });
|
||||
}
|
||||
@@ -296,7 +296,7 @@ async function registerCloudron3() {
|
||||
await settings.set(settings.CLOUDRON_ID_KEY, response.body.cloudronId);
|
||||
await settings.set(settings.APPSTORE_API_TOKEN_KEY, response.body.cloudronToken);
|
||||
|
||||
debug(`registerCloudron3: Cloudron registered with id ${response.body.cloudronId}`);
|
||||
log(`registerCloudron3: Cloudron registered with id ${response.body.cloudronId}`);
|
||||
|
||||
await getSubscription();
|
||||
}
|
||||
@@ -307,7 +307,7 @@ async function unregister() {
|
||||
}
|
||||
|
||||
async function unlinkAccount() {
|
||||
debug('unlinkAccount: Unlinking existing account.');
|
||||
log('unlinkAccount: Unlinking existing account.');
|
||||
|
||||
if (constants.DEMO) throw new BoxError(BoxError.BAD_STATE, 'Not allowed in demo mode');
|
||||
|
||||
@@ -326,7 +326,7 @@ async function downloadManifest(appStoreId, manifest) {
|
||||
|
||||
const url = await getApiServerOrigin() + '/api/v1/apps/' + id + (version ? '/versions/' + version : '');
|
||||
|
||||
debug(`downloading manifest from ${url}`);
|
||||
log(`downloading manifest from ${url}`);
|
||||
|
||||
const [error, response] = await safe(superagent.get(url).timeout(60 * 1000).ok(() => true));
|
||||
|
||||
@@ -388,7 +388,7 @@ async function getApp(appId) {
|
||||
async function downloadIcon(appStoreId, version) {
|
||||
const iconUrl = `${await getApiServerOrigin()}/api/v1/apps/${appStoreId}/versions/${version}/icon`;
|
||||
|
||||
return await promiseRetry({ times: 10, interval: 5000, debug }, async function () {
|
||||
return await promiseRetry({ times: 10, interval: 5000, debug: log }, async function () {
|
||||
const [networkError, response] = await safe(superagent.get(iconUrl)
|
||||
.timeout(60 * 1000)
|
||||
.ok(() => true));
|
||||
|
||||
Reference in New Issue
Block a user