Skip to content

Commit

Permalink
chore(logger): cleanup as part of removing 'fancy' logger
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 committed Feb 18, 2023
1 parent 61ef901 commit 83b123a
Show file tree
Hide file tree
Showing 58 changed files with 506 additions and 427 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ orbs:
GARDEN_DISABLE_VERSION_CHECK: "true"
GARDEN_DISABLE_ANALYTICS: "true"
GARDEN_K8S_BUILD_SYNC_MODE: "mutagen"
GARDEN_LOGGER_TYPE: basic

shared-machine-config: &shared-machine-config
image: "ubuntu-2204:2022.10.2"
Expand Down Expand Up @@ -363,7 +362,7 @@ jobs:
- run:
name: Unit test framework components
command: |
GARDEN_LOGGER_TYPE="" yarn run test:framework:unit
yarn run test:framework:unit
environment:
CHOKIDAR_USEPOLLING: "1"
NODE_OPTIONS: --max_old_space_size=4096
Expand Down
4 changes: 1 addition & 3 deletions cli/src/add-version-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import { TreeCache } from "@garden-io/core/build/src/cache"
require("source-map-support").install()

// make sure logger is initialized
try {
Logger.initialize({ level: LogLevel.info, type: "quiet", storeEntries: false })
} catch (_) {}
Logger.initialize({ level: LogLevel.info, type: "quiet", storeEntries: false })

/**
* Write .garden-version files for modules in garden-system/static.
Expand Down
2 changes: 1 addition & 1 deletion cli/src/generate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ try {
type: "quiet",
storeEntries: false,
// level: LogLevel.debug,
// writers: [new BTerminalWriter()],
// writers: [new TerminalWriter()],
})
} catch (_) {}

Expand Down
17 changes: 10 additions & 7 deletions core/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ export async function makeDummyGarden(root: string, gardenOpts: GardenOpts) {
return DummyGarden.factory(root, { noEnterprise: true, ...gardenOpts })
}

function renderHeader({ environmentName, namespaceName, log }: { environmentName: string; namespaceName: string, log: Log }) {
function renderHeader({
environmentName,
namespaceName,
log,
}: {
environmentName: string
namespaceName: string
log: Log
}) {
const divider = chalk.gray(renderDivider())
let msg = `${printEmoji("🌍", log)} Running in namespace ${chalk.cyan(namespaceName)} in environment ${chalk.cyan(
environmentName
Expand Down Expand Up @@ -554,7 +562,6 @@ ${renderCommands(commands)}

async function done(abortCode: number, consoleOutput: string, result: any = {}) {
if (exitOnError) {
logger && logger.stop()
// eslint-disable-next-line no-console
console.log(consoleOutput)
await waitForOutputFlush()
Expand Down Expand Up @@ -685,7 +692,7 @@ ${renderCommands(commands)}
} catch (_) {
logger = Logger.initialize({
level: LogLevel.info,
type: "basic",
type: "default",
storeEntries: false,
})
}
Expand All @@ -696,10 +703,6 @@ ${renderCommands(commands)}
await waitForOutputFlush()
code = commandResult.exitCode || 1
}
if (exitOnError) {
logger.stop()
logger.cleanup()
}

if (this.bufferedEventStream) {
if (code === 0) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import { platform, release } from "os"
import qs from "qs"
import stringWidth from "string-width"
import { maxBy, zip } from "lodash"
import { Logger } from "../logger/logger"
import { Logger, formatGardenErrorWithDetail } from "../logger/logger"

import { ParameterValues, Parameter, Parameters } from "./params"
import { GardenBaseError, InternalError, ParameterError, toGardenError } from "../exceptions"
import { getPackageVersion, removeSlice } from "../util/util"
import { Log } from "../logger/log-entry"
import { STATIC_DIR, VERSION_CHECK_URL, gardenEnv, ERROR_LOG_FILENAME } from "../constants"
import { formatGardenErrorWithDetail, printWarningMessage } from "../logger/util"
import { printWarningMessage } from "../logger/util"
import { GlobalConfigStore } from "../config-store/global"
import { got } from "../util/http"
import minimist = require("minimist")
Expand Down
8 changes: 5 additions & 3 deletions core/src/cli/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,11 @@ export const globalOptions = {
choices: [...LOGGER_TYPES],
help: deline`
Set logger type.
${chalk.bold("fancy")} updates log lines in-place when their status changes (e.g. when tasks complete),
${chalk.bold("basic")} appends a new log line when a log line's status changes,
${chalk.bold("json")} same as basic, but renders log lines as JSON,
${chalk.bold("default")} The default Garden logger,
${chalk.bold(
"basic"
)} [DEPRECATED] Sames as the default Garden logger. This option will be removed in a future release,
${chalk.bold("json")} same as default, but renders log lines as JSON,
${chalk.bold("quiet")} suppresses all log output, same as --silent.
`,
cliOnly: true,
Expand Down
6 changes: 4 additions & 2 deletions core/src/cloud/buffered-event-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Bluebird from "bluebird"

import { Events, EventName, EventBus, pipedEventNames } from "../events"
import { LogEntryMetadata, Log, LogEntryMessage, LogEntry } from "../logger/log-entry"
import { LogEntryMetadata, Log, LogEntry } from "../logger/log-entry"
import { got } from "../util/http"

import { LogLevel } from "../logger/logger"
Expand All @@ -22,12 +22,14 @@ export type StreamEvent = {
timestamp: Date
}

type LogEntryMessage = Pick<LogEntry, "msg" | "section" | "symbol" | "data" | "dataFormat">

// TODO: Remove data, section, timestamp and msg once we've updated GE (it's included in the message)
export interface LogEntryEventPayload {
key: string
timestamp: string
level: LogLevel
message: Omit<LogEntryMessage, "timestamp">
message: LogEntryMessage
metadata?: LogEntryMetadata
}

Expand Down
3 changes: 1 addition & 2 deletions core/src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export abstract class Command<A extends Parameters = {}, O extends Parameters =
}

getLoggerType(_: CommandParamsBase<A, O>): LoggerType {
return "basic"
return "default"
}

describe() {
Expand Down Expand Up @@ -263,7 +263,6 @@ export abstract class Command<A extends Parameters = {}, O extends Parameters =
* @memberof Command
*/
async isAllowedToRun(garden: Garden, log: Log, opts: ParameterValues<GlobalOptions>): Promise<Boolean> {
log.root.stop()
if (!opts.yes && this.protected && garden.production) {
const defaultMessage = chalk.yellow(dedent`
Warning: you are trying to run "garden ${this.getFullName()}" against a production environment ([${
Expand Down
7 changes: 0 additions & 7 deletions core/src/commands/create/create-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { flatten, keyBy } from "lodash"
import { fixedPlugins } from "../../config/project"
import { deline, wordWrap, truncate } from "../../util/string"
import { joi } from "../../config/common"
import { LoggerType } from "../../logger/logger"
import Bluebird from "bluebird"
import { ModuleTypeMap } from "../../types/module"
import { Log } from "../../logger/log-entry"
Expand Down Expand Up @@ -91,10 +90,6 @@ export class CreateModuleCommand extends Command<CreateModuleArgs, CreateModuleO
arguments = createModuleArgs
options = createModuleOpts

getLoggerType(): LoggerType {
return "basic"
}

printHeader({ headerLog }) {
printHeader(headerLog, "Create new module", "pencil2")
}
Expand Down Expand Up @@ -127,8 +122,6 @@ export class CreateModuleCommand extends Command<CreateModuleArgs, CreateModuleO
const allModuleTypes = getModuleTypes(getSupportedPlugins().map((p) => p.callback()))

if (opts.interactive && (!opts.name || !opts.type)) {
log.root.stop()

if (!opts.type) {
const choices = await getModuleTypeSuggestions(log, allModuleTypes, configDir, name)

Expand Down
7 changes: 0 additions & 7 deletions core/src/commands/create/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { GardenBaseError, ParameterError } from "../../exceptions"
import { renderProjectConfigReference } from "../../docs/config"
import { addConfig } from "./helpers"
import { wordWrap } from "../../util/string"
import { LoggerType } from "../../logger/logger"
import { PathParameter, StringParameter, BooleanParameter, StringOption } from "../../cli/params"
import { userPrompt } from "../../util/util"

Expand Down Expand Up @@ -87,10 +86,6 @@ export class CreateProjectCommand extends Command<CreateProjectArgs, CreateProje
arguments = createProjectArgs
options = createProjectOpts

getLoggerType(): LoggerType {
return "basic"
}

printHeader({ headerLog }) {
printHeader(headerLog, "Create new project", "✏️")
}
Expand Down Expand Up @@ -124,8 +119,6 @@ export class CreateProjectCommand extends Command<CreateProjectArgs, CreateProje
let name = opts.name || basename(configDir)

if (opts.interactive && !opts.name) {
log.root.stop()

const answer = await userPrompt({
name: "name",
message: "Project name:",
Expand Down
5 changes: 0 additions & 5 deletions core/src/commands/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import chalk from "chalk"
import { LoggerType } from "../logger/logger"
import { printHeader } from "../logger/util"
import { Command, CommandResult, CommandParams } from "./base"
import dedent = require("dedent")
Expand Down Expand Up @@ -64,10 +63,6 @@ export class ExecCommand extends Command<Args, Opts> {

outputsSchema = () => execInDeployResultSchema()

getLoggerType(): LoggerType {
return "basic"
}

printHeader({ headerLog, args }) {
const serviceName = args.service
const command = this.getCommand(args)
Expand Down
3 changes: 2 additions & 1 deletion core/src/commands/get/get-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { StringsParameter, BooleanParameter } from "../../cli/params"
import { moduleSchema, GardenModule } from "../../types/module"
import { keyBy, omit, sortBy } from "lodash"
import { joiIdentifierMap, StringMap, createSchema } from "../../config/common"
import { printEmoji, printHeader, renderDivider, withoutInternalFields } from "../../logger/util"
import { printEmoji, printHeader, renderDivider } from "../../logger/util"
import { withoutInternalFields } from "../../logger/logger"
import chalk from "chalk"
import { renderTable, dedent, deline } from "../../util/string"
import { relative, sep } from "path"
Expand Down
3 changes: 2 additions & 1 deletion core/src/commands/get/get-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import { deline } from "../../util/string"
import { EnvironmentStatusMap } from "../../plugin/handlers/Provider/getEnvironmentStatus"
import { joi, joiIdentifierMap, joiStringMap } from "../../config/common"
import { environmentStatusSchema } from "../../config/status"
import { printHeader, sanitizeValue } from "../../logger/util"
import { printHeader } from "../../logger/util"
import { BuildStatusMap, getBuildStatusSchema } from "../../plugin/handlers/Build/get-status"
import { getTestResultSchema, TestStatusMap } from "../../plugin/handlers/Test/get-result"
import { getRunResultSchema, RunStatusMap } from "../../plugin/handlers/Run/get-result"
import { DeployStatusMap, getDeployStatusSchema } from "../../plugin/handlers/Deploy/get-status"
import { ActionRouter } from "../../router/router"
import { sanitizeValue } from "../../logger/logger"

// Value is "completed" if the test/task has been run for the current version.
export interface StatusCommandResult {
Expand Down
7 changes: 1 addition & 6 deletions core/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { every, some, sortBy } from "lodash"
import Bluebird = require("bluebird")
import { DeployLogEntry } from "../types/service"
import Stream from "ts-stream"
import { LoggerType, logLevelMap, LogLevel, parseLogLevel } from "../logger/logger"
import { logLevelMap, LogLevel, parseLogLevel } from "../logger/logger"
import { StringsParameter, BooleanParameter, IntegerParameter, DurationParameter, TagsOption } from "../cli/params"
import { printHeader, renderDivider } from "../logger/util"
import hasAnsi = require("has-ansi")
Expand Down Expand Up @@ -114,10 +114,6 @@ export class LogsCommand extends Command<Args, Opts> {

private events?: PluginEventBroker

getLoggerType(): LoggerType {
return "basic"
}

printHeader({ headerLog }) {
printHeader(headerLog, "Logs", "scroll")
}
Expand Down Expand Up @@ -185,7 +181,6 @@ export class LogsCommand extends Command<Args, Opts> {
log.info("")
log.info(chalk.white.bold("Service logs" + details + ":"))
log.info(chalk.white.bold(renderDivider()))
log.root.stop()

// Map all deploys names in the project to a specific color. This ensures
// that in most cases they have the same color (unless any have been added/removed),
Expand Down
5 changes: 0 additions & 5 deletions core/src/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { defaultDotIgnoreFile, findConfigPathsInPath } from "../util/fs"
import { GitHandler } from "../vcs/git"
import { DEFAULT_GARDEN_DIR_NAME } from "../constants"
import { exec, safeDumpYaml } from "../util/util"
import { LoggerType } from "../logger/logger"
import Bluebird from "bluebird"
import { loadAndValidateYaml, findProjectConfig } from "../config/base"
import { BooleanParameter, StringsParameter } from "../cli/params"
Expand Down Expand Up @@ -67,10 +66,6 @@ export class MigrateCommand extends Command<Args, Opts> {
`

getLoggerType(): LoggerType {
return "basic"
}

printHeader() {}

async action({ garden, log, args, opts }: CommandParams<Args, Opts>): Promise<CommandResult<MigrateCommandResult>> {
Expand Down
5 changes: 0 additions & 5 deletions core/src/commands/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { Garden } from "../garden"
import { Command, CommandResult, CommandParams } from "./base"
import Bluebird from "bluebird"
import { printHeader, getTerminalWidth } from "../logger/util"
import { LoggerType } from "../logger/logger"
import { StringOption } from "../cli/params"
import { ConfigGraph } from "../graph/config-graph"
import { ModuleGraph } from "../graph/modules"
Expand Down Expand Up @@ -61,10 +60,6 @@ export class PluginsCommand extends Command<Args> {

arguments = pluginArgs

getLoggerType(): LoggerType {
return "basic"
}

printHeader({ headerLog }) {
printHeader(headerLog, "Plugins", "gear")
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/commands/run-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import chalk from "chalk"
import { cloneDeep, flatten, last, repeat, size } from "lodash"
import { printHeader, getTerminalWidth, renderMessageWithDivider, formatGardenErrorWithDetail } from "../logger/util"
import { printHeader, getTerminalWidth, renderMessageWithDivider } from "../logger/util"
import { Command, CommandParams, CommandResult } from "./base"
import { dedent, wordWrap, deline } from "../util/string"
import { Garden } from "../garden"
Expand All @@ -28,7 +28,7 @@ import Bluebird from "bluebird"
import { getDurationMsec, toEnvVars } from "../util/util"
import { runScript } from "../util/util"
import { ExecaError } from "execa"
import { LogLevel } from "../logger/logger"
import { LogLevel, formatGardenErrorWithDetail } from "../logger/logger"
import { registerWorkflowRun } from "../cloud/workflow-lifecycle"
import { parseCliArgs, pickCommand, processCliArgs } from "../cli/helpers"
import { GlobalOptions, ParameterValues, StringParameter } from "../cli/params"
Expand Down
5 changes: 0 additions & 5 deletions core/src/commands/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Log } from "../logger/log-entry"
import { Garden, DummyGarden } from "../garden"
import { Command, CommandParams } from "./base"
import { getTerminalWidth } from "../logger/util"
import { LoggerType } from "../logger/logger"
import { ParameterError } from "../exceptions"
import { uniqByName, exec, shutdown } from "../util/util"
import { PluginTool } from "../util/ext-tools"
Expand Down Expand Up @@ -75,10 +74,6 @@ export class ToolsCommand extends Command<Args, Opts> {
arguments = toolsArgs
options = toolsOpts

getLoggerType(): LoggerType {
return "basic"
}

printHeader() {}

async prepare({ log }) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { BuildState } from "./plugin/handlers/Build/get-status"
import type { ActionReference } from "./config/common"
import type { GraphResult } from "./graph/results"
import { NamespaceStatus } from "./types/namespace"
import { sanitizeValue } from "./logger/util"
import { sanitizeValue } from "./logger/logger"

export type GardenEventListener<T extends EventName> = (payload: Events[T]) => void

Expand Down
3 changes: 2 additions & 1 deletion core/src/graph/solver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { GraphResult, GraphResults, resultToString, TaskEventBase } from "./resu
import { gardenEnv } from "../constants"
import type { Garden } from "../garden"
import { GraphResultEventPayload, toGraphResultEventPayload } from "../events"
import { formatGardenErrorWithDetail, renderDivider, renderMessageWithDivider } from "../logger/util"
import { renderDivider, renderMessageWithDivider } from "../logger/util"
import { formatGardenErrorWithDetail } from "../logger/logger"
import chalk from "chalk"
import {
CompleteTaskParams,
Expand Down
Loading

0 comments on commit 83b123a

Please sign in to comment.