mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	| @@ -299,7 +299,7 @@ func (cc *hugoBuilderCommon) handleFlags(cmd *cobra.Command) { | |||||||
| 	cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date and author info to the pages") | 	cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date and author info to the pages") | ||||||
| 	cmd.Flags().BoolVar(&cc.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build") | 	cmd.Flags().BoolVar(&cc.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build") | ||||||
| 	cmd.Flags().StringVar(&cc.poll, "poll", "", "set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes") | 	cmd.Flags().StringVar(&cc.poll, "poll", "", "set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes") | ||||||
|  | 	cmd.Flags().BoolVar(&loggers.PanicOnWarning, "panicOnWarning", false, "panic on first WARNING log") | ||||||
| 	cmd.Flags().Bool("templateMetrics", false, "display metrics about template executions") | 	cmd.Flags().Bool("templateMetrics", false, "display metrics about template executions") | ||||||
| 	cmd.Flags().Bool("templateMetricsHints", false, "calculate some improvement hints when combined with --templateMetrics") | 	cmd.Flags().Bool("templateMetricsHints", false, "calculate some improvement hints when combined with --templateMetrics") | ||||||
| 	cmd.Flags().BoolP("forceSyncStatic", "", false, "copy all files when static is changed.") | 	cmd.Flags().BoolP("forceSyncStatic", "", false, "copy all files when static is changed.") | ||||||
|   | |||||||
| @@ -68,7 +68,7 @@ func newSystemErrorF(format string, a ...interface{}) commandError { | |||||||
| // Catch some of the obvious user errors from Cobra. | // Catch some of the obvious user errors from Cobra. | ||||||
| // We don't want to show the usage message for every error. | // We don't want to show the usage message for every error. | ||||||
| // The below may be to generic. Time will show. | // The below may be to generic. Time will show. | ||||||
| var userErrorRegexp = regexp.MustCompile("argument|flag|shorthand") | var userErrorRegexp = regexp.MustCompile("unknown flag") | ||||||
|  |  | ||||||
| func isUserError(err error) bool { | func isUserError(err error) bool { | ||||||
| 	if cErr, ok := err.(commandError); ok && cErr.isUserError() { | 	if cErr, ok := err.(commandError); ok && cErr.isUserError() { | ||||||
|   | |||||||
| @@ -29,8 +29,11 @@ import ( | |||||||
| 	jww "github.com/spf13/jwalterweatherman" | 	jww "github.com/spf13/jwalterweatherman" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // Counts ERROR logs to the global jww logger. | var ( | ||||||
| var GlobalErrorCounter *jww.Counter | 	// Counts ERROR logs to the global jww logger. | ||||||
|  | 	GlobalErrorCounter *jww.Counter | ||||||
|  | 	PanicOnWarning     bool | ||||||
|  | ) | ||||||
|  |  | ||||||
| func init() { | func init() { | ||||||
| 	GlobalErrorCounter = &jww.Counter{} | 	GlobalErrorCounter = &jww.Counter{} | ||||||
| @@ -130,12 +133,20 @@ func (l *logger) Info() *log.Logger { | |||||||
| 	return l.INFO | 	return l.INFO | ||||||
| } | } | ||||||
|  |  | ||||||
|  | const panicOnWarningMessage = "Warning trapped. Remvove the --panicOnWarning flag to continue." | ||||||
|  |  | ||||||
| func (l *logger) Warnf(format string, v ...interface{}) { | func (l *logger) Warnf(format string, v ...interface{}) { | ||||||
| 	l.WARN.Printf(format, v...) | 	l.WARN.Printf(format, v...) | ||||||
|  | 	if PanicOnWarning { | ||||||
|  | 		panic(panicOnWarningMessage) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (l *logger) Warnln(v ...interface{}) { | func (l *logger) Warnln(v ...interface{}) { | ||||||
| 	l.WARN.Println(v...) | 	l.WARN.Println(v...) | ||||||
|  | 	if PanicOnWarning { | ||||||
|  | 		panic(panicOnWarningMessage) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (l *logger) Warn() *log.Logger { | func (l *logger) Warn() *log.Logger { | ||||||
|   | |||||||
| @@ -331,12 +331,14 @@ func (l *DistinctLogger) Warnf(format string, v ...interface{}) { | |||||||
| 		l.Logger.Warnf(format, v...) | 		l.Logger.Warnf(format, v...) | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (l *DistinctLogger) Warnln(v ...interface{}) { | func (l *DistinctLogger) Warnln(v ...interface{}) { | ||||||
| 	logStatement := fmt.Sprint(v...) | 	logStatement := fmt.Sprint(v...) | ||||||
| 	l.printIfNotPrinted("warnln", logStatement, func() { | 	l.printIfNotPrinted("warnln", logStatement, func() { | ||||||
| 		l.Logger.Warnln(v...) | 		l.Logger.Warnln(v...) | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (l *DistinctLogger) Errorf(format string, v ...interface{}) { | func (l *DistinctLogger) Errorf(format string, v ...interface{}) { | ||||||
| 	logStatement := fmt.Sprint(v...) | 	logStatement := fmt.Sprint(v...) | ||||||
| 	l.printIfNotPrinted("errorf", logStatement, func() { | 	l.printIfNotPrinted("errorf", logStatement, func() { | ||||||
| @@ -396,7 +398,6 @@ var ( | |||||||
| func InitLoggers() { | func InitLoggers() { | ||||||
| 	DistinctErrorLog.Reset() | 	DistinctErrorLog.Reset() | ||||||
| 	DistinctWarnLog.Reset() | 	DistinctWarnLog.Reset() | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // Deprecated informs about a deprecation, but only once for a given set of arguments' values. | // Deprecated informs about a deprecation, but only once for a given set of arguments' values. | ||||||
| @@ -408,7 +409,11 @@ func Deprecated(item, alternative string, err bool) { | |||||||
| 	if err { | 	if err { | ||||||
| 		DistinctErrorLog.Errorf("%s is deprecated and will be removed in Hugo %s. %s", item, hugo.CurrentVersion.Next().ReleaseVersion(), alternative) | 		DistinctErrorLog.Errorf("%s is deprecated and will be removed in Hugo %s. %s", item, hugo.CurrentVersion.Next().ReleaseVersion(), alternative) | ||||||
| 	} else { | 	} else { | ||||||
| 		DistinctWarnLog.Warnf("%s is deprecated and will be removed in a future release. %s", item, alternative) | 		var warnPanicMessage string | ||||||
|  | 		if !loggers.PanicOnWarning { | ||||||
|  | 			warnPanicMessage = "\n\nRe-run Hugo with the flag --panicOnWarning to get a better error message." | ||||||
|  | 		} | ||||||
|  | 		DistinctWarnLog.Warnf("%s is deprecated and will be removed in a future release. %s%s", item, alternative, warnPanicMessage) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user