mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-25 20:26:36 +00:00
Merge pull request #111 from resin-io/refactor/logger-log
Move LoggerService timestamp to $log decorator
This commit is contained in:
commit
e770e858e3
@ -28,7 +28,6 @@ require('angular-ui-bootstrap');
|
|||||||
require('./browser/modules/selection-state');
|
require('./browser/modules/selection-state');
|
||||||
require('./browser/modules/drive-scanner');
|
require('./browser/modules/drive-scanner');
|
||||||
require('./browser/modules/image-writer');
|
require('./browser/modules/image-writer');
|
||||||
require('./browser/modules/logger');
|
|
||||||
require('./browser/modules/path');
|
require('./browser/modules/path');
|
||||||
|
|
||||||
var app = angular.module('ResinEtcher', [
|
var app = angular.module('ResinEtcher', [
|
||||||
@ -38,8 +37,7 @@ var app = angular.module('ResinEtcher', [
|
|||||||
'ResinEtcher.path',
|
'ResinEtcher.path',
|
||||||
'ResinEtcher.selection-state',
|
'ResinEtcher.selection-state',
|
||||||
'ResinEtcher.drive-scanner',
|
'ResinEtcher.drive-scanner',
|
||||||
'ResinEtcher.image-writer',
|
'ResinEtcher.image-writer'
|
||||||
'ResinEtcher.logger'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// TrackJS integration
|
// TrackJS integration
|
||||||
@ -60,6 +58,7 @@ app.config(function($provide) {
|
|||||||
var debugFn = $delegate.debug;
|
var debugFn = $delegate.debug;
|
||||||
|
|
||||||
$delegate.debug = function(message) {
|
$delegate.debug = function(message) {
|
||||||
|
message = new Date() + ' ' + message;
|
||||||
$window.trackJs.console.debug(message);
|
$window.trackJs.console.debug(message);
|
||||||
debugFn.call(null, message);
|
debugFn.call(null, message);
|
||||||
};
|
};
|
||||||
@ -68,7 +67,7 @@ app.config(function($provide) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.controller('AppController', function($q, DriveScannerService, SelectionStateService, ImageWriterService, LoggerService) {
|
app.controller('AppController', function($q, $log, DriveScannerService, SelectionStateService, ImageWriterService) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -77,7 +76,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
|
|||||||
this.scanner = DriveScannerService;
|
this.scanner = DriveScannerService;
|
||||||
|
|
||||||
this.restart = function(options) {
|
this.restart = function(options) {
|
||||||
LoggerService.debug('Restarting');
|
$log.debug('Restarting');
|
||||||
this.selection.clear(options);
|
this.selection.clear(options);
|
||||||
this.writer.reset();
|
this.writer.reset();
|
||||||
this.scanner.start(2000).on('scan', function(drives) {
|
this.scanner.start(2000).on('scan', function(drives) {
|
||||||
@ -94,7 +93,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
|
|||||||
// `angular.equals` is used instead of `_.isEqual` to
|
// `angular.equals` is used instead of `_.isEqual` to
|
||||||
// cope with `$$hashKey`.
|
// cope with `$$hashKey`.
|
||||||
if (!angular.equals(self.selection.getDrive(), drive)) {
|
if (!angular.equals(self.selection.getDrive(), drive)) {
|
||||||
LoggerService.debug('Autoselecting drive: ' + drive.device);
|
$log.debug('Autoselecting drive: ' + drive.device);
|
||||||
self.selectDrive(drive);
|
self.selectDrive(drive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,13 +117,13 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
|
|||||||
this.selectImage = function() {
|
this.selectImage = function() {
|
||||||
return $q.when(dialog.selectImage()).then(function(image) {
|
return $q.when(dialog.selectImage()).then(function(image) {
|
||||||
self.selection.setImage(image);
|
self.selection.setImage(image);
|
||||||
LoggerService.debug('Image selected: ' + image);
|
$log.debug('Image selected: ' + image);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectDrive = function(drive) {
|
this.selectDrive = function(drive) {
|
||||||
self.selection.setDrive(drive);
|
self.selection.setDrive(drive);
|
||||||
LoggerService.debug('Drive selected: ' + drive.device);
|
$log.debug('Drive selected: ' + drive.device);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.reselectImage = function() {
|
this.reselectImage = function() {
|
||||||
@ -138,7 +137,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
|
|||||||
// "returns" to the first step.
|
// "returns" to the first step.
|
||||||
self.selection.clear();
|
self.selection.clear();
|
||||||
|
|
||||||
LoggerService.debug('Reselecting image');
|
$log.debug('Reselecting image');
|
||||||
};
|
};
|
||||||
|
|
||||||
this.reselectDrive = function() {
|
this.reselectDrive = function() {
|
||||||
@ -147,7 +146,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.selection.removeDrive();
|
self.selection.removeDrive();
|
||||||
LoggerService.debug('Reselecting drive');
|
$log.debug('Reselecting drive');
|
||||||
};
|
};
|
||||||
|
|
||||||
this.burn = function(image, drive) {
|
this.burn = function(image, drive) {
|
||||||
@ -156,9 +155,9 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState
|
|||||||
// otherwise Windows throws EPERM
|
// otherwise Windows throws EPERM
|
||||||
self.scanner.stop();
|
self.scanner.stop();
|
||||||
|
|
||||||
LoggerService.debug('Burning ' + image + ' to ' + drive.device);
|
$log.debug('Burning ' + image + ' to ' + drive.device);
|
||||||
return self.writer.burn(image, drive).then(function() {
|
return self.writer.burn(image, drive).then(function() {
|
||||||
LoggerService.debug('Done!');
|
$log.debug('Done!');
|
||||||
}).catch(dialog.showError);
|
}).catch(dialog.showError);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
var angular = require('angular');
|
var angular = require('angular');
|
||||||
var electron = require('electron');
|
var electron = require('electron');
|
||||||
require('./logger');
|
|
||||||
|
|
||||||
if (window.mocha) {
|
if (window.mocha) {
|
||||||
var writer = electron.remote.require(require('path').join(__dirname, '..', '..', 'src', 'writer'));
|
var writer = electron.remote.require(require('path').join(__dirname, '..', '..', 'src', 'writer'));
|
||||||
@ -28,11 +27,9 @@ if (window.mocha) {
|
|||||||
var writer = electron.remote.require('./src/writer');
|
var writer = electron.remote.require('./src/writer');
|
||||||
}
|
}
|
||||||
|
|
||||||
var imageWriter = angular.module('ResinEtcher.image-writer', [
|
var imageWriter = angular.module('ResinEtcher.image-writer', []);
|
||||||
'ResinEtcher.logger'
|
|
||||||
]);
|
|
||||||
|
|
||||||
imageWriter.service('ImageWriterService', function($q, $timeout, LoggerService) {
|
imageWriter.service('ImageWriterService', function($q, $timeout, $log) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -83,7 +80,7 @@ imageWriter.service('ImageWriterService', function($q, $timeout, LoggerService)
|
|||||||
// Transform bytes to megabytes preserving only two decimal places
|
// Transform bytes to megabytes preserving only two decimal places
|
||||||
self.state.speed = Math.floor(state.speed / 1e+6 * 100) / 100 || 0;
|
self.state.speed = Math.floor(state.speed / 1e+6 * 100) / 100 || 0;
|
||||||
|
|
||||||
LoggerService.debug('Progress: ' + self.state.progress + '% at ' + self.state.speed + ' MB/s');
|
$log.debug('Progress: ' + self.state.progress + '% at ' + self.state.speed + ' MB/s');
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2016 Resin.io
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @module ResinEtcher.logger
|
|
||||||
*/
|
|
||||||
|
|
||||||
var angular = require('angular');
|
|
||||||
var logger = angular.module('ResinEtcher.logger', []);
|
|
||||||
|
|
||||||
logger.service('LoggerService', function($log) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @summary Print a debug log message
|
|
||||||
* @function
|
|
||||||
* @public
|
|
||||||
*
|
|
||||||
* @param {String} message - message
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* LoggerService.debug('Hello World');
|
|
||||||
*/
|
|
||||||
this.debug = function(message) {
|
|
||||||
$log.debug(new Date() + ' ' + message);
|
|
||||||
};
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user