Skip to content

Commit d8a832e

Browse files
author
Maxime Mangel
authored
Merge pull request #3723 from fable-compiler/fix_logging_version
Fix logging initialisation to allow `--version` to work
2 parents a3486b4 + dc2f8ef commit d8a832e

File tree

2 files changed

+54
-46
lines changed

2 files changed

+54
-46
lines changed

src/Fable.Cli/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
* [GH-3719](https://github.com/fable-compiler/Fable/issues/3719) Restore dependencies against the `.fsproj` after evaluating the `fable-temp.csproj` file (Improves IDE supports) (by @MangelMaxime)
1515
* Don't delete `fable_modules` when re-evaluating the project file after a changes has been detected (Improves HMR experience) (by @MangelMaxime)
1616

17+
### Fixed
18+
19+
#### All
20+
21+
* [GH-3723](https://github.com/fable-compiler/Fable/pull/3723) Fix logging initialisation to allow `--version` to work (by @MangelMaxime)
22+
1723
#### JavaScript
1824

1925
* [GH-3716](https://github.com/fable-compiler/Fable/pull/3716) System.Array.Resize: also handle the case where the array is null (by @chkn)

src/Fable.Cli/Entry.fs

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,35 @@ let getLibPkgVersion =
560560
| Dart
561561
| Php -> None
562562

563+
let private logPrelude commands language =
564+
match commands with
565+
| [ "--version" ] -> ()
566+
| _ ->
567+
let status =
568+
match getStatus language with
569+
| "stable"
570+
| "" -> ""
571+
| status -> $" (status: {status})"
572+
573+
Log.always (
574+
$"Fable {Literals.VERSION}: F# to {language} compiler{status}"
575+
)
576+
577+
match getLibPkgVersion language with
578+
| Some(repository, pkgName, version) ->
579+
Log.always (
580+
$"Minimum {pkgName} version (when installed from {repository}): {version}"
581+
)
582+
| None -> ()
583+
584+
Log.always (
585+
"\nThanks to the contributor! @" + Contributors.getRandom ()
586+
)
587+
588+
Log.always (
589+
"Stand with Ukraine! https://standwithukraine.com.ua/" + "\n"
590+
)
591+
563592
[<EntryPoint>]
564593
let main argv =
565594
result {
@@ -600,57 +629,30 @@ let main argv =
600629
| Some rootDir -> File.getExactFullPath rootDir
601630
| None -> IO.Directory.GetCurrentDirectory()
602631

603-
let verbosity =
632+
let level, verbosity =
604633
match commands with
605-
| [ "--version" ] -> Verbosity.Normal
634+
| [ "--version" ] -> LogLevel.Information, Verbosity.Normal
606635
| _ ->
607-
let verbosity =
608-
let level, verbosity =
609-
if args.FlagEnabled "--verbose" then
610-
LogLevel.Debug, Fable.Verbosity.Verbose
611-
else
612-
LogLevel.Information, Fable.Verbosity.Normal
613-
614-
use factory =
615-
LoggerFactory.Create(fun builder ->
616-
builder
617-
.SetMinimumLevel(level)
618-
.AddCustomConsole(fun options ->
619-
options.UseNoPrefixMsgStyle <- true
620-
)
621-
|> ignore
622-
)
623-
624-
Log.setLogger (factory.CreateLogger(""))
625-
verbosity
626-
627-
let status =
628-
match getStatus language with
629-
| "stable"
630-
| "" -> ""
631-
| status -> $" (status: {status})"
632-
633-
Log.always (
634-
$"Fable {Literals.VERSION}: F# to {language} compiler{status}"
635-
)
636-
637-
match getLibPkgVersion language with
638-
| Some(repository, pkgName, version) ->
639-
Log.always (
640-
$"Minimum {pkgName} version (when installed from {repository}): {version}"
636+
if args.FlagEnabled "--verbose" then
637+
LogLevel.Debug, Verbosity.Verbose
638+
else
639+
LogLevel.Information, Verbosity.Normal
640+
641+
// Initialize logging
642+
let factory =
643+
LoggerFactory.Create(fun builder ->
644+
builder
645+
.SetMinimumLevel(level)
646+
.AddCustomConsole(fun options ->
647+
options.UseNoPrefixMsgStyle <- true
641648
)
642-
| None -> ()
643-
644-
Log.always (
645-
"\nThanks to the contributor! @" + Contributors.getRandom ()
646-
)
649+
|> ignore
650+
)
647651

648-
Log.always (
649-
"Stand with Ukraine! https://standwithukraine.com.ua/"
650-
+ "\n"
651-
)
652+
Log.setLogger (factory.CreateLogger(""))
653+
factory.Dispose()
652654

653-
verbosity
655+
logPrelude commands language
654656

655657
match commands with
656658
| [ "--help" ] -> return printHelp ()

0 commit comments

Comments
 (0)