mirror of https://github.com/sbt/sbt.git
Move GlobalLogBacking.newLogger to GlobalLogging to make the role of GlobalLogBacking clearer.
This commit is contained in:
parent
6350a4b51d
commit
0cf702efd5
|
|
@ -49,7 +49,7 @@ object MainLoop
|
||||||
def runWithNewLog(state: State, logBacking: GlobalLogBacking): RunNext =
|
def runWithNewLog(state: State, logBacking: GlobalLogBacking): RunNext =
|
||||||
Using.fileWriter(append = true)(logBacking.file) { writer =>
|
Using.fileWriter(append = true)(logBacking.file) { writer =>
|
||||||
val out = new java.io.PrintWriter(writer)
|
val out = new java.io.PrintWriter(writer)
|
||||||
val loggedState = state.copy(globalLogging = logBacking.newLogger(out, logBacking))
|
val loggedState = state.copy(globalLogging = state.globalLogging.newLogger(out, logBacking))
|
||||||
try run(loggedState) finally out.close()
|
try run(loggedState) finally out.close()
|
||||||
}
|
}
|
||||||
sealed trait RunNext
|
sealed trait RunNext
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ object StandardMain
|
||||||
val console = ConsoleOut.systemOutOverwrite(ConsoleOut.overwriteContaining("Resolving "))
|
val console = ConsoleOut.systemOutOverwrite(ConsoleOut.overwriteContaining("Resolving "))
|
||||||
|
|
||||||
def initialGlobalLogging: GlobalLogging =
|
def initialGlobalLogging: GlobalLogging =
|
||||||
GlobalLogging.initial((pw, glb) => MainLogging.globalDefault(pw,glb,console), File.createTempFile("sbt",".log"), console)
|
GlobalLogging.initial(MainLogging.globalDefault(console), File.createTempFile("sbt",".log"), console)
|
||||||
|
|
||||||
def initialState(configuration: xsbti.AppConfiguration, initialDefinitions: Seq[Command], preCommands: Seq[String]): State =
|
def initialState(configuration: xsbti.AppConfiguration, initialDefinitions: Seq[Command], preCommands: Seq[String]): State =
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,39 +10,34 @@ package sbt
|
||||||
* `full` is the current global logger. It should not be set directly because it is generated as needed from `backing.newLogger`.
|
* `full` is the current global logger. It should not be set directly because it is generated as needed from `backing.newLogger`.
|
||||||
* `console` is where all logging from all ConsoleLoggers should go.
|
* `console` is where all logging from all ConsoleLoggers should go.
|
||||||
* `backed` is the Logger that other loggers should feed into.
|
* `backed` is the Logger that other loggers should feed into.
|
||||||
* `backing` tracks the files that persist the global logging. */
|
* `backing` tracks the files that persist the global logging.
|
||||||
final case class GlobalLogging(full: Logger, console: ConsoleOut, backed: AbstractLogger, backing: GlobalLogBacking)
|
* `newLogger` creates a new global logging configuration from a sink and backing configuration.
|
||||||
|
*/
|
||||||
|
final case class GlobalLogging(full: Logger, console: ConsoleOut, backed: AbstractLogger, backing: GlobalLogBacking, newLogger: (PrintWriter, GlobalLogBacking) => GlobalLogging)
|
||||||
|
|
||||||
/** Tracks the files that persist the global logging.
|
/** Tracks the files that persist the global logging.
|
||||||
* `file` is the current backing file. `last` is the previous backing file, if there is one.
|
* `file` is the current backing file. `last` is the previous backing file, if there is one.
|
||||||
* `newLogger` creates a new global logging configuration from a sink and backing configuration.
|
|
||||||
* `newBackingFile` creates a new temporary location for the next backing file. */
|
* `newBackingFile` creates a new temporary location for the next backing file. */
|
||||||
final case class GlobalLogBacking(file: File, last: Option[File], newLogger: (PrintWriter, GlobalLogBacking) => GlobalLogging, newBackingFile: () => File)
|
final case class GlobalLogBacking(file: File, last: Option[File], newBackingFile: () => File)
|
||||||
{
|
{
|
||||||
/** Shifts the current backing file to `last` and sets the current backing to `newFile`. */
|
/** Shifts the current backing file to `last` and sets the current backing to `newFile`. */
|
||||||
def shift(newFile: File) = GlobalLogBacking(newFile, Some(file), newLogger, newBackingFile)
|
def shift(newFile: File) = GlobalLogBacking(newFile, Some(file), newBackingFile)
|
||||||
|
|
||||||
/** Shifts the current backing file to `last` and sets the current backing to a new temporary file generated by `newBackingFile`. */
|
/** Shifts the current backing file to `last` and sets the current backing to a new temporary file generated by `newBackingFile`. */
|
||||||
def shiftNew() = shift(newBackingFile())
|
def shiftNew() = shift(newBackingFile())
|
||||||
|
|
||||||
/** If there is a previous backing file in `last`, that becomes the current backing file and the previous backing is cleared.
|
/** If there is a previous backing file in `last`, that becomes the current backing file and the previous backing is cleared.
|
||||||
* Otherwise, no changes are made. */
|
* Otherwise, no changes are made. */
|
||||||
def unshift = GlobalLogBacking(last getOrElse file, None, newLogger, newBackingFile)
|
def unshift = GlobalLogBacking(last getOrElse file, None, newBackingFile)
|
||||||
}
|
}
|
||||||
object GlobalLogBacking
|
object GlobalLogBacking {
|
||||||
{
|
def apply(newBackingFile: => File): GlobalLogBacking = GlobalLogBacking(newBackingFile, None, newBackingFile _)
|
||||||
def apply(newLogger: (PrintWriter, GlobalLogBacking) => GlobalLogging, newBackingFile: => File): GlobalLogBacking =
|
|
||||||
GlobalLogBacking(newBackingFile, None, newLogger, newBackingFile _)
|
|
||||||
}
|
}
|
||||||
object GlobalLogging
|
object GlobalLogging
|
||||||
{
|
{
|
||||||
@deprecated("Explicitly specify standard out.", "0.13.0")
|
|
||||||
def initial(newLogger: (PrintWriter, GlobalLogBacking) => GlobalLogging, newBackingFile: => File): GlobalLogging =
|
|
||||||
initial(newLogger, newBackingFile, ConsoleOut.systemOut)
|
|
||||||
|
|
||||||
def initial(newLogger: (PrintWriter, GlobalLogBacking) => GlobalLogging, newBackingFile: => File, console: ConsoleOut): GlobalLogging =
|
def initial(newLogger: (PrintWriter, GlobalLogBacking) => GlobalLogging, newBackingFile: => File, console: ConsoleOut): GlobalLogging =
|
||||||
{
|
{
|
||||||
val log = ConsoleLogger(console)
|
val log = ConsoleLogger(console)
|
||||||
GlobalLogging(log, console, log, GlobalLogBacking(newLogger, newBackingFile))
|
GlobalLogging(log, console, log, GlobalLogBacking(newBackingFile), newLogger)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,15 +18,14 @@ object MainLogging
|
||||||
multi: Logger
|
multi: Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
@deprecated("Explicitly specify the console output.", "0.13.0")
|
def globalDefault(console: ConsoleOut): (PrintWriter, GlobalLogBacking) => GlobalLogging =
|
||||||
def globalDefault(writer: PrintWriter, backing: GlobalLogBacking): GlobalLogging =
|
|
||||||
globalDefault(writer, backing, ConsoleOut.systemOut)
|
|
||||||
|
|
||||||
def globalDefault(writer: PrintWriter, backing: GlobalLogBacking, console: ConsoleOut): GlobalLogging =
|
|
||||||
{
|
{
|
||||||
val backed = defaultBacked()(writer)
|
lazy val f: (PrintWriter, GlobalLogBacking) => GlobalLogging = (writer, backing) => {
|
||||||
val full = multiLogger(defaultMultiConfig(console, backed ) )
|
val backed = defaultBacked()(writer)
|
||||||
GlobalLogging(full, console, backed, backing)
|
val full = multiLogger(defaultMultiConfig(console, backed ) )
|
||||||
|
GlobalLogging(full, console, backed, backing, f)
|
||||||
|
}
|
||||||
|
f
|
||||||
}
|
}
|
||||||
|
|
||||||
@deprecated("Explicitly specify the console output.", "0.13.0")
|
@deprecated("Explicitly specify the console output.", "0.13.0")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue