Skip to content

Commit

Permalink
Merge pull request #269 from garden-io/logger-refactor
Browse files Browse the repository at this point in the history
refactor(logger): clean up code + enable empty log entries
  • Loading branch information
edvald committed Sep 12, 2018
2 parents 250d408 + a83117a commit b7d03cf
Show file tree
Hide file tree
Showing 38 changed files with 480 additions and 517 deletions.
6 changes: 3 additions & 3 deletions garden-cli/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import { getUrlChecksum } from "../support/support-util"
import * as Bluebird from "bluebird"
import { GitHandler } from "./src/vcs/git"
import { Garden } from "./src/garden"
import { RootLogNode } from "./src/logger/logger"
import { LogLevel } from "./src/logger/types"
import { Logger } from "./src/logger/logger"
import { LogLevel } from "./src/logger/log-node"
import execa = require("execa")

const gulp = require("gulp")
Expand Down Expand Up @@ -90,7 +90,7 @@ process.on("SIGTERM", die)

// make sure logger is initialized
try {
RootLogNode.initialize({ level: LogLevel.info })
Logger.initialize({ level: LogLevel.info })
} catch (_) { }

gulp.task("add-version-files", async () => {
Expand Down
12 changes: 6 additions & 6 deletions garden-cli/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import {
} from "../exceptions"
import { Garden, ContextOpts } from "../garden"

import { RootLogNode, getLogger } from "../logger/logger"
import { LogLevel, LoggerType } from "../logger/types"
import { Logger, LoggerType, getLogger } from "../logger/logger"
import { LogLevel } from "../logger/log-node"
import { BasicTerminalWriter } from "../logger/writers/basic-terminal-writer"
import { FancyTerminalWriter } from "../logger/writers/fancy-terminal-writer"
import { FileWriter } from "../logger/writers/file-writer"
Expand Down Expand Up @@ -137,7 +137,7 @@ export interface ParseResults {

interface SywacParseResults extends ParseResults {
output: string
details: { logger: RootLogNode, result?: CommandResult }
details: { logger: Logger, result?: CommandResult }
}

export class GardenCli {
Expand Down Expand Up @@ -223,7 +223,7 @@ export class GardenCli {
}
}

const logger = RootLogNode.initialize({ level, writers })
const logger = Logger.initialize({ level, writers })
let garden: Garden
let result
do {
Expand Down Expand Up @@ -275,7 +275,7 @@ export class GardenCli {
const { result: commandResult } = details
const { output } = argv
let { code } = parseResult
let logger
let logger: Logger

// Note: Circumvents an issue where the process exits before the output is fully flushed.
// Needed for output renderers and Winston (see: https://github.com/winstonjs/winston/issues/228)
Expand All @@ -285,7 +285,7 @@ export class GardenCli {
try {
logger = getLogger()
} catch (_) {
logger = RootLogNode.initialize({
logger = Logger.initialize({
level: LogLevel.info,
writers: [new BasicTerminalWriter()],
})
Expand Down
2 changes: 1 addition & 1 deletion garden-cli/src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "../exceptions"
import { PluginContext } from "../plugin-context"
import { TaskResults } from "../task-graph"
import { LoggerType } from "../logger/types"
import { LoggerType } from "../logger/logger"
import { ProcessResults } from "../process"
import { Garden } from "../garden"

Expand Down
3 changes: 1 addition & 2 deletions garden-cli/src/commands/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
} from "./base"
import { splitFirst } from "../util/util"
import { ParameterError, RuntimeError } from "../exceptions"
import { EntryStyle } from "../logger/types"
import { pick, find } from "lodash"
import { ServiceEndpoint, getEndpointUrl } from "../types/service"
import dedent = require("dedent")
Expand Down Expand Up @@ -123,7 +122,7 @@ export class CallCommand extends Command<typeof callArgs> {

const entry = ctx.log.info({
msg: chalk.cyan(`Sending ${matchedEndpoint.protocol.toUpperCase()} GET request to `) + url + "\n",
entryStyle: EntryStyle.activity,
status: "active",
})

// this is to accept self-signed certs
Expand Down
5 changes: 2 additions & 3 deletions garden-cli/src/commands/create/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import {
import { join } from "path"
import { pathExists } from "fs-extra"
import { validate } from "../../config/common"
import { EntryStyle } from "../../logger/types"
import { LogNode } from "../../logger/logger"
import { dumpYaml } from "../../util/util"
import { MODULE_CONFIG_FILENAME } from "../../constants"
import { LogNode } from "../../logger/log-node"

export function prepareNewModuleConfig(name: string, type: ModuleType, path: string): ModuleConfigOpts {
const moduleTypeTemplate = {
Expand All @@ -48,7 +47,7 @@ export async function dumpConfig(configOpts: ConfigOpts, schema: Joi.Schema, log
const yamlPath = join(path, MODULE_CONFIG_FILENAME)
const task = logger.info({
msg: `Writing config for ${name}`,
entryStyle: EntryStyle.activity,
status: "active",
})

if (await pathExists(yamlPath)) {
Expand Down
3 changes: 1 addition & 2 deletions garden-cli/src/commands/create/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
PathsParameter,
} from "../base"
import { GardenBaseError } from "../../exceptions"
import { EntryStyle } from "../../logger/types"
import {
prepareNewModuleConfig,
dumpConfig,
Expand Down Expand Up @@ -130,7 +129,7 @@ export class CreateProjectCommand extends Command<typeof createProjectArguments,
}

ctx.log.info("---------")
const task = ctx.log.info({ msg: "Setting up project", entryStyle: EntryStyle.activity })
const task = ctx.log.info({ msg: "Setting up project", status: "active" })

for (const module of moduleConfigs) {
await ensureDir(module.path)
Expand Down
2 changes: 1 addition & 1 deletion garden-cli/src/commands/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import chalk from "chalk"
import { LoggerType } from "../logger/types"
import { LoggerType } from "../logger/logger"
import { ExecInServiceResult } from "../types/plugin/outputs"
import {
Command,
Expand Down
3 changes: 1 addition & 2 deletions garden-cli/src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
CommandResult,
CommandParams,
} from "./base"
import { EntryStyle } from "../logger/types"
import { LoginStatusMap } from "../types/plugin/outputs"
import dedent = require("dedent")

Expand All @@ -29,7 +28,7 @@ export class LoginCommand extends Command {

async action({ ctx }: CommandParams): Promise<CommandResult<LoginStatusMap>> {
ctx.log.header({ emoji: "unlock", command: "Login" })
ctx.log.info({ msg: "Logging in...", entryStyle: EntryStyle.activity })
ctx.log.info({ msg: "Logging in...", status: "active" })

const result = await ctx.login({})

Expand Down
3 changes: 1 addition & 2 deletions garden-cli/src/commands/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
CommandResult,
CommandParams,
} from "./base"
import { EntryStyle } from "../logger/types"
import { LoginStatusMap } from "../types/plugin/outputs"
import dedent = require("dedent")

Expand All @@ -29,7 +28,7 @@ export class LogoutCommand extends Command {

ctx.log.header({ emoji: "lock", command: "Logout" })

const entry = ctx.log.info({ msg: "Logging out...", entryStyle: EntryStyle.activity })
const entry = ctx.log.info({ msg: "Logging out...", status: "active" })

const result = await ctx.logout({})

Expand Down
2 changes: 1 addition & 1 deletion garden-cli/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ServiceLogEntry } from "../types/plugin/outputs"
import Bluebird = require("bluebird")
import { Service } from "../types/service"
import Stream from "ts-stream"
import { LoggerType } from "../logger/types"
import { LoggerType } from "../logger/logger"
import dedent = require("dedent")

export const logsArgs = {
Expand Down
10 changes: 5 additions & 5 deletions garden-cli/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import {
} from "./task-graph"
import {
getLogger,
RootLogNode,
Logger,
} from "./logger/logger"
import {
pluginActionNames,
Expand Down Expand Up @@ -105,8 +105,8 @@ import {
} from "./util/ext-source-util"
import { BuildDependencyConfig, ModuleConfig } from "./config/module"
import { ProjectConfigContext, ModuleConfigContext } from "./config/config-context"
import { LogLevel } from "./logger/types"
import { FileWriter } from "./logger/writers/file-writer"
import { LogLevel } from "./logger/log-node"

export interface ActionHandlerMap<T extends keyof PluginActions> {
[actionName: string]: PluginActions[T]
Expand All @@ -133,7 +133,7 @@ export type ModuleActionMap = {
export interface ContextOpts {
config?: GardenConfig,
env?: string,
logger?: RootLogNode,
logger?: Logger,
plugins?: RegisterPluginParam[],
}

Expand All @@ -146,7 +146,7 @@ const fileWriterConfigs = [
]

export class Garden {
public readonly log: RootLogNode
public readonly log: Logger
public readonly actionHandlers: PluginActionMap
public readonly moduleActionHandlers: ModuleActionMap

Expand All @@ -171,7 +171,7 @@ export class Garden {
public readonly environmentConfig: EnvironmentConfig,
public readonly projectSources: SourceConfig[] = [],
public readonly buildDir: BuildDir,
logger?: RootLogNode,
logger?: Logger,
) {
this.modulesScanned = false
this.log = logger || getLogger()
Expand Down
Loading

0 comments on commit b7d03cf

Please sign in to comment.