Skip to content

Commit 90bfa14

Browse files
authored
feat(Option): Add --log-file, --lf option (#57)
* feat(Option): Add --log-file option * update * update cmd interface * add more log files * docs(CHANGELOG): update * update doc
1 parent aa1f194 commit 90bfa14

File tree

8 files changed

+81
-32
lines changed

8 files changed

+81
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
2626
* Return correct packaged file depends on multi-files flag (23cd251abd4e65c62549feb280e785d1ee9634a7)
2727
* Add keywords command and it's linter (#54)
2828
* Handle many-to-one condition for version string (0ac654face0557ff74c4a6048fc8bef59c915ec8)
29+
* Add new option `--log-file`, `--lf` to generate log files (#57)
2930

3031
## 0.6.17
3132
> Released Mar 5, 2022

docs/content/en/Continuous Integration/GitHub Actions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ubuntu-latest, macos-latest, windows-latest]
17-
emacs-version: [27.2, snapshot]
17+
emacs-version: [26.3, 27.2, 28.1, snapshot]
1818

1919
steps:
2020
- uses: actions/checkout@v2

docs/content/en/Development API/_index.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ Return `t`/`nil` if the `timestamps` option is enabled/disabled.
241241
These flags can't co-exist in the same command.
242242

243243
```elisp
244-
(when (and (eask-timestamps-p) (eask-no-timestamps-p))
245-
(error "This is impossible!"))
244+
(when (eask-timestamps-p)
245+
(message "Print log with timestamps!"))
246246
```
247247

248248
## 🔍 Function: eask-log-level-p ()
@@ -252,8 +252,15 @@ Return `t`/`nil` if the `log-level` option is enabled/disabled.
252252
These flags can't co-exist in the same command.
253253

254254
```elisp
255-
(when (and (eask-log-level-p) (eask-no-log-level-p))
256-
(error "This is impossible!"))
255+
(when (eask-log-level-p)
256+
(message "Print log with level prefix!"))
257+
```
258+
259+
## 🔍 Function: eask-log-file-p ()
260+
261+
```elisp
262+
(when (eask-log-file-p)
263+
(message "Let's create a log file!"))
257264
```
258265

259266
## 🔍 Function: eask-no-color-p ()

docs/content/en/Getting Started/Basic Usage.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ Usage: eask <command> [options..]
2828
2929
Commands:
3030
activate [files..] activate package; use to test package activation
31-
archives list out all package archives [aliases: sources]
31+
archives list out all package archives [aliases: sources]
3232
autoloads generate autoloads file
3333
clean-all do all cleaning tasks
3434
clean-elc remove byte compiled files generated by cask build
3535
clean clean up local .eask directory
36-
compile [names..] byte compile all Emacs Lisp files in the package [aliases: build]
37-
concat [names..] concatenate all elisp files [aliases: concatenate]
38-
create <name> create a new elisp project [aliases: new]
36+
compile [names..] byte compile all Emacs Lisp files in the package [aliases: build]
37+
concat [names..] concatenate all elisp files [aliases: concatenate]
38+
create <name> create a new elisp project [aliases: new]
3939
emacs [args..] execute emacs with the appropriate environment
4040
eval [form] evaluate lisp form with a proper PATH
41-
path print the PATH (exec-path) from workspace [aliases: exec-path]
41+
path print the PATH (exec-path) from workspace [aliases: exec-path]
4242
exec [args..] execute command with correct environment PATH set up
4343
files print the list of all package files
4444
info display information about the current package
4545
init create new Eask file in current directory
46-
install-deps automatically install package dependencies [aliases: install-dependencies, prepare]
46+
install-deps automatically install package dependencies [aliases: install-dependencies, prepare]
4747
install [names..] install packages
4848
keywords list available keywords that can be used in the header section
4949
lint <type> run linter
@@ -60,31 +60,32 @@ Commands:
6060
reinstall [names..] reinstall packages
6161
search [queries..] search packages
6262
test <type> run test
63-
uninstall [names..] uninstall packages [aliases: delete]
63+
uninstall [names..] uninstall packages [aliases: delete]
6464
upgrade [names..] upgrade packages
6565
check-eask [files..] run eask checker
6666
locate print out Eask installed location
67-
upgrade-eask upgrade Eask itself [aliases: upgrade-self]
67+
upgrade-eask upgrade Eask itself [aliases: upgrade-self]
6868
6969
Options:
70-
--version Show version number [boolean]
71-
--help Show usage instructions [boolean]
72-
-g, --global change default workspace to ~/.emacs.d/ [boolean]
73-
-f, --force enable force flag [boolean]
74-
--development, --dev turn on development mode [boolean]
75-
--debug turn on debug mode [boolean]
76-
--strict report error instead of warnings [boolean]
77-
--allow-error continue the executioon even there is error reported [boolean]
78-
--insecure allow insecure connection [boolean]
79-
--timestamps log with timestamps [boolean]
80-
--log-level log with level [boolean]
81-
--elapsed-time, --et show elapsed time between each operation [boolean]
82-
--no-color disable color output [boolean]
83-
--proxy update proxy for HTTP and HTTPS to host [string]
84-
--http-proxy update proxy for HTTP to host [string]
85-
--https-proxy update proxy for HTTPS to host [string]
86-
--no-proxy set no-proxy to host [string]
87-
-v, --verbose set verbosity from 0 to 4 [number]
70+
--version Show version number [boolean]
71+
--help Show usage instructions [boolean]
72+
-g, --global change default workspace to ~/.emacs.d/ [boolean]
73+
-f, --force enable force flag [boolean]
74+
--development, --dev turn on development mode [boolean]
75+
--debug turn on debug mode [boolean]
76+
--strict report error instead of warnings [boolean]
77+
--allow-error continue the executioon even there is error reported [boolean]
78+
--insecure allow insecure connection [boolean]
79+
--timestamps log with timestamps [boolean]
80+
--log-level log with level [boolean]
81+
--log-file, --lf generate log files [boolean]
82+
--elapsed-time, --et show elapsed time between each operation [boolean]
83+
--no-color disable color output [boolean]
84+
--proxy update proxy for HTTP and HTTPS to host [string]
85+
--http-proxy update proxy for HTTP to host [string]
86+
--https-proxy update proxy for HTTPS to host [string]
87+
--no-proxy set no-proxy to host [string]
88+
-v, --verbose set verbosity from 0 to 4 [number]
8889
8990
For more information, find the manual at https://emacs-eask.github.io/
9091
```

docs/content/en/Getting Started/Commands and options.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,15 @@ Enable/Disable timestamps.
547547

548548
Enable/Disable log header.
549549

550+
## 🔍 --log-file, --lf
551+
552+
Weather to generate log files.
553+
550554
## 🔍 --no-color
551555

552556
Disable color output.
553557

554-
## 🔍 --elapsed-time
558+
## 🔍 --elapsed-time, --et
555559

556560
Show elapsed time between each operation
557561

eask

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ yargs
6666
description: 'log with level',
6767
type: 'boolean',
6868
})
69+
.option('log-file', {
70+
description: 'generate log files',
71+
alias: 'lf',
72+
type: 'boolean',
73+
})
6974
.option('elapsed-time', {
7075
description: 'show elapsed time between each operation',
7176
alias: 'et',

lisp/_prepare.el

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ the `eask-start' execution.")
415415
(defun eask-strict-p () (eask--flag "--strict")) ; --strict
416416
(defun eask-timestamps-p () (eask--flag "--timestamps")) ; --timestamps
417417
(defun eask-log-level-p () (eask--flag "--log-level")) ; --log-level
418+
(defun eask-log-file-p () (eask--flag "--log-file")) ; --log-file, --lf
418419
(defun eask-elapsed-time-p () (eask--flag "--elapsed-time")) ; --elapsed-time, --et
419420
(defun eask-allow-error-p () (eask--flag "--allow-error")) ; --allow-error
420421
(defun eask-insecure-p () (eask--flag "--insecure")) ; --insecure
@@ -439,6 +440,7 @@ the `eask-start' execution.")
439440
(when (eask-insecure-p) (setq network-security-level 'low))
440441
(when (eask-timestamps-p) (setq eask-timestamps t))
441442
(when (eask-log-level-p) (setq eask-log-level t))
443+
(when (eask-log-file-p) (setq eask-log-file t))
442444
(when (eask-elapsed-time-p) (setq eask-elapsed-time t))
443445
(when (eask-no-color-p) (setq ansi-inhibit-ansi t))
444446
(unless eask-has-colors (setq ansi-inhibit-ansi t))
@@ -478,6 +480,7 @@ other scripts internally. See function `eask-call'.")
478480
"--allow-error"
479481
"--insecure"
480482
"--timestamps" "--log-level"
483+
"--log-file"
481484
"--elapsed-time"
482485
"--no-color"))
483486
"List of boolean type options.")
@@ -975,6 +978,33 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
975978
"Report error/warning depends on strict flag."
976979
(apply (if (eask-strict-p) #'eask-error #'eask-warn) args))
977980

981+
;;
982+
;;; Log
983+
984+
(defconst eask-log-path ".log"
985+
"Directory path to create log files.")
986+
987+
(defcustom eask-log-file nil
988+
"Weather to generate log files."
989+
:type 'boolean)
990+
991+
(defmacro eask--log-write-buffer (buffer file)
992+
"Write BUFFER to FILE."
993+
`(when (get-buffer-create ,buffer)
994+
(let ((buffer-file-coding-system 'utf-8))
995+
(write-region (with-current-buffer ,buffer (buffer-string)) nil
996+
(expand-file-name ,file log-dir)))))
997+
998+
(add-hook 'kill-emacs-hook ; Write log files
999+
(lambda (&rest _)
1000+
(when eask-log-file
1001+
(let ((log-dir (expand-file-name eask-log-path)))
1002+
(make-directory log-dir t)
1003+
(eask--log-write-buffer "*Messages*" "messages.log")
1004+
(eask--log-write-buffer "*Warnings*" "warnings.log")
1005+
(eask--log-write-buffer "*Backtrace*" "backtrace.log")
1006+
(eask--log-write-buffer "*Compile-Log*" "compile-log.log")))))
1007+
9781008
;;
9791009
;;; File
9801010

src/util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function _global_options(argv) {
8383
flags.push(def_flag(argv['allow-error'], '--allow-error'));
8484
flags.push(def_flag(argv.timestamps, (argv.timestamps) ? '--timestamps' : '--no-timestamps'));
8585
flags.push(def_flag(argv['log-level'], (argv['log-level']) ? '--log-level' : '--no-log-level'));
86+
flags.push(def_flag(argv['log-file'], (argv['log-file']) ? '--log-file' : '--no-log-file'));
8687
flags.push(def_flag(argv['elapsed-time'], (argv['elapsed-time']) ? '--elapsed-time' : '--no-elapsed-time'));
8788
flags.push(def_flag(argv['color'], '--no-color'));
8889
/* With arguments */

0 commit comments

Comments
 (0)