File tree Expand file tree Collapse file tree 1 file changed +74
-0
lines changed
Expand file tree Collapse file tree 1 file changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ class Logger {
4+ constructor ( serverless , log ) {
5+ this . serverless = serverless ;
6+ this . logOutput = log ;
7+
8+ this . logTypes = {
9+ NOTICE : "notice" ,
10+ DEBUG : "debug" ,
11+ ERROR : "error" ,
12+ WARNING : "warning" ,
13+ INFO : "info" ,
14+ VERBOSE : "verbose" ,
15+ SUCCESS : "success" ,
16+ } ;
17+
18+ this . defaultLog = this . logTypes . NOTICE ;
19+ }
20+
21+ log ( str , type = this . defaultLog ) {
22+ switch ( this . serverless . version [ 0 ] ) {
23+ case "2" :
24+ let colouredString = str ;
25+ if ( type === "error" ) {
26+ colouredString = chalk . bold . red ( `✖ ${ str } ` ) ;
27+ } else if ( type === "success" ) {
28+ colouredString = chalk . bold . green ( `✓ ${ str } ` ) ;
29+ }
30+
31+ this . serverless . cli . log ( colouredString ) ;
32+ break ;
33+
34+ case "4" :
35+ case "3" :
36+ this . logOutput [ type ] ( str ) ;
37+ break ;
38+
39+ default :
40+ process . stdout . write ( str . join ( " " ) ) ;
41+ break ;
42+ }
43+ }
44+
45+ debug ( str ) {
46+ this . log ( str , this . logTypes . DEBUG ) ;
47+ }
48+
49+ error ( str ) {
50+ this . log ( str , this . logTypes . ERROR ) ;
51+ }
52+
53+ info ( str ) {
54+ this . log ( str , this . logTypes . INFO ) ;
55+ }
56+
57+ notice ( str ) {
58+ this . log ( str , this . logTypes . NOTICE ) ;
59+ }
60+
61+ success ( str ) {
62+ this . log ( str , this . logTypes . SUCCESS ) ;
63+ }
64+
65+ verbose ( str ) {
66+ this . log ( str , this . logTypes . VERBOSE ) ;
67+ }
68+
69+ warning ( str ) {
70+ this . log ( str , this . logTypes . WARNING ) ;
71+ }
72+ }
73+
74+ module . exports = Logger ;
You can’t perform that action at this time.
0 commit comments