chore: add global logger
parent
5242e7ef52
commit
0440a33b65
|
|
@ -17,7 +17,9 @@
|
|||
"jest/globals": true
|
||||
},
|
||||
"globals": {
|
||||
"Deno": true
|
||||
"Deno": true,
|
||||
"log": true,
|
||||
"window": true
|
||||
},
|
||||
"rules": {
|
||||
// Error out for code formatting errors
|
||||
|
|
@ -62,6 +64,10 @@
|
|||
// Deno has dependencies file, this rule enforces it's named re-exports
|
||||
"unicorn/prevent-abbreviations": "off",
|
||||
// Allow disabling eslint per file
|
||||
"eslint-comments/no-use": "off"
|
||||
"eslint-comments/no-use": "off",
|
||||
// Deno import style
|
||||
"import/extensions": "off",
|
||||
// Deno import style
|
||||
"import/no-unresolved": "off"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,3 +5,4 @@ lib/
|
|||
.vsconfig
|
||||
yarn-error.log
|
||||
.orig
|
||||
*.log
|
||||
|
|
|
|||
29
package.json
29
package.json
|
|
@ -45,24 +45,25 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@arkweid/lefthook": "^0.7.7",
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/jest": "^28.1.6",
|
||||
"@types/node": "^18.6.4",
|
||||
"@types/semver": "^7.3.9",
|
||||
"@typescript-eslint/parser": "4.8.1",
|
||||
"@typescript-eslint/parser": "5.32.0",
|
||||
"@vercel/ncc": "^0.33.3",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "7.17.0",
|
||||
"eslint-config-prettier": "8.1.0",
|
||||
"eslint-plugin-github": "^4.1.1",
|
||||
"eslint-plugin-jest": "24.1.3",
|
||||
"eslint-plugin-prettier": "^3.3.1",
|
||||
"eslint-plugin-unicorn": "28.0.2",
|
||||
"jest": "^27.5.1",
|
||||
"jest-circus": "^27.5.1",
|
||||
"jest-fail-on-console": "^2.3.0",
|
||||
"eslint": "^8.21.0",
|
||||
"eslint-config-prettier": "8.5.0",
|
||||
"eslint-plugin-github": "4.3.7",
|
||||
"eslint-plugin-jest": "26.7.0",
|
||||
"eslint-plugin-prettier": "4.2.1",
|
||||
"eslint-plugin-unicorn": "43.0.2",
|
||||
"jest": "^28.1.3",
|
||||
"jest-circus": "^28.1.3",
|
||||
"jest-fail-on-console": "^2.4.2",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.5.1",
|
||||
"ts-jest": "^27.1.3",
|
||||
"prettier": "2.7.1",
|
||||
"ts-jest": "^28.0.7",
|
||||
"ts-node": "10.4.0",
|
||||
"typescript": "4.1.3"
|
||||
"typescript": "4.3.5"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
import { pad } from 'https://deno.land/std@0.36.0/strings/pad.ts';
|
||||
import { FormatterFunction } from 'https://deno.land/std@0.151.0/log/handlers.ts';
|
||||
import { LogRecord } from 'https://deno.land/std@0.151.0/log/logger.ts';
|
||||
|
||||
// See: https://github.com/denoland/deno_std/blob/0.151.0/log/README.md#custom-message-format
|
||||
export const createFormatter = ({
|
||||
showTime = false,
|
||||
showLogger = false,
|
||||
showLevel = false,
|
||||
showLevelName = true,
|
||||
showBrackets = true,
|
||||
depth = 3,
|
||||
} = {}): FormatterFunction => {
|
||||
const column = (value: string) => (showBrackets ? `[${value}]` : ` ${value}`);
|
||||
|
||||
return ({ level, levelName, msg, args, loggerName }: LogRecord) => {
|
||||
let line = '';
|
||||
|
||||
if (showLogger) {
|
||||
line += column(loggerName);
|
||||
}
|
||||
|
||||
if (showTime) {
|
||||
const now = new Date();
|
||||
const hours = pad(`${now.getHours()}`, 2, { char: '0' });
|
||||
const minutes = pad(`${now.getMinutes()}`, 2, { char: '0' });
|
||||
const seconds = pad(`${now.getSeconds()}`, 2, { char: '0' });
|
||||
const time = [hours, minutes, seconds].join(':');
|
||||
line += column(time);
|
||||
}
|
||||
|
||||
if (showLevelName) {
|
||||
const shortName = levelName.length <= 5 ? levelName : levelName.slice(0, 4);
|
||||
line += column(`${pad(shortName, 5, { side: 'left' })}`);
|
||||
}
|
||||
|
||||
if (showLevel) {
|
||||
line += column(level);
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
if (line.length > 0) line += ' ';
|
||||
line += msg;
|
||||
}
|
||||
|
||||
if (args) {
|
||||
if (line.length > 0) line += ' ';
|
||||
line += args
|
||||
.map((value) => {
|
||||
switch (typeof value) {
|
||||
case 'object':
|
||||
return Deno.inspect(value, { depth });
|
||||
case 'undefined':
|
||||
return 'undefined';
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
})
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
return line;
|
||||
};
|
||||
};
|
||||
|
||||
export const formatter = createFormatter();
|
||||
export const consoleFormatter = createFormatter();
|
||||
export const fileFormatter = createFormatter({ showTime: true, showLevel: true, showBrackets: false });
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
import * as log from 'https://deno.land/std@0.151.0/log/mod.ts';
|
||||
import { fileFormatter, consoleFormatter } from './formatter.ts';
|
||||
|
||||
// Handlers
|
||||
const consoleHandler = new log.handlers.ConsoleHandler('DEBUG', { formatter: consoleFormatter });
|
||||
const fileHandler = new log.handlers.FileHandler('WARNING', { filename: './game-ci.log', formatter: fileFormatter });
|
||||
|
||||
// Make sure it saves on Ctrl+C interrupt https://github.com/denoland/deno_std/issues/2193
|
||||
Deno.addSignalListener('SIGINT', () => fileHandler.flush());
|
||||
|
||||
await log.setup({
|
||||
handlers: {
|
||||
consoleHandler,
|
||||
fileHandler,
|
||||
},
|
||||
|
||||
loggers: {
|
||||
default: {
|
||||
level: 'DEBUG',
|
||||
handlers: ['consoleHandler', 'fileHandler'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Allows using `log.debug` and other methods directly from anywhere
|
||||
*
|
||||
* Example
|
||||
* log.debug('something', [{ a: { b: { c: { d: ['a', 'b'] } } } }], 'something', {
|
||||
* a: { b: { c: { d: { e: { f: { g: 'foo' } } } } } },
|
||||
* });
|
||||
*
|
||||
* Outputs:
|
||||
* [DEBUG] something [ { a: { b: [Object] } } ] something { a: { b: { c: [Object] } } }
|
||||
*/
|
||||
window.log = log.getLogger();
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable unicorn/prefer-export-from */
|
||||
// These are the packages from Deno that replace the ones from Node.
|
||||
import * as assert from 'https://deno.land/std@0.144.0/testing/asserts.ts';
|
||||
import * as aws from 'https://deno.land/x/aws_api/client/mod.ts';
|
||||
|
|
@ -15,6 +16,7 @@ import * as yaml from 'https://deno.land/std@0.145.0/encoding/yaml.ts';
|
|||
import { crypto } from 'https://deno.land/std@0.142.0/crypto/mod.ts';
|
||||
import { v4 as uuid } from 'https://deno.land/std@0.142.0/uuid/mod.ts';
|
||||
import * as http from 'https://deno.land/std@0.145.0/node/http.ts';
|
||||
import * as string from 'https://deno.land/std@0.36.0/strings/mod.ts';
|
||||
import { Command } from 'https://deno.land/x/cmd@v1.2.0/commander/index.ts';
|
||||
import { getUnityChangeset as getUnityChangeSet } from 'https://deno.land/x/unity_changeset@2.0.0/src/index.ts';
|
||||
|
||||
|
|
@ -57,6 +59,7 @@ export {
|
|||
path,
|
||||
process,
|
||||
semver,
|
||||
string,
|
||||
uuid,
|
||||
waitUntil,
|
||||
Writable,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
/* eslint-disable no-unused-vars */
|
||||
export type Level = 'debug' | 'info' | 'warn' | 'error' | 'critical';
|
||||
|
||||
declare global {
|
||||
const log: (level: Level, ...args: any[]) => void;
|
||||
|
||||
interface Window {
|
||||
log: any;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import './core/logger/index.ts';
|
||||
import { core, process } from './dependencies.ts';
|
||||
import { Action, BuildParameters, Cache, CloudRunner, Docker, ImageTag, Output } from './model/index.ts';
|
||||
import { Cli } from './model/cli/cli.ts';
|
||||
|
|
@ -7,6 +8,7 @@ import PlatformSetup from './model/platform-setup.ts';
|
|||
async function runMain() {
|
||||
try {
|
||||
if (Cli.InitCliMode()) {
|
||||
log.debug('CloudBuilder CLI mode');
|
||||
await Cli.RunCli();
|
||||
|
||||
return;
|
||||
|
|
@ -15,9 +17,13 @@ async function runMain() {
|
|||
Cache.verify();
|
||||
|
||||
const { workspace, actionFolder } = Action;
|
||||
log.debug('workspace', workspace, 'actionFolder', actionFolder);
|
||||
|
||||
const buildParameters = await BuildParameters.create();
|
||||
log.debug('buildParameters', buildParameters);
|
||||
|
||||
const baseImage = new ImageTag(buildParameters);
|
||||
log.debug('baseImage', baseImage);
|
||||
|
||||
if (buildParameters.cloudRunnerCluster !== 'local') {
|
||||
await CloudRunner.run(buildParameters, baseImage.toString());
|
||||
|
|
|
|||
|
|
@ -68,10 +68,15 @@ class BuildParameters {
|
|||
|
||||
static async create(): Promise<BuildParameters> {
|
||||
const buildFile = this.parseBuildFile(Input.buildName, Input.targetPlatform, Input.androidAppBundle);
|
||||
log.debug('buildFile:', buildFile);
|
||||
const editorVersion = UnityVersioning.determineUnityVersion(Input.projectPath, Input.unityVersion);
|
||||
log.debug('editorVersion:', editorVersion);
|
||||
const buildVersion = await Versioning.determineBuildVersion(Input.versioningStrategy, Input.specifiedVersion);
|
||||
log.debug('buildVersion', buildVersion);
|
||||
const androidVersionCode = AndroidVersioning.determineVersionCode(buildVersion, Input.androidVersionCode);
|
||||
log.debug('androidVersionCode', androidVersionCode);
|
||||
const androidSdkManagerParameters = AndroidVersioning.determineSdkManagerParameters(Input.androidTargetSdkVersion);
|
||||
log.debug('androidSdkManagerParameters', androidSdkManagerParameters);
|
||||
|
||||
// Todo - Don't use process.env directly, that's what the input model class is for.
|
||||
// ---
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { Command } from '../../dependencies.ts';
|
||||
import { BuildParameters, CloudRunner, ImageTag, Input } from '../index.ts';
|
||||
import { core } from '../../dependencies.ts';
|
||||
import { Command, core } from '../../dependencies.ts';
|
||||
import { ActionYamlReader } from '../input-readers/action-yaml.ts';
|
||||
import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger.ts';
|
||||
import CloudRunnerQueryOverride from '../cloud-runner/services/cloud-runner-query-override.ts';
|
||||
|
|
|
|||
Loading…
Reference in New Issue