Skip to content

Commit 44787ac

Browse files
authored
A4 (#85)
* removed dayjs, debuggified winston, removed bundledDependencies * this is a good commit * bump to latest @lando/prepare-release-action@v3 * fix tests * fix tests part 2
1 parent 36297a8 commit 44787ac

File tree

17 files changed

+238
-821
lines changed

17 files changed

+238
-821
lines changed

.github/workflows/pr-core-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- name: Install dependencies
5959
run: npm clean-install --prefer-offline --frozen-lockfile
6060
- name: Bundle Deps
61-
uses: lando/prepare-release-action@v2
61+
uses: lando/prepare-release-action@v3
6262
with:
6363
lando-plugin: true
6464
version: dev

.github/workflows/pr-plugin-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
- name: Install dependencies
6161
run: npm clean-install --prefer-offline --frozen-lockfile
6262
- name: Bundle Deps
63-
uses: lando/prepare-release-action@v2
63+
uses: lando/prepare-release-action@v3
6464
with:
6565
lando-plugin: true
6666
version: dev

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- ubuntu-20.04
1818
node-version:
1919
- "18"
20+
2021
steps:
2122
# Install deps and cache
2223
- name: Checkout code
@@ -36,7 +37,7 @@ jobs:
3637
- name: Run unit tests
3738
run: npm run test:unit
3839
- name: Prepare Release
39-
uses: lando/prepare-release-action@v2
40+
uses: lando/prepare-release-action@v3
4041
with:
4142
lando-plugin: true
4243

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
### Internal
2424

2525
* Added `app.addMessage` for more granular and accessible post-start app status reporting
26+
* Changed `lando.log` and `app.log` to be more like `debug`
2627
* Bumped minimum `node` version to `18`
27-
* Bumped supported Docker Desktop version to `>4 <4.26`
28+
* Bumped supported Docker Desktop version to `>4 <4.27`
2829
* Removed lingering and dangling should-now-be-in-plugins code eg `_drupaly.js`
2930
* Reorganized core to be more like `@lando/core-next` (eg Lando 4)
3031
* Switched (fully, finally) from `github` to `@octokit/rest`
3132
* Switched plugin package manager to `npm`
33+
* Removed `bundledDependencies` from `package.json`, now handled by `@lando/prepare-release-action@v3`
34+
* Removed `dayjs` dependency
3235
* Removed `github` dependency
3336
* Removed `mkdirp` dependency
3437

components/plugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class Plugin {
270270
async check4Update() {
271271
// if plugin is not updateable then immediately return
272272
if (!this.isUpdateable) {
273-
this.debug('%o is not updateable, update manually', this.name);
273+
this.debug('is not updateable, update manually');
274274
return this;
275275
}
276276

@@ -295,7 +295,7 @@ class Plugin {
295295

296296
// if the hv is lte to what we have then no update is available
297297
if (semver.lte(hv, this.version)) {
298-
this.debug('%o cannot be updated on channel %o (%o <= %o)', this.package, channel, hv, this.version);
298+
this.debug('cannot be updated on channel %o (%o <= %o)', this.package, channel, hv, this.version);
299299
return this;
300300

301301
// otherwise update is available
@@ -304,7 +304,7 @@ class Plugin {
304304
this.update = await Plugin.info(this.updateAvailable);
305305
this.update.channel = hc;
306306
this.debug(
307-
'%o can be updated to %o on channel %o (%o > %o) ',
307+
'can be updated to %o on channel %o (%o > %o) ',
308308
this.package,
309309
this.updateAvailable,
310310
channel,

examples/base/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ lando info -vv | grep VERBOSE || echo $? | grep 1
8787
lando info -vvv | grep DEBUG || echo $? | grep 1
8888
lando info -vvvv | grep SILLY || echo $? | grep 1
8989

90-
# Should run with specified verbosity on stderr
91-
lando info -v 2>&1 | grep INFO
92-
lando info -vv 2>&1 | grep VERBOSE
93-
lando info -vvv 2>&1 | grep DEBUG
94-
lando info -vvvv 2>&1 | grep SILLY
90+
# Should run all log levels on stderr
91+
lando info -v 2>&1 | grep lando | grep + | grep ms
92+
lando info -vv 2>&1 | grep lando | grep + | grep ms
93+
lando info -vvv 2>&1 | grep lando | grep + | grep ms
94+
lando info -vvvv 2>&1 | grep lando | grep + | grep ms
95+
lando info --debug 2>&1 | grep lando | grep + | grep ms
9596

9697
# Should run lando config without error
9798
lando config

hooks/app-check-for-updates.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
module.exports = async (app, lando) => {
44
if (lando.config.channel !== 'none' && !lando.cache.get('updates-2')) {
55
lando.log.debug('checking for updates...');
6+
// add the plugins and install dir
7+
const dir = lando.config.pluginDirs.find(dir => dir.type === require('../utils/get-plugin-type')());
8+
lando.updates.plugins = lando.config.plugins;
9+
lando.updates.dir = dir ? dir.dir : undefined;
10+
611
const tasks = await lando.updates.getUpdateTasks();
712
// next check in a day
813
const expires = Date.now() + 60 * 60 * 24 * 1000;

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ module.exports = async lando => {
8686
lando.events.on('almost-ready', 2, async () => await require('./hooks/lando-get-compat')(lando));
8787

8888
// throw error if engine/orchestrator is not available
89-
lando.events.on('engine-autostart', 1, async () => await require('./hooks/lando-dep-check')(lando));
89+
lando.events.once('pre-engine-autostart', async () => await require('./hooks/lando-dep-check')(lando));
9090

9191
// autostart docker if we need to
92-
lando.events.on('engine-autostart', 2, async () => await require('./hooks/lando-autostart-engine')(lando));
92+
lando.events.once('engine-autostart', async () => await require('./hooks/lando-autostart-engine')(lando));
9393

9494
// Make sure we have a host-exposed root ca if we don't already
9595
// NOTE: we don't run this on the caProject otherwise infinite loop happens!

lib/lando.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ const bootstrapConfig = async lando => {
8989
// log
9090
if (!_.isEmpty(removed)) lando.log.debug('removed duplicate plugin entries %o', removed);
9191

92-
// add the plugins and install dir
93-
const dir = lando.config.pluginDirs.find(dir => dir.type === require('../utils/get-plugin-type')());
94-
lando.updates.plugins = plugins;
95-
lando.updates.dir = dir ? dir.dir : undefined;
96-
9792
// he who remains
9893
return plugins;
9994
};

lib/logger.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
// Modules
44
const _ = require('lodash');
5-
const dayjs = require('dayjs');
65
const fs = require('fs');
76
const path = require('path');
87
const serialize = require('winston/lib/winston/common').serialize;
9-
const util = require('util');
108
const winston = require('winston');
9+
const util = require('util');
1110

1211
// Constants
1312
const logLevels = {
@@ -28,12 +27,10 @@ const logColors = {
2827
timestamp: 'magenta',
2928
lando: 'cyan',
3029
app: 'green',
30+
extra: 'dim',
3131
};
3232
const userLevels = ['warn', 'error'];
3333

34-
// Maxsize
35-
let fcw = 0;
36-
3734
// Rewriters
3835
const keySanitizer = sanitizeKey => (level, msg, meta) => {
3936
// start with a deep clone of meta so we dont mutate important underlying data
@@ -143,34 +140,44 @@ const keySanitizer = sanitizeKey => (level, msg, meta) => {
143140
* lando.log.warning('Something is up with app %s in directory %s', appName, dir);
144141
*/
145142
module.exports = class Log extends winston.Logger {
146-
constructor({logDir, logLevelConsole = 'warn', logLevel = 'debug', logName = 'lando'} = {}) {
143+
constructor({logDir, extra, logLevelConsole = 'warn', logLevel = 'debug', logName = 'lando'} = {}) {
147144
// If loglevelconsole is numeric lets map it!
148145
if (_.isInteger(logLevelConsole)) logLevelConsole = logLevels[logLevelConsole];
149146

150147
// The default console transport
151148
const transports = [
152149
new winston.transports.Console({
153-
timestamp: () => dayjs().format('HH:mm:ss'),
150+
timestamp: () => Date.now(),
154151
formatter: options => {
155152
// Get da prefixes
156153
const element = (logName === 'lando') ? 'lando' : logName;
157154
const elementColor = (logName === 'lando') ? 'lando' : 'app';
158-
// Set the leftmost column width
159-
fcw = _.max([fcw, _.size(element)]);
160-
// Default output
161-
const output = [
162-
winston.config.colorize(elementColor, _.padEnd(element.toLowerCase(), fcw)),
163-
winston.config.colorize('timestamp', options.timestamp()),
164-
winston.config.colorize(options.level, options.level.toUpperCase()),
165-
'==>',
166-
util.format(options.message),
167-
serialize(options.meta),
168-
];
169-
// If this is a warning or error and we aren't verbose then omit prefixes
155+
156+
// approximate debug mod timestamp
157+
const curr = Number(new Date());
158+
const ms = curr - (this.lasttime || curr);
159+
this.lasttime = curr;
160+
161+
// build useful things first
162+
const prefix = winston.config.colorize(elementColor, element.toLowerCase());
163+
const level = winston.config.colorize(options.level, options.level.toUpperCase());
164+
const msg = util.format(options.message);
165+
const meta = serialize(options.meta);
166+
const timestamp = winston.config.colorize(elementColor, `+${ms}ms`);
167+
168+
// If this is a warning or error and we aren't verbose then we have more "normal" output
170169
if (_.includes(userLevels, options.level) && _.includes(userLevels, logLevelConsole)) {
171-
return _.drop(output, 2).join(' ');
170+
return [level, '==>', msg].join(' ');
172171
}
173-
return output.join(' ');
172+
173+
// debug output
174+
const output = [prefix, msg, meta, timestamp];
175+
// if we have extra stuff
176+
if (typeof extra === 'string') output.splice(1, 0, winston.config.colorize('extra', extra.toLowerCase()));
177+
// if error or warning then try to make it more obvious by splicing in the level
178+
if (_.includes(userLevels, options.level)) output.splice(1, 0, level);
179+
// return
180+
return ` ${output.join(' ')}`;
174181
},
175182
label: logName,
176183
level: logLevelConsole,
@@ -204,10 +211,15 @@ module.exports = class Log extends winston.Logger {
204211
// Get the winston logger
205212
super({transports: transports, exitOnError: true, colors: logColors});
206213

214+
// set initial timestamp
215+
this.lasttime = Date.now();
207216
// Extend with special lando things
208217
this.sanitizedKeys = ['auth', 'token', 'password', 'key', 'api_key', 'secret', 'machine_token'];
209218
// Loop through our sanitizedKeys and add sanitation
210219
_.forEach(this.sanitizedKeys, key => this.rewriters.push(keySanitizer(key)));
220+
221+
// save the initial config for shiming
222+
this.shim = {logDir, extra, logLevelConsole, logLevel, logName};
211223
};
212224

213225
// Method to help other things add sanitizations

0 commit comments

Comments
 (0)