StreamLogger::output()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
/*
3
 * This file is part of Yolk - Gamer Network's PHP Framework.
4
 *
5
 * Copyright (c) 2014 Gamer Network Ltd.
6
 * 
7
 * Distributed under the MIT License, a copy of which is available in the
8
 * LICENSE file that was bundled with this package, or online at:
9
 * https://github.com/gamernetwork/yolk-logger
10
 */
11
12
namespace yolk\log\adapter;
13
14
use yolk\log\BaseLogger;
15
use yolk\log\Exception;
16
17
/**
18
 * Provides logging to a stream resource.
19
 */
20
abstract class StreamLogger extends BaseLogger {
21
22
	/**
23
	 * Open log file.
24
	 * @var resource
25
	 */
26
	protected $stream;
27
28
	/**
29
	 * Create a logger that outputs to the specified stream resource
30
	 * @param resource $stream
31
	 */
32
	public function __construct( $stream ) {
33
34
		if( !is_resource($stream) || (get_resource_type($stream) != 'stream') )
35
			throw new Exception('Not a valid stream: '. gettype($stream));
36
37
		$this->stream = $stream;
38
39
		parent::__construct();
40
41
	}
42
43
	protected function output( $level, $msg ) {
44
		fwrite($this->stream, $msg);
45
	}
46
47
}
48
49
// EOF