feat(logger): add bunyan without DI
This commit is contained in:
parent
b2fac3494b
commit
25b375d6ac
|
@ -0,0 +1,11 @@
|
||||||
|
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||||
|
|
||||||
|
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [RemoteOptions](./cautious-journey.remoteoptions.md) > [logger](./cautious-journey.remoteoptions.logger.md)
|
||||||
|
|
||||||
|
## RemoteOptions.logger property
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
logger: Logger;
|
||||||
|
```
|
|
@ -16,5 +16,6 @@ export interface RemoteOptions
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| [data](./cautious-journey.remoteoptions.data.md) | Record<string, string> | Arbitrary key-value data for this remote, usually credentials and base URLs. |
|
| [data](./cautious-journey.remoteoptions.data.md) | Record<string, string> | Arbitrary key-value data for this remote, usually credentials and base URLs. |
|
||||||
| [dryrun](./cautious-journey.remoteoptions.dryrun.md) | boolean | If set, do not make any real changes. |
|
| [dryrun](./cautious-journey.remoteoptions.dryrun.md) | boolean | If set, do not make any real changes. |
|
||||||
|
| [logger](./cautious-journey.remoteoptions.logger.md) | Logger | |
|
||||||
| [type](./cautious-journey.remoteoptions.type.md) | string | Remote class/type name. |
|
| [type](./cautious-journey.remoteoptions.type.md) | string | Remote class/type name. |
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||||
|
|
||||||
|
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [SyncOptions](./cautious-journey.syncoptions.md) > [logger](./cautious-journey.syncoptions.logger.md)
|
||||||
|
|
||||||
|
## SyncOptions.logger property
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
logger: Logger;
|
||||||
|
```
|
|
@ -15,6 +15,7 @@ export interface SyncOptions
|
||||||
| Property | Type | Description |
|
| Property | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| [flags](./cautious-journey.syncoptions.flags.md) | Array<[FlagLabel](./cautious-journey.flaglabel.md)<!-- -->> | |
|
| [flags](./cautious-journey.syncoptions.flags.md) | Array<[FlagLabel](./cautious-journey.flaglabel.md)<!-- -->> | |
|
||||||
|
| [logger](./cautious-journey.syncoptions.logger.md) | Logger | |
|
||||||
| [project](./cautious-journey.syncoptions.project.md) | string | |
|
| [project](./cautious-journey.syncoptions.project.md) | string | |
|
||||||
| [remote](./cautious-journey.syncoptions.remote.md) | [Remote](./cautious-journey.remote.md) | |
|
| [remote](./cautious-journey.syncoptions.remote.md) | [Remote](./cautious-journey.remote.md) | |
|
||||||
| [states](./cautious-journey.syncoptions.states.md) | Array<[StateLabel](./cautious-journey.statelabel.md)<!-- -->> | |
|
| [states](./cautious-journey.syncoptions.states.md) | Array<[StateLabel](./cautious-journey.statelabel.md)<!-- -->> | |
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { LogLevel } from 'noicejs';
|
||||||
|
|
||||||
import { FlagLabel, StateLabel } from '../labels';
|
import { FlagLabel, StateLabel } from '../labels';
|
||||||
import { RemoteOptions } from '../remote';
|
import { RemoteOptions } from '../remote';
|
||||||
|
|
||||||
|
@ -5,6 +7,10 @@ import { RemoteOptions } from '../remote';
|
||||||
* Config data for the app, loaded from CLI or DOM.
|
* Config data for the app, loaded from CLI or DOM.
|
||||||
*/
|
*/
|
||||||
export interface ConfigData {
|
export interface ConfigData {
|
||||||
|
logger: {
|
||||||
|
level: LogLevel;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
projects: Array<{
|
projects: Array<{
|
||||||
/**
|
/**
|
||||||
* Color palette for labels without their own.
|
* Color palette for labels without their own.
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { constructorName } from '@apextoaster/js-utils';
|
||||||
|
import bunyan from 'bunyan';
|
||||||
|
import { Logger } from 'noicejs';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attach bunyan to the Logger. Does very little, since bunyan matches the Logger interface.
|
||||||
|
*/
|
||||||
|
export class BunyanLogger {
|
||||||
|
public static create(options: bunyan.LoggerOptions): Logger {
|
||||||
|
return bunyan.createLogger({
|
||||||
|
...options,
|
||||||
|
serializers: {
|
||||||
|
...bunyan.stdSerializers,
|
||||||
|
container: constructorName,
|
||||||
|
logger: constructorName,
|
||||||
|
module: constructorName,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
10
src/main.ts
10
src/main.ts
|
@ -6,6 +6,7 @@ import { join } from 'path';
|
||||||
|
|
||||||
import { ConfigData } from './config';
|
import { ConfigData } from './config';
|
||||||
import { Commands, createParser } from './config/args';
|
import { Commands, createParser } from './config/args';
|
||||||
|
import { BunyanLogger } from './logger/BunyanLogger';
|
||||||
import { GithubRemote } from './remote/github';
|
import { GithubRemote } from './remote/github';
|
||||||
import { syncIssues, syncLabels, SyncOptions } from './sync';
|
import { syncIssues, syncLabels, SyncOptions } from './sync';
|
||||||
import { VERSION_INFO } from './version';
|
import { VERSION_INFO } from './version';
|
||||||
|
@ -46,26 +47,27 @@ export async function main(argv: Array<string>): Promise<number> {
|
||||||
const parser = createParser((argMode) => mode = argMode as Commands);
|
const parser = createParser((argMode) => mode = argMode as Commands);
|
||||||
const args = parser.parse(argv.slice(SLICE_ARGS));
|
const args = parser.parse(argv.slice(SLICE_ARGS));
|
||||||
const config = await loadConfig(args.config);
|
const config = await loadConfig(args.config);
|
||||||
// TODO: create logger
|
const logger = BunyanLogger.create(config.logger);
|
||||||
|
|
||||||
/* eslint-disable-next-line no-console */
|
logger.info({
|
||||||
console.log({
|
|
||||||
args,
|
args,
|
||||||
config,
|
config,
|
||||||
mode,
|
mode,
|
||||||
version: VERSION_INFO,
|
version: VERSION_INFO,
|
||||||
});
|
}, 'startup environment');
|
||||||
|
|
||||||
for (const project of config.projects) {
|
for (const project of config.projects) {
|
||||||
const remote = new GithubRemote({
|
const remote = new GithubRemote({
|
||||||
...project.remote,
|
...project.remote,
|
||||||
dryrun: args.dryrun,
|
dryrun: args.dryrun,
|
||||||
|
logger,
|
||||||
});
|
});
|
||||||
await remote.connect();
|
await remote.connect();
|
||||||
|
|
||||||
// mode switch
|
// mode switch
|
||||||
const options: SyncOptions = {
|
const options: SyncOptions = {
|
||||||
flags: project.flags,
|
flags: project.flags,
|
||||||
|
logger,
|
||||||
project: project.name,
|
project: project.name,
|
||||||
remote,
|
remote,
|
||||||
states: project.states,
|
states: project.states,
|
||||||
|
|
|
@ -18,11 +18,11 @@ export class GithubRemote implements Remote {
|
||||||
constructor(options: RemoteOptions) {
|
constructor(options: RemoteOptions) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
/* eslint-disable-next-line */
|
options.logger.debug({ options }, 'github remote');
|
||||||
console.log('options:', options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async connect() {
|
public async connect() {
|
||||||
|
this.options.logger.info('connecting to github');
|
||||||
this.request = new Octokit({
|
this.request = new Octokit({
|
||||||
auth: {
|
auth: {
|
||||||
id: parseInt(mustExist(this.options.data.id), 10),
|
id: parseInt(mustExist(this.options.data.id), 10),
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { Logger } from 'noicejs';
|
||||||
|
|
||||||
export interface ProjectQuery {
|
export interface ProjectQuery {
|
||||||
project: string;
|
project: string;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +37,8 @@ export interface RemoteOptions {
|
||||||
*/
|
*/
|
||||||
dryrun: boolean;
|
dryrun: boolean;
|
||||||
|
|
||||||
|
logger: Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote class/type name.
|
* Remote class/type name.
|
||||||
*/
|
*/
|
||||||
|
|
24
src/sync.ts
24
src/sync.ts
|
@ -1,15 +1,14 @@
|
||||||
import { doesExist, mustExist } from '@apextoaster/js-utils';
|
import { doesExist, mustExist } from '@apextoaster/js-utils';
|
||||||
|
import { Logger } from 'noicejs';
|
||||||
|
|
||||||
import { FlagLabel, getLabelNames, StateLabel, valueName } from './labels';
|
import { FlagLabel, getLabelNames, StateLabel, valueName } from './labels';
|
||||||
import { LabelUpdate, Remote } from './remote';
|
import { LabelUpdate, Remote } from './remote';
|
||||||
import { resolveLabels } from './resolve';
|
import { resolveLabels } from './resolve';
|
||||||
import { defaultTo } from './utils';
|
import { defaultTo } from './utils';
|
||||||
|
|
||||||
// TODO: turn this back on/remove the disable pragma
|
|
||||||
/* eslint-disable no-console */
|
|
||||||
|
|
||||||
export interface SyncOptions {
|
export interface SyncOptions {
|
||||||
flags: Array<FlagLabel>;
|
flags: Array<FlagLabel>;
|
||||||
|
logger: Logger;
|
||||||
project: string;
|
project: string;
|
||||||
remote: Remote;
|
remote: Remote;
|
||||||
states: Array<StateLabel>;
|
states: Array<StateLabel>;
|
||||||
|
@ -21,7 +20,7 @@ export async function syncIssues(options: SyncOptions): Promise<unknown> {
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const issue of issues) {
|
for (const issue of issues) {
|
||||||
console.log('issue:', issue);
|
options.logger.info({ issue }, 'issue');
|
||||||
|
|
||||||
const resolution = resolveLabels({
|
const resolution = resolveLabels({
|
||||||
flags: options.flags,
|
flags: options.flags,
|
||||||
|
@ -31,7 +30,7 @@ export async function syncIssues(options: SyncOptions): Promise<unknown> {
|
||||||
|
|
||||||
// TODO: prompt user to update this particular issue
|
// TODO: prompt user to update this particular issue
|
||||||
if (resolution.changes.length > 0) {
|
if (resolution.changes.length > 0) {
|
||||||
console.log('updating issue:', issue, resolution);
|
options.logger.info({ issue, resolution }, 'updating issue');
|
||||||
await options.remote.updateIssue({
|
await options.remote.updateIssue({
|
||||||
...issue,
|
...issue,
|
||||||
labels: resolution.labels,
|
labels: resolution.labels,
|
||||||
|
@ -54,14 +53,19 @@ export async function syncLabels(options: SyncOptions): Promise<unknown> {
|
||||||
for (const label of combined) {
|
for (const label of combined) {
|
||||||
const exists = present.has(label);
|
const exists = present.has(label);
|
||||||
const expected = desired.has(label);
|
const expected = desired.has(label);
|
||||||
console.log('label:', label, exists, expected);
|
|
||||||
|
options.logger.info({
|
||||||
|
exists,
|
||||||
|
expected,
|
||||||
|
label,
|
||||||
|
}, 'label');
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
if (expected) {
|
if (expected) {
|
||||||
const data = mustExist(labels.find((l) => l.name === label));
|
const data = mustExist(labels.find((l) => l.name === label));
|
||||||
await syncSingleLabel(options, data);
|
await syncSingleLabel(options, data);
|
||||||
} else {
|
} else {
|
||||||
console.log('remove label:', label);
|
options.logger.warn({ label }, 'remove label');
|
||||||
await options.remote.deleteLabel({
|
await options.remote.deleteLabel({
|
||||||
name: label,
|
name: label,
|
||||||
project: options.project,
|
project: options.project,
|
||||||
|
@ -69,7 +73,7 @@ export async function syncLabels(options: SyncOptions): Promise<unknown> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (expected) {
|
if (expected) {
|
||||||
console.log('create label:', label);
|
options.logger.info({ label }, 'create label');
|
||||||
await createLabel(options, label);
|
await createLabel(options, label);
|
||||||
} else {
|
} else {
|
||||||
// skip
|
// skip
|
||||||
|
@ -122,11 +126,11 @@ export async function syncLabelDiff(options: SyncOptions, current: LabelUpdate,
|
||||||
project: options.project,
|
project: options.project,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('update label:', current, expected, body);
|
options.logger.debug({ body, current, expected }, 'update label');
|
||||||
|
|
||||||
const resp = await options.remote.updateLabel(body);
|
const resp = await options.remote.updateLabel(body);
|
||||||
|
|
||||||
console.log('update resp:', resp);
|
options.logger.debug({ resp }, 'update resp');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue