mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-08 05:20:01 +00:00
log into a file
This commit is contained in:
parent
8d12d6a547
commit
e1eb1beb87
@ -20,6 +20,7 @@
|
||||
"@types/js-yaml": "^3.9.0",
|
||||
"@types/node": "^7.0.37",
|
||||
"@types/webpack-env": "^1.13.0",
|
||||
"@types/winston": "^2.3.6",
|
||||
"axios": "0.16.2",
|
||||
"bootstrap": "4.0.0-alpha.6",
|
||||
"core-js": "^2.4.1",
|
||||
@ -39,7 +40,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"deepmerge": "^1.5.0",
|
||||
"js-yaml": "^3.9.0"
|
||||
"js-yaml": "^3.9.0",
|
||||
"winston": "^2.4.0"
|
||||
},
|
||||
"false": {}
|
||||
}
|
||||
|
@ -1,12 +1,47 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { ElectronService } from './electron.service'
|
||||
import * as winston from 'winston'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
const initializeWinston = (electron: ElectronService) => {
|
||||
const logDirectory = electron.app.getPath('userData')
|
||||
|
||||
if (!fs.existsSync(logDirectory)) {
|
||||
fs.mkdirSync(logDirectory)
|
||||
}
|
||||
|
||||
return new winston.Logger({
|
||||
transports: [
|
||||
new winston.transports.File({
|
||||
level: 'info',
|
||||
filename: path.join(logDirectory, 'log.txt'),
|
||||
handleExceptions: false,
|
||||
json: false,
|
||||
maxsize: 5242880,
|
||||
maxFiles: 5,
|
||||
colorize: false
|
||||
}),
|
||||
new winston.transports.Console({
|
||||
level: 'info',
|
||||
handleExceptions: false,
|
||||
json: false,
|
||||
colorize: true
|
||||
})
|
||||
],
|
||||
exitOnError: false
|
||||
})
|
||||
}
|
||||
|
||||
export class Logger {
|
||||
constructor (
|
||||
private winstonLogger: any,
|
||||
private name: string,
|
||||
) {}
|
||||
|
||||
doLog (level: string, ...args: any[]) {
|
||||
console[level](`%c[${this.name}]`, 'color: #aaa', ...args)
|
||||
this.winstonLogger[level](...args)
|
||||
}
|
||||
|
||||
debug (...args: any[]) { this.doLog('debug', ...args) }
|
||||
@ -18,7 +53,13 @@ export class Logger {
|
||||
|
||||
@Injectable()
|
||||
export class LogService {
|
||||
private log: any
|
||||
|
||||
constructor (electron: ElectronService) {
|
||||
this.log = initializeWinston(electron)
|
||||
}
|
||||
|
||||
create (name: string): Logger {
|
||||
return new Logger(name)
|
||||
return new Logger(this.log, name)
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ module.exports = {
|
||||
'path',
|
||||
'deepmerge',
|
||||
'untildify',
|
||||
'winston',
|
||||
'js-yaml',
|
||||
/^rxjs/,
|
||||
/^@angular/,
|
||||
|
@ -6,7 +6,7 @@
|
||||
version "3.9.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.9.1.tgz#2f3c142771bb345829ce690c5838760b6b9ba553"
|
||||
|
||||
"@types/node@^7.0.37":
|
||||
"@types/node@*", "@types/node@^7.0.37":
|
||||
version "7.0.43"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.43.tgz#a187e08495a075f200ca946079c914e1a5fe962c"
|
||||
|
||||
@ -14,12 +14,22 @@
|
||||
version "1.13.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.1.tgz#b45c222e24301bd006e3edfc762cc6b51bda236a"
|
||||
|
||||
"@types/winston@^2.3.6":
|
||||
version "2.3.6"
|
||||
resolved "https://registry.yarnpkg.com/@types/winston/-/winston-2.3.6.tgz#0f0954b9e16abd40598dc6e9cc2ea43044237997"
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
argparse@^1.0.7:
|
||||
version "1.0.9"
|
||||
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.9.tgz#73d83bc263f86e97f8cc4f6bae1b0e90a7d22c86"
|
||||
dependencies:
|
||||
sprintf-js "~1.0.2"
|
||||
|
||||
async@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/async/-/async-1.0.0.tgz#f8fc04ca3a13784ade9e1641af98578cfbd647a9"
|
||||
|
||||
axios@0.16.2:
|
||||
version "0.16.2"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.16.2.tgz#ba4f92f17167dfbab40983785454b9ac149c3c6d"
|
||||
@ -44,10 +54,18 @@ bootstrap@4.0.0-alpha.6:
|
||||
jquery ">=1.9.1"
|
||||
tether "^1.4.0"
|
||||
|
||||
colors@1.0.x:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
|
||||
|
||||
core-js@^2.4.1:
|
||||
version "2.5.1"
|
||||
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.1.tgz#ae6874dc66937789b80754ff5428df66819ca50b"
|
||||
|
||||
cycle@1.0.x:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/cycle/-/cycle-1.0.3.tgz#21e80b2be8580f98b468f379430662b046c34ad2"
|
||||
|
||||
debug@^2.4.5:
|
||||
version "2.6.8"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
|
||||
@ -97,6 +115,10 @@ esprima@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"
|
||||
|
||||
eyes@0.1.x:
|
||||
version "0.1.8"
|
||||
resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0"
|
||||
|
||||
follow-redirects@^1.2.3:
|
||||
version "1.2.4"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.2.4.tgz#355e8f4d16876b43f577b0d5ce2668b9723214ea"
|
||||
@ -126,6 +148,10 @@ is-buffer@^1.1.5:
|
||||
version "1.1.5"
|
||||
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc"
|
||||
|
||||
isstream@0.1.x:
|
||||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
|
||||
|
||||
jquery@>=1.9.1:
|
||||
version "3.2.1"
|
||||
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.2.1.tgz#5c4d9de652af6cd0a770154a631bba12b015c787"
|
||||
@ -191,6 +217,10 @@ sprintf-js@~1.0.2:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
|
||||
|
||||
stack-trace@0.0.x:
|
||||
version "0.0.10"
|
||||
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
|
||||
|
||||
tether@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/tether/-/tether-1.4.0.tgz#0f9fa171f75bf58485d8149e94799d7ae74d1c1a"
|
||||
@ -209,6 +239,17 @@ uuid-1345@^0.99.6:
|
||||
dependencies:
|
||||
macaddress "^0.2.7"
|
||||
|
||||
winston@^2.4.0:
|
||||
version "2.4.0"
|
||||
resolved "https://registry.yarnpkg.com/winston/-/winston-2.4.0.tgz#808050b93d52661ed9fb6c26b3f0c826708b0aee"
|
||||
dependencies:
|
||||
async "~1.0.0"
|
||||
colors "1.0.x"
|
||||
cycle "1.0.x"
|
||||
eyes "0.1.x"
|
||||
isstream "0.1.x"
|
||||
stack-trace "0.0.x"
|
||||
|
||||
xelement@^1.0.16:
|
||||
version "1.0.16"
|
||||
resolved "https://registry.yarnpkg.com/xelement/-/xelement-1.0.16.tgz#900bb46c20fc2dffadff778a9d2dc36699d0ff7e"
|
||||
|
Loading…
x
Reference in New Issue
Block a user